From 8d6fe9baa022894a1034488001ac9b162d091ff0 Mon Sep 17 00:00:00 2001 From: Mohammer5 Date: Wed, 13 Mar 2024 15:14:15 +0800 Subject: [PATCH] test(data element new form): add cypress test --- .gitignore | 3 +- cypress/e2e/dataElements/New.spec.ts | 209 +++++++++++++++++++++++++++ i18n/en.pot | 16 +- 3 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 cypress/e2e/dataElements/New.spec.ts diff --git a/.gitignore b/.gitignore index 196a4d6a..732e9121 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ cypress.env.json .env.test.local .env.production.local cypress/screenshots/* -coverage/ \ No newline at end of file +coverage/ +cypress.env.json diff --git a/cypress/e2e/dataElements/New.spec.ts b/cypress/e2e/dataElements/New.spec.ts new file mode 100644 index 00000000..9a6fcbb4 --- /dev/null +++ b/cypress/e2e/dataElements/New.spec.ts @@ -0,0 +1,209 @@ +describe('Data elements / New', () => { + it('should create a data element with only the required values', () => { + const now = Date.now() + const newDataElementName = `ZZZ ${now}` // Will be at the end, does not pollute the first page of the list + + cy.visit('/') + + // Open data elements group in side nav + cy.get('[data-test="sidenav"] button:contains("Data elements")', { + timeout: 10000, + }).click() + + // Navigate to data element list view + cy.get('[data-test="sidenav"] a:contains("Data element")') + .first() // the selector will also grab "Data element group" and "Data element group set" + .click() + + // Go to New form + cy.get('button:contains("New")').click() + + cy.get('[data-test="formfields-name-content"] input').type( + newDataElementName + ) + cy.get('[data-test="formfields-shortname-content"] input').type( + `shortname ${now}` + ) + cy.get( + '[data-test="formfields-categorycombo"] [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-singleselectoption"]:contains("None")' + ).click() + + // Submit form + cy.get('button:contains("Create data element")').click() + + cy.contains('Data element management').should('exist') + }) + + it('should create a data element with all values', () => { + const now = Date.now() + const newDataElementName = `ZZZ ${now}` // Will be at the end, does not pollute the first page of the list + + cy.visit('/') + + // Open data elements group in side nav + cy.get('[data-test="sidenav"] button:contains("Data elements")', { + timeout: 10000, + }).click() + + // Navigate to data element list view + cy.get('[data-test="sidenav"] a:contains("Data element")') + .first() // the selector will also grab "Data element group" and "Data element group set" + .click() + + // Go to New form + cy.get('button:contains("New")').click() + + cy.get('[data-test="formfields-name"] input').type(newDataElementName) + cy.get('[data-test="formfields-shortname"] input').type( + `Short name ${now}` + ) + cy.get('[data-test="formfields-formname"] input').type( + `Form name ${now}` + ) + cy.get('[data-test="formfields-code"] input').type(`Code ${now}`) + cy.get('[data-test="formfields-description"] textarea').type( + `Multiline{enter}description ${now}` + ) + cy.get('[data-test="formfields-url"] input').type( + `https://dhis2.org ${now}` + ) + + // pick color + cy.get('[data-test="colorpicker-trigger"]').click() + cy.get('[title="#b71c1c"]').click() + + // icon color + cy.get('[data-test="iconpicker-trigger"]').click() + cy.get('[data-test="dhis2-uicore-modal"] img[src$="/icon"]') + .first() + .click() + cy.get( + '[data-test="dhis2-uicore-modal"] button:contains("Select")' + ).click() + + cy.get('[data-test="formfields-fieldmask"] input').type( + `000 1111 000 ${now}` + ) + cy.get('[data-test="formfields-zeroissignificant"] input').check() + + // Select value type + cy.get( + '[data-test="formfields-valuetype"] [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-singleselectoption"]:contains("Integer")' + ).click() + + // Select aggregation type + cy.get( + '[data-test="formfields-aggregationtype"] [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-singleselectoption"]:contains("Sum")' + ).click() + + // Select category combo + cy.get( + '[data-test="formfields-categorycombo"] [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-singleselectoption"]:contains("None")' + ).click() + + // Select category combo + cy.get( + '[data-test="formfields-optionset"] [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-singleselectoption"]:contains("ARV drugs")' + ).click() + + // Select category combo + cy.get( + '[data-test="formfields-commentoptionset"] [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-singleselectoption"]:contains("ARV treatment plan")' + ).click() + + // Select legend sets + cy.get( + '[data-test="formfields-legendsets"] [data-test="dhis2-uicore-transferoption"]:contains("ANC Coverage")' + ).dblclick() + cy.get( + '[data-test="formfields-legendsets"] [data-test="dhis2-uicore-transferoption"]:contains("Age 10y interval")' + ).dblclick() + + // Select aggregation levels + cy.get( + '[data-test="formfields-aggregationlevels"] [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-checkbox"]:contains("Chiefdom")' + ).click() + cy.get( + '[data-test="dhis2-uicore-checkbox"]:contains("District")' + ).click() + cy.get('.backdrop').click() + + // Select custom attribute "Classification" + cy.get( + '[data-test="dhis2-uiwidgets-singleselectfield"]:contains("Classification") [data-test="dhis2-uicore-select-input"]' + ).click() + cy.get( + '[data-test="dhis2-uicore-singleselectoption"]:contains("Input")' + ).click() + + cy.get('[name="attributeValues[1].value"]').type( + `Collection{enter}method! ${now}` + ) + cy.get('[name="attributeValues[2].value"]').type(`PEPFAR ID! ${now}`) + cy.get('[name="attributeValues[3].value"]').type(`Rationale! ${now}`) + cy.get('[name="attributeValues[4].value"]').type( + `Unit of measure! ${now}` + ) + + // Submit form + cy.get('button:contains("Create data element")').click() + + cy.contains('Data element management').should('exist') + }) + + it('should not create a DE when reuired fields are missing', () => { + cy.visit('/') + + // Open data elements group in side nav + cy.get('[data-test="sidenav"] button:contains("Data elements")', { + timeout: 10000, + }).click() + + // Navigate to data element list view + cy.get('[data-test="sidenav"] a:contains("Data element")') + .first() // the selector will also grab "Data element group" and "Data element group set" + .click() + + // Go to New form + cy.get('button:contains("New")').click() + + // Submit form + cy.get('button:contains("Create data element")').click() + + // Should have required errors for name, shortname and cat combo + cy.get('[data-test$="-validation"]:contains("Required")').should( + 'have.length', + 3 + ) + cy.get( + '[data-test="formfields-name-validation"]:contains("Required")' + ).should('exist') + cy.get( + '[data-test="formfields-shortname-validation"]:contains("Required")' + ).should('exist') + cy.get( + '[data-test="formfields-categorycombo-validation"]:contains("Required")' + ).should('exist') + }) +}) diff --git a/i18n/en.pot b/i18n/en.pot index b752ce00..21085e8b 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-03-13T07:12:06.820Z\n" -"PO-Revision-Date: 2024-03-13T07:12:06.820Z\n" +"POT-Creation-Date: 2024-03-18T02:31:48.399Z\n" +"PO-Revision-Date: 2024-03-18T02:31:48.399Z\n" msgid "schemas" msgstr "schemas" @@ -252,12 +252,21 @@ msgstr "Public access" msgid "Show details" msgstr "Show details" +msgid "Sharing settings" +msgstr "Sharing settings" + msgid "At least one column must be selected" msgstr "At least one column must be selected" msgid "At least one filter must be selected" msgstr "At least one filter must be selected" +msgid "Columns" +msgstr "Columns" + +msgid "Filters" +msgstr "Filters" + msgid "Available columns" msgstr "Available columns" @@ -552,6 +561,9 @@ msgstr "Locale" msgid "Locales" msgstr "Locales" +msgid "You do not have access to edit this item." +msgstr "You do not have access to edit this item." + msgid "Sum" msgstr "Sum"