-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add Cypress tests for SV icon (DHIS2-10496) (#2372)
- Loading branch information
1 parent
eee29fb
commit b233883
Showing
6 changed files
with
202 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ const DataIcon = () => ( | |
option={{ | ||
name: 'icons', | ||
}} | ||
dataTest="option-show-data-item-icon" | ||
/> | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters