Skip to content

Commit 9a05497

Browse files
committed
frontend/submission: implement upload attachment test
1 parent 9c0d4c4 commit 9a05497

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

frontend/submission/components/forms/AttachmentsList.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const AttachmentEntry = ({ id, description, onChangeDescription, blob, status, o
6666
</ListItemAvatar>
6767
<ListItemText
6868
primary={<TextField
69+
id={`attachment-description-${blob.name}`}
6970
variant='outlined'
7071
sx={{ width: '100%' }}
7172
label={t('attachment.description', { name: blob.name })}

frontend/submission/cypress/integration/5-attachment/attachments.spec.js

+39-16
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,35 @@ const gotoNextPage = () => {
66
}
77

88
describe('Minimal test, to check the setup before testing details', () => {
9-
it('Attach passport and tazkira', () => {
9+
it('Click through wizard and fill some of the forms', () => {
1010
cy.visit('/?token=demoToken')
11-
cy.get('input[id="#/properties/passport-file-input"]', {timeout: 30000})
11+
cy.log('In case of a dev build it might take some time to jit compile…')
12+
cy.log('The next test might fail, when the id is taken by another property with the same name. This sometimes happens with the combination of jsonforms and next dev builds.')
13+
cy.get('[data-testid="SendIcon"]').click()
14+
gotoNextPage()
15+
/** TODO We need proper test selectors from jsonforms inputs.
16+
* - selectors should be stable in next dev builds
17+
* - selectors should be uniq when properties are reused at different places or we always need select the parent component (form) first
18+
**/
19+
cy.get('input[id="#/properties/passportExisting-input"]', {timeout: 30000})
20+
.click()
21+
cy.wait(300)
22+
cy.get('input[id="passportAttachment-file-input"]', {timeout: 30000})
1223
.attachFile('passport.jpg')
13-
cy.get('input[id="#/properties/tazkira-file-input"]', {timeout: 30000})
24+
cy.get('input[id="#/properties/tazkiraExisting-input"]', {timeout: 30000})
25+
.click()
26+
cy.wait(300)
27+
cy.get('input[id="tazkiraAttachment-file-input"]', {timeout: 30000})
1428
.attachFile('tazkira.jpg')
1529
cy.wait(300)
1630

31+
cy.get('input[id="attachment-description-tazkira.jpg"]', {timeout: 30000})
32+
.type('This is my Tazkira')
33+
cy.wait(300)
34+
1735
gotoNextPage()
36+
cy.get('textarea[id="#/properties/risksCV-input"]')
37+
.type('risks…')
1838
})
1939

2040
it('Submit the formData', () => {
@@ -30,24 +50,27 @@ describe('Minimal test, to check the setup before testing details', () => {
3050
})
3151

3252
it('Decrypt formData', () => {
33-
cy.log('We expect, the test key is imported (gpg --import backend/data/keys/test.sec.gpg)') // TODO we should use a separate keyring
53+
// TODO we should use a separate keyring
54+
let formData
3455
cy.exec('(cd ../../backend/data/upload/demoToken/; gpg --decrypt --passphrase "test" "$(ls -t formData* | head -n1)")')
3556
.then($result => {
36-
const formData = JSON.parse($result.stdout)
37-
cy.log(formData)
57+
const formData_ = JSON.parse($result.stdout)
58+
formData = formData_
3859
expect(formData).to.have.any.keys('general')
39-
expect(formData.general).to.have.any.keys('firstName')
40-
expect(formData.general.firstName).to.equal('Max')
41-
expect(formData.general).to.have.any.keys('lastName')
42-
expect(formData.general.lastName).to.equal('Mustermann')
60+
expect(formData.general).to.have.any.keys('passportAttachment')
61+
expect(formData.general.passportAttachment.uploadStatus).to.equal(200)
62+
expect(formData.general.passportAttachment.fileType).to.equal('image/jpeg')
63+
expect(formData.general).to.have.any.keys('tazkiraAttachment')
64+
expect(formData.general.tazkiraAttachment.uploadStatus).to.equal(200)
65+
expect(formData.general.tazkiraAttachment.fileType).to.equal('image/jpeg')
66+
expect(formData.general.tazkiraAttachment.description).to.equal('This is my Tazkira')
4367
expect(formData).to.have.any.keys('risks')
4468
expect(formData.risks).to.have.any.keys('risksCV')
4569
expect(formData.risks.risksCV).to.equal('risks…')
46-
})
47-
cy.exec('(cd ../../backend/data/upload/demoToken/; ls -lct)")')
48-
.then($result => {
49-
cy.log($result.stdout)
50-
expect('').to.equal('fnord')
51-
})
70+
}).then(() =>
71+
cy.exec(`(cd ../../backend/data/upload/demoToken/; gpg --decrypt --passphrase "test" attachment_${formData.general.passportAttachment.id}_*.gpg) | cmp - cypress/fixtures/passport.jpg`)
72+
).then(() =>
73+
cy.exec(`(cd ../../backend/data/upload/demoToken/; gpg --decrypt --passphrase "test" attachment_${formData.general.tazkiraAttachment.id}_*.gpg) | cmp - cypress/fixtures/tazkira.jpg`)
74+
)
5275
})
5376
})

frontend/submission/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
1515
"jsx": "preserve",
16-
"incremental": true,
17-
"types": ["cypress", "cypress-file-upload"]
16+
"incremental": true
1817
},
1918
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
2019
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)