Skip to content

Commit

Permalink
chore: add cypress tests for name property
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen committed Sep 29, 2023
1 parent 8cb981c commit 00ca2ab
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 5 deletions.
33 changes: 33 additions & 0 deletions cypress/elements/thematic_layer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Layer } from './layer.js'

export class ThematicLayer extends Layer {
selectItemType(itemType) {
cy.getByDataTest('itemtypeselect').click()
cy.contains(itemType).click()

return this
}
selectIndicatorGroup(indicatorGroup) {
cy.get('[data-test="indicatorgroupselect"]').click()
cy.contains(indicatorGroup).click()
Expand All @@ -15,6 +21,33 @@ export class ThematicLayer extends Layer {
return this
}

selectDataElementGroup(dataElementGroup) {
cy.getByDataTest('dataelementgroupselect').click()
cy.getByDataTest('dhis2-uicore-singleselectoption')
.contains(dataElementGroup)
.click()

return this
}

selectDataElement(dataElement) {
cy.getByDataTest('dataelementselect').click()
cy.getByDataTest('dhis2-uicore-singleselectoption')
.contains(dataElement)
.click()

return this
}

selectDataElementOperand(dataElementOperand) {
cy.getByDataTest('dataelementoperandselect').click()
cy.getByDataTest('dhis2-uicore-singleselectoption')
.contains(dataElementOperand)
.click()

return this
}

selectPeriodType(periodType) {
cy.get('[data-test="periodtypeselect"]').click()
cy.contains(periodType).click()
Expand Down
56 changes: 55 additions & 1 deletion cypress/integration/usersettings.cy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ThematicLayer } from '../elements/thematic_layer.js'
import { EXTENDED_TIMEOUT, getApiBaseUrl } from '../support/util.js'

const testMap = {
Expand All @@ -17,7 +18,6 @@ describe('userSettings', () => {
body: 'nb',
}).then((response) => {
expect(response.status).to.eq(200)
cy.log('language switched to', response.message)

cy.visit(`/?id=${testMap.id}`)
cy.get('[data-test=layercard]')
Expand Down Expand Up @@ -66,4 +66,58 @@ describe('userSettings', () => {
})
})
})

it.only('uses the correct name property', () => {
cy.request({
method: 'POST',
url: `${getApiBaseUrl()}/api/userSettings/keyAnalysisDisplayProperty`,
headers: {
'Content-Type': 'text/plain',
},
body: 'shortName',
}).then((response) => {
expect(response.status).to.eq(200)

cy.visit('/')
const ThemLayer = new ThematicLayer()
ThemLayer.openDialog('Thematic')
.selectIndicatorGroup('ANC')
.selectIndicator('ANC visit clinical prof')

ThemLayer.selectItemType('Data element')
.selectDataElementGroup('Acute Flaccid Paralysis (AFP)')
.selectDataElement('AFP follow-up')

cy.get('input[type=radio][value=details]').click()
ThemLayer.selectDataElementOperand('AFP follow-up 0-11m')

cy.request({
method: 'POST',
url: `${getApiBaseUrl()}/api/userSettings/keyAnalysisDisplayProperty`,
headers: {
'Content-Type': 'text/plain',
},
body: 'name',
}).then((response) => {
expect(response.status).to.eq(200)

cy.visit('/')
const ThemLayer = new ThematicLayer()
ThemLayer.openDialog('Thematic')
.selectIndicatorGroup('ANC')
.selectIndicator('ANC visits per clinical professional')

ThemLayer.selectItemType('Data element')
.selectDataElementGroup('Acute Flaccid Paralysis (AFP)')
.selectDataElement(
'Acute Flaccid Paralysis (AFP) follow-up'
)

cy.get('input[type=radio][value=details]').click()
ThemLayer.selectDataElementOperand(
'Acute Flaccid Paralysis (AFP) follow-up 0-11m'
)
})
})
})
})
6 changes: 2 additions & 4 deletions src/components/app/FileMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FileMenu as UiFileMenu, useCachedDataQuery } from '@dhis2/analytics'
import { useDataMutation, useDataEngine } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { useAlert } from '@dhis2/app-service-alerts'
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -53,11 +52,10 @@ const getSaveFailureMessage = (message) =>
})

const FileMenu = ({ onFileMenuAction }) => {
const { d2 } = useD2()
const engine = useDataEngine()
const map = useSelector((state) => state.map)
const dispatch = useDispatch()
const { systemSettings, basemaps } = useCachedDataQuery()
const { systemSettings, currentUser, basemaps } = useCachedDataQuery()
const defaultBasemap = systemSettings.keyDefaultBaseMap
//alerts
const saveAlert = useAlert(ALERT_MESSAGE_DYNAMIC, ALERT_OPTIONS_DYNAMIC)
Expand Down Expand Up @@ -188,7 +186,7 @@ const FileMenu = ({ onFileMenuAction }) => {

return (
<UiFileMenu
currentUser={d2.currentUser}
currentUser={currentUser}
fileType="map"
fileObject={map}
onNew={onNew}
Expand Down
1 change: 1 addition & 0 deletions src/components/dataElement/DataElementGroupSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const DataElementGroupSelect = ({
error?.message ||
(!dataElementGroup && errorText ? errorText : null)
}
dataTest="dataelementgroupselect"
/>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/dataElement/DataElementOperandSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const DataElementOperandSelect = ({
errorText={
error?.message || (!dataElement && errorText ? errorText : null)
}
dataTest="dataelementoperandselect"
/>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/dataElement/DataElementSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const DataElementSelect = ({
errorText={
error?.message || (!dataElement && errorText ? errorText : null)
}
dataTest="dataelementselect"
/>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/edit/thematic/ValueTypeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ValueTypeSelect = (props) => {
value={type}
onChange={(valueType) => onChange(valueType.id)}
className={className}
dataTest="itemtypeselect"
/>
)
}
Expand Down

0 comments on commit 00ca2ab

Please sign in to comment.