Skip to content

Commit

Permalink
test(data element new form): add cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammer5 committed Mar 18, 2024
1 parent 7373ef0 commit 17291ea
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ cypress.env.json
.env.test.local
.env.production.local
cypress/screenshots/*
coverage/
coverage/
cypress.env.json
209 changes: 209 additions & 0 deletions cypress/e2e/dataElements/New.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
describe('Data elements', () => {
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')
})
})
16 changes: 14 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 17291ea

Please sign in to comment.