Skip to content

Commit

Permalink
test: add tests for numeric conditions (currently all skipped though)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott committed Jan 18, 2024
1 parent 610c1ee commit f7c5b22
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ describe(['>=41'], 'text conditions (TE)', { testIsolation: false }, () => {
openOrgUnitTreeItem('Bo')
openOrgUnitTreeItem('Badjia')
selectOrgUnitTreeItem('Njandama MCHP')

clickOrgUnitDimensionModalUpdateButton()

expectTableToBeVisible()
Expand Down
269 changes: 251 additions & 18 deletions cypress/integration/conditions/numericConditions.cy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DIMENSION_ID_ORGUNIT } from '@dhis2/analytics'
import { DIMENSION_ID_EVENT_DATE } from '../../../src/modules/dimensionConstants.js'
import {
E2E_PROGRAM,
Expand All @@ -13,16 +14,27 @@ import {
TEST_DIM_WITH_PRESET,
} from '../../data/index.js'
import {
clickAddRemoveTrackedEntityTypeDimensions,
openDimension,
openProgramDimensionsSidebar,
selectEventWithProgram,
selectEventWithProgramDimensions,
selectTrackedEntityWithType,
} from '../../helpers/dimensions.js'
import {
assertChipContainsText,
assertTooltipContainsEntries,
} from '../../helpers/layout.js'
import { clickMenubarUpdateButton } from '../../helpers/menubar.js'
import {
clickOrgUnitDimensionModalUpdateButton,
deselectUserOrgUnit,
expectOrgUnitDimensionModalToBeVisible,
expectOrgUnitDimensionToNotBeLoading,
openOrgUnitTreeItem,
openOuDimension,
selectOrgUnitTreeItem,
} from '../../helpers/orgUnit.js'
import {
getPreviousYearStr,
getCurrentYearStr,
Expand All @@ -44,21 +56,6 @@ const event = E2E_PROGRAM
const periodLabel = event[DIMENSION_ID_EVENT_DATE]
const stageName = 'Stage 1 - Repeatable'

const setUpTable = (dimensionName, period) => {
selectEventWithProgramDimensions({ ...event, dimensions: [dimensionName] })

selectRelativePeriod({
label: periodLabel,
period,
})

clickMenubarUpdateButton()

expectTableToBeVisible()

assertChipContainsText(dimensionName, 'all')
}

const addConditions = (conditions, dimensionName) => {
cy.getBySelLike('layout-chip').contains(dimensionName).click()
conditions.forEach(({ conditionName, value }) => {
Expand All @@ -76,12 +73,26 @@ const addConditions = (conditions, dimensionName) => {

/* This test doesn't look like it needs `testIsolation: false`
* but start failing once this is removed */
describe('number conditions', { testIsolation: false }, () => {
describe('number conditions (event)', { testIsolation: false }, () => {
const dimensionName = TEST_DIM_NUMBER

beforeEach(() => {
goToStartPage()
setUpTable(dimensionName, TEST_REL_PE_THIS_YEAR)
selectEventWithProgramDimensions({
...event,
dimensions: [dimensionName],
})

selectRelativePeriod({
label: periodLabel,
TEST_REL_PE_THIS_YEAR,
})

clickMenubarUpdateButton()

expectTableToBeVisible()

assertChipContainsText(dimensionName, 'all')
})

it('equal to', () => {
Expand Down Expand Up @@ -236,14 +247,236 @@ describe('number conditions', { testIsolation: false }, () => {
})
})

// TODO: backend issue, adding a condition throws an error, uncomment once fixed
describe.skip(
['>=41'],
'number conditions (TE)',
{ testIsolation: false },
() => {
const dimensionName = 'Age (years)'

beforeEach(() => {
goToStartPage()

selectTrackedEntityWithType('Malaria Entity')

cy.getBySel('main-sidebar')
.contains('Malaria Entity dimensions')
.click()
clickAddRemoveTrackedEntityTypeDimensions(dimensionName)

clickMenubarUpdateButton()

expectTableToBeVisible()

assertChipContainsText(dimensionName, 'all')
})

it('equal to', () => {
addConditions(
[{ conditionName: 'equal to (=)', value: '15' }],
dimensionName
)

expectTableToMatchRows(['15'])

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([stageName, 'Equal to (=): 15'])
})

it('greater than', () => {
addConditions(
[{ conditionName: 'greater than (>)', value: '43' }],
dimensionName
)

expectTableToMatchRows(['46', '64'])

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([stageName, 'Greater than (>): 43'])
})

it('greater than or equal to', () => {
addConditions(
[{ conditionName: 'greater than or equal to', value: '43' }],
dimensionName
)
expectTableToMatchRows(['43', '46', '64'])

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([
stageName,
'Greater than or equal to (≥): 43',
])
})

it('less than', () => {
addConditions(
[{ conditionName: 'less than (<)', value: '11' }],
dimensionName
)

expectTableToMatchRows([
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'6',
'9',
'9',
])

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([stageName, 'Less than (<): 11'])
})

it('less than or equal to', () => {
addConditions(
[{ conditionName: 'less than or equal to', value: '11' }],
dimensionName
)

expectTableToMatchRows([
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'6',
'9',
'9',
'11',
])

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([
stageName,
'Less than or equal to (≤): 11',
])
})

it('not equal to', () => {
openOuDimension(DIMENSION_ID_ORGUNIT)
expectOrgUnitDimensionModalToBeVisible()
expectOrgUnitDimensionToNotBeLoading()
deselectUserOrgUnit('User organisation unit')
openOrgUnitTreeItem('Bo')
openOrgUnitTreeItem('Badjia')
selectOrgUnitTreeItem('Njandama MCHP')
clickOrgUnitDimensionModalUpdateButton()

addConditions(
[{ conditionName: 'not equal to', value: '11' }],
dimensionName
)

expectTableToMatchRows(['0', '0', '26', '36'])

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([stageName, 'Not equal to (≠): 11'])
})

it('is empty / null', () => {
cy.getBySel('main-sidebar')
.contains('Malaria Entity dimensions')
.click()
clickAddRemoveTrackedEntityTypeDimensions('System Case ID')

addConditions([{ conditionName: 'is empty / null' }], dimensionName)

expectTableToMatchRows(['GFS397135', 'VCA989272', 'PVZ270497'])

getTableDataCells()
.eq(1)
.invoke('text')
.invoke('trim')
.should('equal', '')

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([stageName, 'Is empty / null'])
})

it('is not empty / not null', () => {
openOuDimension(DIMENSION_ID_ORGUNIT)
expectOrgUnitDimensionModalToBeVisible()
expectOrgUnitDimensionToNotBeLoading()
deselectUserOrgUnit('User organisation unit')
openOrgUnitTreeItem('Bo')
openOrgUnitTreeItem('Badjia')
selectOrgUnitTreeItem('Ngelehun CHC')
clickOrgUnitDimensionModalUpdateButton()

getTableRows().should('have.length', 32)

addConditions(
[{ conditionName: 'is not empty / not null' }],
dimensionName
)

getTableRows().should('have.length', 29)

assertChipContainsText(dimensionName, 1)

assertTooltipContainsEntries([stageName, 'Is not empty / not null'])
})

it('2 conditions: greater than + less than', () => {
addConditions(
[
{ conditionName: 'greater than (>)', value: '21' },
{ conditionName: 'less than (<)', value: '24' },
],
dimensionName
)

expectTableToMatchRows(['23'])

assertChipContainsText(dimensionName, 2)

assertTooltipContainsEntries([
stageName,
'Greater than (>): 21',
'Less than (<): 24',
])
})
}
)

/* This test doesn't look like it needs `testIsolation: false`
* but start failing once this is removed */
describe('integer', { testIsolation: false }, () => {
const dimensionName = TEST_DIM_INTEGER_ZERO_OR_POSITIVE

beforeEach(() => {
goToStartPage()
setUpTable(dimensionName, TEST_REL_PE_LAST_YEAR)

selectEventWithProgramDimensions({
...event,
dimensions: [dimensionName],
})

selectRelativePeriod({
label: periodLabel,
TEST_REL_PE_THIS_YEAR,
})

clickMenubarUpdateButton()

expectTableToBeVisible()

assertChipContainsText(dimensionName, 'all')
})

it('integer with negative value', () => {
Expand Down

0 comments on commit f7c5b22

Please sign in to comment.