Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
af9acf9
Add the new form to modify the distribution agreement
dukenuken09 Nov 15, 2022
ec3d4d0
improve the text
dukenuken09 Nov 17, 2022
dc9ad0c
Add title
dukenuken09 Nov 17, 2022
8959129
added the call and the data to work the form about the distribution a…
dukenuken09 Nov 25, 2022
61baa8b
Fix the call of the distribution_Agreement form
dukenuken09 Nov 29, 2022
d802018
Read the error code from the server
dukenuken09 Dec 1, 2022
1bd2234
Added Success component
dukenuken09 Dec 7, 2022
9706c1e
WIP manage the file's type errors from back
dukenuken09 Dec 21, 2022
6218335
ADDED validators for the type of files
dukenuken09 Dec 21, 2022
4ef89de
Added the new success text and fix the language manager of the dist a…
dukenuken09 Jan 12, 2023
40ed769
added the tag for the new success text
dukenuken09 Jan 12, 2023
04dd88c
Added the pop up when remain som docs, fix the error when call the ap…
dukenuken09 Jan 13, 2023
7ba3903
Added the tests with cypress
dukenuken09 Jan 17, 2023
81768ed
remove console log
dukenuken09 Jan 17, 2023
9cad67d
Added the tests for modDistAgreement and mock_files related
dukenuken09 Jan 17, 2023
1eab5f4
Improve the validation functions, add a new test for incorrect files …
dukenuken09 Jan 18, 2023
67b5340
Add new structure of files and testing directory
dukenuken09 Jan 18, 2023
f8417ae
Added the new cypress test and the i18n configuration for unit tests
dukenuken09 Jan 20, 2023
859d910
added tests of Uploader component (100% coverage), test of fileType v…
dukenuken09 Jan 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added cypress/fixtures/mock_files/file-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions cypress/fixtures/mock_files/file-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
txtaa
104 changes: 104 additions & 0 deletions cypress/integration/modDistAgreement/modDistAgreement.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/// <reference types="cypress" />

describe('Update distribution agreement form', () => {
const filepathJpg = 'mock_files/file-1.jpg'
const filepathTxt = 'mock_files/file-2.txt'
const jpgFileName = 'file-1.jpg'
const txtFileName = 'file-2.txt'
const urlTxt = '/form/upload_txt_attachment/1'
const urlAttachment = '/form/upload_attachment/0'
const modAgreementUrl = '/procedures/distribution_agreement'

Cypress.on('uncaught:exception', (error, runnable) => {
console.error(error)
return false
})

beforeEach(() => {
cy.visit('/mod-distribution-agreement')
})

describe('Update the distribution agreement', function () {
function uploadFile(fileName, url) {
cy.intercept('POST', url, {
data: { code: 'UPLOAD_OK', file_hash: fileName }
}).as('uploadFile')

cy.wait('@uploadFile').then((interception) => {
assert.isNotNull(interception.response.body.data.code, 'UPLOAD_OK')
})
}

it('Upload correct files', function () {
cy.get('#type9-input-file').attachFile({
filePath: filepathJpg
})

uploadFile(jpgFileName, urlAttachment)

cy.get('#type12-input-file').attachFile({
filePath: filepathTxt
})

uploadFile(txtFileName, urlTxt)

cy.intercept('POST', modAgreementUrl, { data: { statusCode: 200 } })
cy.get('#submit-button').click()
})

it('Upload incorrect files', function () {
cy.get('#type9-input-file').attachFile({
filePath: filepathTxt
})

uploadFile(txtFileName, urlAttachment)

cy.get('#type12-input-file').attachFile({
filePath: filepathJpg
})

uploadFile(jpgFileName, urlTxt)

cy.intercept('POST', modAgreementUrl, { data: { statusCode: 200 } })
cy.get('#submit-button').click()
cy.get('#accept-button').click()
})

it('Upload only one file and accept', function () {
cy.get('#type9-input-file').attachFile({
filePath: filepathJpg
})

uploadFile(jpgFileName, urlAttachment)

cy.intercept('POST', modAgreementUrl, { data: { statusCode: 200 } })
cy.get('#submit-button').click()
cy.get('#accept-button').click()
})

it('Upload only one file and decline', function () {
cy.get('#type9-input-file').attachFile({
filePath: filepathJpg
})

uploadFile(jpgFileName, urlAttachment)

cy.intercept('POST', modAgreementUrl, { data: { statusCode: 200 } })
cy.get('#submit-button').click()
cy.get('#decline-button').click()

})

it('Upload without files and accept', function () {
cy.intercept('POST', modAgreementUrl, { data: { statusCode: 200 } })
cy.get('#submit-button').click()
cy.get('#accept-button').click()
})

it('Upload without files and decline', function () {
cy.intercept('POST', modAgreementUrl, { data: { statusCode: 200 } })
cy.get('#submit-button').click()
cy.get('#decline-button').click()
})
})
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
]
},
"devDependencies": {
"axios-mock-adapter": "^1.21.2",
"cypress": "^9.5.1",
"cypress-file-upload": "^5.0.8",
"eslint-plugin-cypress": "^2.12.1",
Expand Down
10 changes: 10 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const App = (props) => {
const ModifyContract = lazy(() => import('./containers/ModifyContract'))
const Tariff = lazy(() => import('./containers/Tariff'))
const MailSubscriptions = lazy(() => import('./containers/MailSubscriptions'))
const ModDistAgreement = lazy(() => import('./containers/ModDistAgreement/ModDistAgreement'))

const loadContractData = () => {
const contractData =
Expand Down Expand Up @@ -323,6 +324,15 @@ const App = (props) => {
/>
}
/>
<Route
exact
path="/mod-distribution-agreement"
element={<ModDistAgreement {...props} />}
/>
<Route
path="/:language/mod-distribution-agreement/"
element={<ModDistAgreement {...props} />}
/>
</Routes>
</Router>
</Suspense>
Expand Down
9 changes: 0 additions & 9 deletions src/App.test.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/TermsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const TermsDialog = (props) => {
</DialogContentText>
</DialogContent>
<DialogActions>
<Button data-cy="decline" onClick={onClose}>
<Button data-cy="decline" id={'decline-button'} onClick={onClose}>
{t('I_DECLINE')}
</Button>
<Button data-cy="accept" onClick={onAccept} variant="contained" color="primary">
<Button data-cy="accept" id={'accept-button'} onClick={onAccept} variant="contained" color="primary">
{t('I_ACCEPT')}
</Button>
</DialogActions>
Expand Down
74 changes: 48 additions & 26 deletions src/components/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,66 @@ const useStyles = makeStyles((theme) => ({
}
}))

/**
* testingCustomError : Variable to force the error for testing (not delete)
*
*/

const Uploader = (props) => {
const { name, callbackFn, fieldError, values, maxFiles } = props
const {
id,
name,
callbackFn,
fieldError,
values,
maxFiles,
validationFileFunction,
testingCustomError
} = props

const { t } = useTranslation()
const classes = useStyles()

const validTypeFiles = props.validTypeFiles || 'INSTALL_TYPE_ATTACHMENTS_INFO'
const [uploads, setUploads] = useState([...values])
const [inputKey, setInputKey] = useState(Date.now())
const [isUploading, setUploading] = useState(false)
const [error, setError] = useState(false)
const [error, setError] = useState(testingCustomError || false)

useEffect(() => {
callbackFn(uploads)
}, [uploads])

const upload = useCallback(
async (name, file) => {
return uploadFile(name, file)
.then((response) => {
if (response?.data?.code === 'UPLOAD_OK') {
setUploads([...uploads, response?.data?.file_hash])
setInputKey(Date.now())
} else {
const errorMsg = response?.data?.code
? response?.data?.code
let validation = validationFileFunction
? validationFileFunction(file.name)
: null
if (!validation || validation.result) {
setError('')
return uploadFile(name, file, props.uploadUrl)
.then((response) => {
if (response?.data?.code === 'UPLOAD_OK') {
setUploads([...uploads, response?.data?.file_hash])
setInputKey(Date.now())
} else {
const errorMsg = response?.data?.code
? response?.data?.code
: 'MODIFY_POTTAR_UNEXPECTED'
setError(errorMsg)
}
})
.catch((error) => {
const errorMsg = error?.response?.data?.code
? error.response.data.code
: 'MODIFY_POTTAR_UNEXPECTED'
setError(errorMsg)
}
})
.catch((error) => {
const errorMsg = error?.response?.data?.code
? error.response.data.code
: 'MODIFY_POTTAR_UNEXPECTED'
setError(errorMsg)
})
})
} else {
setError(validation.msg)
}
},
[uploads]
[uploads, props.uploadUrl]
)

const handleChange = useCallback(
Expand Down Expand Up @@ -99,6 +123,7 @@ const Uploader = (props) => {
return (
<>
<TextField
id={id}
key={inputKey}
type="file"
label=""
Expand All @@ -113,9 +138,9 @@ const Uploader = (props) => {
endAdornment: (
<InputAdornment position="end">
{isUploading ? (
<CircularProgress size={24} />
<CircularProgress id={'uploader-circular-progress'} size={24} />
) : error ? (
<IconButton onClick={handleClean}>
<IconButton id={'clean-icon'} onClick={handleClean}>
<HighlightOffIcon />
</IconButton>
) : (
Expand All @@ -126,11 +151,7 @@ const Uploader = (props) => {
}}
error={(error || fieldError) && true}
helperText={
error
? t(error)
: fieldError
? t(fieldError)
: t('INSTALL_TYPE_ATTACHMENTS_INFO')
error ? t(error) : fieldError ? t(fieldError) : t(validTypeFiles)
}
/>
<List>
Expand All @@ -142,6 +163,7 @@ const Uploader = (props) => {
<ListItemText>{upload}</ListItemText>
<ListItemSecondaryAction>
<IconButton
id={'delete-icon' + index}
edge="end"
aria-label="delete"
onClick={(event) => handleDelete(event, index)}>
Expand Down
1 change: 1 addition & 0 deletions src/containers/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const options = [
{ title: 'Contractació 20', href: `${language}/contract-20` },
{ title: 'Contractació 30', href: '/contract-30' },
{ title: 'Modificació contractual', href: '/modify-contract' },
{ title: 'Modificació acord de repartiment', href: '/mod-distribution-agreement' },
]

const Home = (props) => {
Expand Down
77 changes: 77 additions & 0 deletions src/containers/ModDistAgreement/ModDistAgreement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useLocation, useParams } from 'react-router-dom'
import { distribution_agreement } from '../../services/api'
import ModDistAgreementData from './ModDistAgreementData'

const ModDistAgreement = (props) => {
const { i18n } = useTranslation()
const { state } = useLocation()
const { language } = useParams()

const templateProps = JSON.parse(props.d1)
const [type9Attachment, setType9Attachment] = useState([])
const [type12Attachment, setType12Attachment] = useState([])
const [error, setError] = useState('')
const [completed, setCompleted] = useState(false)
const [isSendingData, setSendingData] = useState(false)
const [isDialogOpen, setDialogOpen] = useState(false)

const [data] = useState(state?.d1CaseData || templateProps)

const handleSubmit = async () => {
setSendingData(true)
await distribution_agreement(
{
...data,
rich_attachments: [...type9Attachment, ...type12Attachment]
},
data.token
)
.then(() => {
setCompleted(true)
setSendingData(false)
})
.catch(() => {
setSendingData(false)
setError('UPDATE_DIST_AGREEMENT_ERROR')
})
}

const updateAttachment = (values, type) => {
type === '09'
? setType9Attachment(values.map((el) => ({ type: type, data: el })))
: setType12Attachment(values.map((el) => ({ type: type, data: el })))
}

useEffect(() => {
i18n.changeLanguage(language)
}, [language, i18n])


const handleSubmitButton = () => {
if ([...type9Attachment, ...type12Attachment].length < 2) {
setDialogOpen(true)
} else {
handleSubmit()
}
}

return (
<ModDistAgreementData
isDialogOpen={isDialogOpen}
setDialogOpen={setDialogOpen}
type9Attachment={type9Attachment}
type12Attachment={type12Attachment}
error={error}
isSendingData={isSendingData}
completed={completed}
data={data}
updateAttachment={updateAttachment}
handleSubmitButton={handleSubmitButton}
handleSubmit={handleSubmit}
/>
)
}

export default React.memo(ModDistAgreement)
Loading