diff --git a/.gitignore b/.gitignore index 264c07f05c9..c4f4faac412 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ config/*/forms/contact/*.xlsx /**/*/.snapshots/local.json tests/integration/results/ allure* +tests/config-temp tests/utils/config-temp .eslintcache doc-conflicts/ @@ -61,4 +62,4 @@ user-password-change.csv /tests/e2e/visual/images/*.png .envrc release-notes.md -/scripts/build/helm/values.yaml \ No newline at end of file +/scripts/build/helm/values.yaml diff --git a/eslint.config.js b/eslint.config.js index 4f376c4a77b..c39ba3ca1d9 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -51,7 +51,6 @@ module.exports = defineConfig([ 'shared-libs/cht-datasource/docs/**/*', 'tests/scalability/report*/**/*', 'tests/scalability/jmeter/**/*', - 'webapp/src/ts/providers/xpath-element-path.provider.ts', 'webapp/dist/**/*', '.github/**/compiled/index.js' ]), diff --git a/tests/e2e/default/contacts/contact-attachments.wdio-spec.js b/tests/e2e/default/contacts/contact-attachments.wdio-spec.js index 0cb104e711d..e90842df843 100644 --- a/tests/e2e/default/contacts/contact-attachments.wdio-spec.js +++ b/tests/e2e/default/contacts/contact-attachments.wdio-spec.js @@ -14,7 +14,6 @@ const { CONTACT_TYPES } = require('@medic/constants'); describe('Contact form attachments', () => { const photoPngPath = path.join(__dirname, '../enketo/images/photo-for-upload-form.png'); const layersPngPath = path.join(__dirname, '../../../../webapp/src/img/layers.png'); - const places = placeFactory.generateHierarchy(); const healthCenter = places.get(CONTACT_TYPES.HEALTH_CENTER); @@ -44,42 +43,15 @@ describe('Contact form attachments', () => { 'contact.type.person_with_attachments.edit': 'Edit Person With Attachments' }; - const createFormXml = fs.readFileSync( - path.join(__dirname, 'forms/person-with-attachments-create.xml'), - 'utf8' + const createFormDoc = commonPage.createFormDoc( + path.join(__dirname, 'forms/person-with-attachments-create'), + 'contact:person_with_attachments:create' ); - - const editFormXml = fs.readFileSync( - path.join(__dirname, 'forms/person-with-attachments-edit.xml'), - 'utf8' + const editFormDoc = commonPage.createFormDoc( + path.join(__dirname, 'forms/person-with-attachments-edit'), + 'contact:person_with_attachments:edit' ); - const createFormDoc = { - _id: 'form:contact:person_with_attachments:create', - internalId: 'contact:person_with_attachments:create', - title: 'New Person With Attachments', - type: 'form', - _attachments: { - xml: { - content_type: 'application/octet-stream', - data: Buffer.from(createFormXml).toString('base64'), - } - } - }; - - const editFormDoc = { - _id: 'form:contact:person_with_attachments:edit', - internalId: 'contact:person_with_attachments:edit', - title: 'Edit Person With Attachments', - type: 'form', - _attachments: { - xml: { - content_type: 'application/octet-stream', - data: Buffer.from(editFormXml).toString('base64'), - } - } - }; - const createContactWithAttachment = (contactName, imagePath = photoPngPath) => { const imageBuffer = fs.readFileSync(imagePath); const imageBase64 = imageBuffer.toString('base64'); @@ -128,37 +100,6 @@ describe('Contact form attachments', () => { await commonPage.waitForPageLoaded(); }); - it('should create contact with image attachment', async () => { - const contactName = 'Test Person With Photo'; - - await commonPage.goToPeople(healthCenter._id); - await commonPage.clickFastActionFAB({ actionId: personWithAttachmentsType.id }); - - await commonEnketoPage.setInputValue('Full name', contactName); - await commonEnketoPage.addFileInputValue('Photo', photoPngPath); - - await genericForm.submitForm(); - await commonPage.waitForPageLoaded(); - await contactPage.waitForContactLoaded(); - - const contactId = await contactPage.getCurrentContactId(); - expect(contactId).to.exist; - - const createdContact = await utils.getDoc(contactId); - - expect(createdContact).to.exist; - expect(createdContact.name).to.equal(contactName); - expect(createdContact._attachments).to.exist; - - const attachmentNames = Object.keys(createdContact._attachments); - expect(attachmentNames).to.have.lengthOf(1); - expect(attachmentNames[0]).to.match(/^user-file-photo-for-upload-form.*\.png$/); - - const attachment = createdContact._attachments[attachmentNames[0]]; - expect(attachment.content_type).to.equal('image/png'); - expect(attachment.length, 'Attachment should have a valid size').to.be.greaterThan(0); - }); - it('should create contact with multiple attachments (image + document)', async () => { const contactName = 'Test Person With Multiple Files'; @@ -183,7 +124,7 @@ describe('Contact form attachments', () => { expect(createdContact._attachments).to.exist; const attachmentNames = Object.keys(createdContact._attachments); - expect(attachmentNames).to.have.lengthOf(2); + expect(attachmentNames).to.have.lengthOf(3); const photoAttachment = attachmentNames.find(name => name.match(/^user-file-photo-for-upload-form.*\.png$/)); const documentAttachment = attachmentNames.find(name => name.match(/^user-file-layers.*\.png$/)); @@ -198,6 +139,9 @@ describe('Contact form attachments', () => { expect(createdContact._attachments[documentAttachment].content_type).to.equal('image/png'); expect(createdContact._attachments[documentAttachment].length, 'Document should have a valid size') .to.be.greaterThan(0); + + expect(createdContact._attachments['user-file/badge'].content_type).to.equal('image/png'); + expect(createdContact._attachments['user-file/badge'].length).to.be.greaterThan(0); }); it('should preserve attachments when editing contact', async () => { @@ -221,7 +165,9 @@ describe('Contact form attachments', () => { const contactBefore = await utils.getDoc(contactId); expect(contactBefore._attachments).to.exist; const originalAttachments = Object.keys(contactBefore._attachments); - expect(originalAttachments).to.have.lengthOf(1); + expect(originalAttachments).to.have.lengthOf(2); + expect(originalAttachments[0]).to.match(/^user-file-photo-for-upload-form.*\.png$/); + expect(originalAttachments[1]).to.equal('user-file/badge'); await commonPage.accessEditOption(); @@ -237,10 +183,11 @@ describe('Contact form attachments', () => { expect(contactAfter._attachments).to.exist; const attachmentsAfter = Object.keys(contactAfter._attachments); - expect(attachmentsAfter).to.have.lengthOf(1); - expect(attachmentsAfter[0]).to.equal(originalAttachments[0]); + expect(attachmentsAfter).to.deep.equal(originalAttachments); expect(contactAfter._attachments[attachmentsAfter[0]].length, 'Preserved attachment should have a valid size') .to.be.greaterThan(0); + expect(contactAfter._attachments[attachmentsAfter[1]].length, 'Preserved attachment should have a valid size') + .to.be.greaterThan(0); }); it('should remove attachment when editing contact', async () => { diff --git a/tests/e2e/default/contacts/forms/health_center-with-attachments-create.xlsx b/tests/e2e/default/contacts/forms/health_center-with-attachments-create.xlsx new file mode 100644 index 00000000000..e684834e208 Binary files /dev/null and b/tests/e2e/default/contacts/forms/health_center-with-attachments-create.xlsx differ diff --git a/tests/e2e/default/contacts/forms/health_center-with-attachments-create.xml b/tests/e2e/default/contacts/forms/health_center-with-attachments-create.xml new file mode 100644 index 00000000000..dbf4209243c --- /dev/null +++ b/tests/e2e/default/contacts/forms/health_center-with-attachments-create.xml @@ -0,0 +1,174 @@ + + + + New Health Center + + + + + Parent District Hospital + + + Parent Name + + + Parent Badge + + + Parent Photo + + + Primary Contact for Heath Center + + + Contact Name + + + Contact Badge + + + Contact Photo + + + Heath Center + + + Health Center Name + + + Health Center Badge + + + Health Center Photo + + + Add Clinics + + + Clinic + + + Child Name + + + Child Badge + + + Child Photo + + + + + + + + + + + + + PARENT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/e2e/default/contacts/forms/health_center-with-attachments-edit.xlsx b/tests/e2e/default/contacts/forms/health_center-with-attachments-edit.xlsx new file mode 100644 index 00000000000..de52ed12212 Binary files /dev/null and b/tests/e2e/default/contacts/forms/health_center-with-attachments-edit.xlsx differ diff --git a/tests/e2e/default/contacts/forms/health_center-with-attachments-edit.xml b/tests/e2e/default/contacts/forms/health_center-with-attachments-edit.xml new file mode 100644 index 00000000000..71ac824f1dd --- /dev/null +++ b/tests/e2e/default/contacts/forms/health_center-with-attachments-edit.xml @@ -0,0 +1,90 @@ + + + + Edit Health Center + + + + + Heath Center + + + Health Center Name + + + Health Center Photo + + + Add Clinics + + + Clinic + + + Child Name + + + Child Photo + + + Child Badge + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/e2e/default/contacts/forms/person-with-attachments-create.xml b/tests/e2e/default/contacts/forms/person-with-attachments-create.xml index 557cd27200b..21f85efe6fa 100644 --- a/tests/e2e/default/contacts/forms/person-with-attachments-create.xml +++ b/tests/e2e/default/contacts/forms/person-with-attachments-create.xml @@ -14,6 +14,9 @@ Document + + Badge + @@ -24,6 +27,7 @@ + iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mP8z8BQz0AEYBxVSF+FABJADveWkH6oAAAAAElFTkSuQmCC @@ -35,6 +39,7 @@ + @@ -49,6 +54,9 @@ + +