Skip to content

Commit

Permalink
chore: update cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BRaimbault committed Dec 27, 2024
1 parent 0ca7358 commit 12ac3a2
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 37 deletions.
22 changes: 17 additions & 5 deletions cypress/elements/thematic_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ export class ThematicLayer extends Layer {
return this
}

selectPeriodType(periodType, periodDimension = 'fixed', n = 'last') {
removeAllPeriods() {
cy.getByDataTest('period-dimension-transfer-actions-removeall').click()

return this
}

/* eslint-disable max-params */
selectPeriodType(
periodType,
periodDimension = 'fixed',
n = 'last',
removeAll = true
) {
cy.getByDataTest(
`period-dimension-${periodDimension}-periods-button`
).click()
Expand All @@ -71,24 +83,24 @@ export class ThematicLayer extends Layer {
cy.wrap($el).click()
}
})
if (n === 'last') {
if (removeAll) {
cy.getByDataTest(
'period-dimension-transfer-actions-removeall'
).click()
}
if (n === 'last') {
cy.getByDataTest('period-dimension-transfer-option-content')
.last()
.dblclick()
} else {
cy.getByDataTest(
'period-dimension-transfer-actions-removeall'
).click()
cy.getByDataTest('period-dimension-transfer-option-content')
.eq(n)
.dblclick()
}

return this
}
/* eslint-enable max-params */

selectPresets() {
cy.contains('Choose from presets').click()
Expand Down
File renamed without changes.
46 changes: 44 additions & 2 deletions cypress/integration/layers/eventlayer.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventLayer } from '../../elements/event_layer.js'
import { EXTENDED_TIMEOUT } from '../../support/util.js'
import { CURRENT_YEAR, EXTENDED_TIMEOUT } from '../../support/util.js'

context('Event Layers', () => {
beforeEach(() => {
Expand Down Expand Up @@ -38,7 +38,24 @@ context('Event Layers', () => {
cy.contains('Program is required').should('be.visible')
})

it('adds an event layer', () => {
it('shows error if no endDate is specified', () => {
Layer.openDialog('Events')
.selectProgram('Inpatient morbidity and mortality')
.validateStage('Inpatient morbidity and mortality')
.selectTab('Period')
.selectPeriodType('Start/end dates')
.typeStartDate(`${CURRENT_YEAR - 5}-02-01`)
.addToMap()

Layer.validateDialogClosed(false)
cy.contains('End date is invalid').should('be.visible')

Layer.selectTab('Period').typeEndDate('2')

cy.contains('End date is invalid').should('not.exist')
})

it('adds an event layer - relative period', () => {
Layer.openDialog('Events')
.selectProgram('Inpatient morbidity and mortality')
.validateStage('Inpatient morbidity and mortality')
Expand All @@ -53,6 +70,31 @@ context('Event Layers', () => {
Layer.validateCardItems(['Event'])
})

it('adds an event layer - start-end dates', () => {
Layer.openDialog('Events')
.selectProgram('Inpatient morbidity and mortality')
.validateStage('Inpatient morbidity and mortality')
.selectTab('Period')
.selectPeriodType('Start/end dates')
.typeStartDate(`${CURRENT_YEAR - 5}-00-00`)
.typeEndDate(`${CURRENT_YEAR}-11-30`)
.selectTab('Org Units')
.selectOu('Bombali')
.selectOu('Bo')
.selectTab('Style')
.selectViewAllEvents()
.addToMap()

Layer.validateDialogClosed(true)

Layer.validateCardTitle(
'Inpatient morbidity and mortality'
).validateCardPeriod(
`Feb 1, ${CURRENT_YEAR - 5} - Nov 30, ${CURRENT_YEAR}`
)
Layer.validateCardItems(['Event'])
})

it('opens an event popup', () => {
Layer.openDialog('Events')
.selectProgram('Inpatient morbidity and mortality')
Expand Down
107 changes: 107 additions & 0 deletions cypress/integration/layers/thematiclayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ context('Thematic Layers', () => {
cy.contains('Indicator is required').should('be.visible')
})

it('shows error in layer edit modal if no period selected', () => {
Layer.openDialog('Thematic')
.selectIndicatorGroup('HIV')
.selectIndicator(INDICATOR_NAME)
.selectTab('Period')
.removeAllPeriods()
.addToMap()

Layer.validateDialogClosed(false)
cy.contains('Period is required').should('be.visible')

Layer.selectTab('Period').selectStartEndDates()
cy.contains('Period is required').should('not.exist')

Layer.selectTab('Period').typeStartDate('2018-01-01').addToMap()

Layer.validateDialogClosed(false)
cy.contains('End date is invalid').should('be.visible')

Layer.selectTab('Period').typeEndDate('2')

cy.contains('End date is invalid').should('not.exist')
})

it('adds a thematic layer', () => {
Layer.openDialog('Thematic')
.selectIndicatorGroup('HIV')
Expand Down Expand Up @@ -168,6 +192,89 @@ context('Thematic Layers', () => {
.should('be.visible')
})

it('available rendering strategies depend on selected periods', () => {
Layer.openDialog('Thematic').selectTab('Period').removeAllPeriods()
cy.get('input[value="SINGLE"]').should('not.be.disabled')
cy.get('input[value="TIMELINE"]').should('be.disabled')
cy.get('input[value="SPLIT_BY_PERIOD"]').should('be.disabled')
cy.contains(
'Select 2 or more periods to enable timeline or split map views.'
).should('be.visible')

Layer.selectTab('Period').selectPeriodType(
'QUARTERLY',
'relative',
2,
false
)
cy.get('input[value="SINGLE"]').should('not.be.disabled')
cy.get('input[value="TIMELINE"]').should('not.be.disabled')
cy.get('input[value="SPLIT_BY_PERIOD"]').should('not.be.disabled')
cy.contains(
'Select 2 or more periods to enable timeline or split map views.'
).should('not.exist')

Layer.selectTab('Period').selectPeriodType(
'DAILY',
'relative',
4,
false
)
cy.get('input[value="SINGLE"]').should('not.be.disabled')
cy.get('input[value="TIMELINE"]').should('not.be.disabled')
cy.get('input[value="SPLIT_BY_PERIOD"]').should('be.disabled')
cy.contains(
'Only up to 12 periods can be selected to enable split map views.'
).should('be.visible')
})

it('adds a thematic layer with timeline period', () => {
Layer.openDialog('Thematic')
.selectIndicatorGroup('ANC')
.selectIndicator('ANC 1 Coverage')
.selectTab('Period')
.selectPeriodType('QUARTERLY', 'relative', 2)
.selectPeriodType('YEARLY', 'fixed', 8, false)

cy.get('[type="radio"]').should('have.length', 3)
cy.get('[type="radio"]').check('TIMELINE')

cy.getByDataTest('dhis2-uicore-modalactions')
.contains('Add layer')
.click()

Layer.validateDialogClosed(true)

cy.get('.dhis2-map-period').should('be.visible')
cy.get('svg.dhis2-map-timeline').find('rect').should('have.length', 5)
cy.get('svg.dhis2-map-timeline')
.find('rect')
.first()
.invoke('attr', 'class')
.should('contain', 'Timeline_selected')

cy.get('.play-icon').click()
cy.get('.pause-icon').should('be.visible')
cy.wait((5 - 1) * 1500)

cy.get('svg.dhis2-map-timeline')
.find('rect')
.last()
.invoke('attr', 'class')
.should('contain', 'Timeline_selected')
cy.get('.play-icon').should('be.visible')

Layer.openDialog('Thematic').selectTab('Period')

cy.get('input[value="SINGLE"]').should('not.be.disabled')
cy.get('input[value="TIMELINE"]').should('be.disabled')
cy.get('input[value="SPLIT_BY_PERIOD"]').should('be.disabled')
cy.contains('Only one timeline is allowed.').should('be.visible')
cy.contains('Remove other layers to enable split map views.').should(
'be.visible'
)
})

it('adds a thematic layer with split view period', () => {
Layer.openDialog('Thematic')
.selectIndicatorGroup('ANC')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TeLayer } from '../../elements/te_layer.js'
import { TeLayer } from '../../elements/trackedentity_layer.js'
import { EXTENDED_TIMEOUT } from '../../support/util.js'

describe('Tracked Entity Layers', () => {
Expand All @@ -8,13 +8,33 @@ describe('Tracked Entity Layers', () => {

const Layer = new TeLayer()

it('adds a tracked entity layer', () => {
Layer.openDialog('Tracked entities')
.selectTab('Data')
.selectTeType('Malaria Entity')
.selectTeProgram(
'Malaria case diagnosis, treatment and investigation'
)
.selectTab('Org Units')
.selectOu('Bombali')
.selectOu('Bo')
.addToMap()

Layer.validateDialogClosed(true)

Layer.validateCardTitle(
'Malaria case diagnosis, treatment and investigation'
)
Layer.validateCardItems(['Malaria Entity'])
})

it('opens a tracked entity layer popup', () => {
Layer.openDialog('Tracked entities')
.selectTab('Data')
.selectTeType('Focus area')
.selectTeProgram('Malaria focus investigation')
.selectTab('Period')
.typeStartDate('2018-01-01')
.typeStartDate('2018-00-00')
.selectTab('Org Units')

cy.getByDataTest('org-unit-tree-node')
Expand Down Expand Up @@ -61,23 +81,29 @@ describe('Tracked Entity Layers', () => {
Layer.validateCardItems(['Focus area'])
})

it('adds a tracked entity layer', () => {
it('shows error if no tracked entity type selected', () => {
Layer.openDialog('Tracked entities').addToMap()

Layer.validateDialogClosed(false)

cy.contains('Tracked Entity Type is required').should('be.visible')
})

it('shows error if no endDate is specified', () => {
Layer.openDialog('Tracked entities')
.selectTab('Data')
.selectTeType('Malaria Entity')
.selectTeProgram(
'Malaria case diagnosis, treatment and investigation'
)
.selectTab('Org Units')
.selectOu('Bombali')
.selectOu('Bo')
.selectTeType('Focus area')
.selectTeProgram('Malaria focus investigation')
.selectTab('Period')
.typeStartDate('2018-01-01')
.typeEndDate('2')
.addToMap()

Layer.validateDialogClosed(true)
Layer.validateDialogClosed(false)
cy.contains('End date is invalid').should('be.visible')

Layer.validateCardTitle(
'Malaria case diagnosis, treatment and investigation'
)
Layer.validateCardItems(['Malaria Entity'])
Layer.selectTab('Period').typeEndDate('2')

cy.contains('End date is invalid').should('not.exist')
})
})
24 changes: 12 additions & 12 deletions cypress/integration/systemsettings.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ describe('systemSettings', () => {
'period-dimension-relative-period-filter-content'
).click()

cy.getByDataTest('dhis2-uicore-select-menu-menuwrapper')
.contains('Bi-weeks')
.should('be.visible')
cy.getByDataTest(
'period-dimension-relative-period-filter-option-BIWEEKLY'
).should('be.visible')

cy.getByDataTest('dhis2-uicore-select-menu-menuwrapper')
.contains('Weeks')
.should('not.exist')
cy.getByDataTest(
'period-dimension-relative-period-filter-option-WEEKLY'
).should('not.exist')
})

it('includes Weekly period type when weekly periods not hidden in system settings', () => {
Expand All @@ -58,13 +58,13 @@ describe('systemSettings', () => {
'period-dimension-relative-period-filter-content'
).click()

cy.getByDataTest('dhis2-uicore-select-menu-menuwrapper')
.contains('Bi-weeks')
.should('be.visible')
cy.getByDataTest(
'period-dimension-relative-period-filter-option-BIWEEKLY'
).should('be.visible')

cy.getByDataTest('dhis2-uicore-select-menu-menuwrapper')
.contains('Weeks')
.should('be.visible')
cy.getByDataTest(
'period-dimension-relative-period-filter-option-WEEKLY'
).should('be.visible')
})

it('uses Last 6 months as default relative period', () => {
Expand Down
7 changes: 5 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-12-24T08:04:42.345Z\n"
"PO-Revision-Date: 2024-12-24T08:04:42.345Z\n"
"POT-Creation-Date: 2024-12-27T23:49:08.516Z\n"
"PO-Revision-Date: 2024-12-27T23:49:08.516Z\n"

msgid "2020"
msgstr "2020"
Expand Down Expand Up @@ -551,6 +551,9 @@ msgstr "Related entity style"
msgid "Line Color"
msgstr "Line Color"

msgid "Tracked Entity Type is required"
msgstr "Tracked Entity Type is required"

msgid "No relationship types were found for tracked entity type {{type}}"
msgstr "No relationship types were found for tracked entity type {{type}}"

Expand Down
2 changes: 1 addition & 1 deletion src/components/edit/trackedEntity/TrackedEntityDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class TrackedEntityDialog extends Component {
if (!trackedEntityType) {
return this.setErrorState(
'trackedEntityTypeError',
i18n.t('This field is required'),
i18n.t('Tracked Entity Type is required'),
'data'
)
}
Expand Down

0 comments on commit 12ac3a2

Please sign in to comment.