Skip to content

Commit

Permalink
test: add Cypress tests for SV icon (DHIS2-10496) (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott authored and janhenrikoverland committed Aug 15, 2023
1 parent eee29fb commit b233883
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cypress/elements/dimensionModal/dataDimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export const expectGroupSelectToBe = (group) =>

export const switchGroupTo = (group) => {
cy.getBySel(groupSelectButtonEl).click()
cy.getBySelLike(groupSelectOptionEl).should('have.length.least', 2)
cy.getBySelLike('singleselect-loading').should('not.exist')
cy.getBySelLike(groupSelectOptionEl).contains(group).click()
}

Expand Down
7 changes: 7 additions & 0 deletions cypress/elements/optionsModal/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const legendKeyEl = 'visualization-legend-key'
const legendKeyContainerEl = 'legend-key-container'
const legendKeyItemEl = 'legend-key-item'
const singleValueTextEl = 'visualization-primary-value'
const singleValueIconEl = 'visualization-icon'
const singleValueOutputEl = 'visualization-container'
const legendDisplayStrategyByDataItemEl = 'legend-display-strategy-BY_DATA_ITEM'
const legendDisplayStrategyFixedEl = 'legend-display-strategy-FIXED'
Expand Down Expand Up @@ -89,6 +90,12 @@ export const expectSingleValueToHaveBackgroundColor = (color) =>
.invoke('attr', 'style')
.should('contain', `background-color: ${color}`)

export const expectSingleValueToHaveIconColor = (color) =>
cy
.getBySel(singleValueIconEl)
.invoke('attr', 'style')
.should('contain', `color: ${color}`)

export const toggleLegendKeyOption = () =>
cy.getBySel(optionsModalContentEl).contains('Show legend key').click()

Expand Down
187 changes: 187 additions & 0 deletions cypress/integration/options/icon.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import {
DIMENSION_ID_DATA,
DIMENSION_ID_PERIOD,
DIMENSION_TYPE_DATA_ELEMENT,
DIMENSION_TYPE_DATA_SET,
DIMENSION_TYPE_EVENT_DATA_ITEM,
DIMENSION_TYPE_INDICATOR,
DIMENSION_TYPE_PROGRAM_INDICATOR,
VIS_TYPE_SINGLE_VALUE,
visTypeDisplayNames,
} from '@dhis2/analytics'
import { expectVisualizationToBeVisible } from '../../elements/chart.js'
import { clickCheckbox } from '../../elements/common.js'
import {
expectSelectableDataItemsAmountToBeLeast,
switchDataTypeTo,
switchGroupTo,
switchSubGroupTo,
} from '../../elements/dimensionModal/dataDimension.js'
import {
clickDimensionModalHideButton,
clickDimensionModalUpdateButton,
expectDataDimensionModalToBeVisible,
expectItemToBeSelected,
inputSearchTerm,
selectItemByDoubleClick,
selectRelativePeriods,
unselectAllItemsByButton,
} from '../../elements/dimensionModal/index.js'
import { openDimension } from '../../elements/dimensionsPanel.js'
import { clickMenuBarOptionsButton } from '../../elements/menuBar.js'
import {
OPTIONS_TAB_LEGEND,
OPTIONS_TAB_STYLE,
clickOptionsModalHideButton,
clickOptionsModalUpdateButton,
clickOptionsTab,
} from '../../elements/optionsModal/index.js'
import {
changeDisplayStrategyToFixed,
changeDisplayStyleToText,
changeFixedLegendSet,
expectSingleValueToHaveIconColor,
toggleLegend,
} from '../../elements/optionsModal/legend.js'
import { goToStartPage } from '../../elements/startScreen.js'
import { changeVisType } from '../../elements/visualizationTypeSelector.js'

const expectIconToBeVisible = () => {
cy.getBySelLike('visualization-icon')
.should('have.length', 1)
.and('be.visible')
}

const expectIconToBeHidden = () => {
cy.getBySelLike('visualization-icon').should('not.exist')
}

const TEST_TYPES = [
DIMENSION_TYPE_INDICATOR,
DIMENSION_TYPE_DATA_ELEMENT,
DIMENSION_TYPE_DATA_SET,
DIMENSION_TYPE_EVENT_DATA_ITEM,
DIMENSION_TYPE_PROGRAM_INDICATOR,
]

const TEST_ITEMS = {
[DIMENSION_TYPE_INDICATOR]: 'ANC 2 Coverage',
[DIMENSION_TYPE_DATA_ELEMENT]: 'ANC 2nd visit',
[DIMENSION_TYPE_DATA_SET]: 'Child Health',
[DIMENSION_TYPE_EVENT_DATA_ITEM]: 'MCH Weight (g)',
[DIMENSION_TYPE_PROGRAM_INDICATOR]: 'Average weight (g)',
}

const PAGE_SIZE = 50

describe('Icon', () => {
beforeEach(() => {
goToStartPage()
changeVisType(visTypeDisplayNames[VIS_TYPE_SINGLE_VALUE])
})
it('no icon shows when option is disabled', () => {
// select a data item
openDimension(DIMENSION_ID_DATA)
expectDataDimensionModalToBeVisible()
expectSelectableDataItemsAmountToBeLeast(PAGE_SIZE)
inputSearchTerm(TEST_ITEMS[DIMENSION_TYPE_INDICATOR])
selectItemByDoubleClick(TEST_ITEMS[DIMENSION_TYPE_INDICATOR])
expectItemToBeSelected(TEST_ITEMS[DIMENSION_TYPE_INDICATOR])
clickDimensionModalUpdateButton()

// icon is hidden
expectVisualizationToBeVisible(VIS_TYPE_SINGLE_VALUE)
expectIconToBeHidden()
})
TEST_TYPES.forEach((type) => {
it(`icon shows when option is enabled for ${type}`, () => {
// enable the icon
clickMenuBarOptionsButton()
clickOptionsTab(OPTIONS_TAB_STYLE)
clickCheckbox('option-show-data-item-icon')
clickOptionsModalHideButton()

// find the data item
openDimension(DIMENSION_ID_DATA)
expectDataDimensionModalToBeVisible()
expectSelectableDataItemsAmountToBeLeast(PAGE_SIZE)
inputSearchTerm(TEST_ITEMS[type])

if (type === DIMENSION_TYPE_DATA_SET) {
switchDataTypeTo('Data sets')
switchSubGroupTo('Reporting rate')
} else if (type === DIMENSION_TYPE_EVENT_DATA_ITEM) {
switchDataTypeTo('Event data items')
switchGroupTo('Child Programme')
}

// select the data item
selectItemByDoubleClick(TEST_ITEMS[type])
expectItemToBeSelected(TEST_ITEMS[type])
clickDimensionModalUpdateButton()

// icon is shown
expectVisualizationToBeVisible(VIS_TYPE_SINGLE_VALUE)
expectIconToBeVisible()
})
})
it('icon gets correct color when a legend is in use', () => {
// enable the icon
clickMenuBarOptionsButton()
clickOptionsTab(OPTIONS_TAB_STYLE)
clickCheckbox('option-show-data-item-icon')

// enable the legend
clickOptionsTab(OPTIONS_TAB_LEGEND)
toggleLegend()
changeDisplayStrategyToFixed()
changeFixedLegendSet('E2E legend')
clickOptionsModalHideButton()

// select a period
openDimension(DIMENSION_ID_PERIOD)
unselectAllItemsByButton()
selectRelativePeriods(['This year'], 'Years')
clickDimensionModalHideButton()

// select a data item
openDimension(DIMENSION_ID_DATA)
expectDataDimensionModalToBeVisible()
expectSelectableDataItemsAmountToBeLeast(PAGE_SIZE)
inputSearchTerm(TEST_ITEMS[DIMENSION_TYPE_INDICATOR])
selectItemByDoubleClick(TEST_ITEMS[DIMENSION_TYPE_INDICATOR])
expectItemToBeSelected(TEST_ITEMS[DIMENSION_TYPE_INDICATOR])
clickDimensionModalUpdateButton()

// default text color is applied to icon
expectVisualizationToBeVisible(VIS_TYPE_SINGLE_VALUE)
expectIconToBeVisible()
expectSingleValueToHaveIconColor('#212934')

// switch to use a data item that will trigger the contrast color
openDimension(DIMENSION_ID_DATA)
expectDataDimensionModalToBeVisible()
unselectAllItemsByButton()
expectSelectableDataItemsAmountToBeLeast(PAGE_SIZE)
inputSearchTerm(TEST_ITEMS[DIMENSION_TYPE_DATA_ELEMENT])
selectItemByDoubleClick(TEST_ITEMS[DIMENSION_TYPE_DATA_ELEMENT])
expectItemToBeSelected(TEST_ITEMS[DIMENSION_TYPE_DATA_ELEMENT])
clickDimensionModalUpdateButton()

// contrast color is applied to icon
expectVisualizationToBeVisible(VIS_TYPE_SINGLE_VALUE)
expectIconToBeVisible()
expectSingleValueToHaveIconColor('#ffffff')

// switch to apply legend color to text
clickMenuBarOptionsButton()
clickOptionsTab(OPTIONS_TAB_LEGEND)
changeDisplayStyleToText()
clickOptionsModalUpdateButton()

// legend color is applied to icon
expectVisualizationToBeVisible(VIS_TYPE_SINGLE_VALUE)
expectIconToBeVisible()
expectSingleValueToHaveIconColor('#2166ac')
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"start-server-and-test": "^1.14.0"
},
"dependencies": {
"@dhis2/analytics": "^25.1.10",
"@dhis2/analytics": "^25.1.11",
"@dhis2/app-runtime": "^3.7.0",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/app-service-datastore": "^1.0.0-beta.3",
Expand Down
1 change: 1 addition & 0 deletions src/components/VisualizationOptions/Options/DataIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const DataIcon = () => (
option={{
name: 'icons',
}}
dataTest="option-show-data-item-icon"
/>
)

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2028,10 +2028,10 @@
classnames "^2.3.1"
prop-types "^15.7.2"

"@dhis2/analytics@^25.1.10":
version "25.1.10"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-25.1.10.tgz#b8bfb442335e6de2dbacfccadbeb907cc01173f4"
integrity sha512-5+jQIcLi0m9V27aIsxUMwf18Lpd3X8HyOxAnXYV5QMthbs2sodAQZNfM3TsPxPlcKCqNBLAIgyVrRm5RDn2zSw==
"@dhis2/analytics@^25.1.11":
version "25.1.11"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-25.1.11.tgz#04c1990798f1c33bebd16849dff4a81523d9e1ce"
integrity sha512-+aLYTbcVsxt5ZVLROJgvljFoLWK31jsS6xWzhwzWTQi+7WGVt5ONRUS45rZBYJas4FQj+SqPhCF6nXCssx7huA==
dependencies:
"@dhis2/d2-ui-rich-text" "^7.4.0"
"@dhis2/multi-calendar-dates" "1.0.0"
Expand Down

0 comments on commit b233883

Please sign in to comment.