From e7a6d78b76eba9ac7184f50dd61932e5b4dfd5f1 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Wed, 8 Jan 2025 10:51:30 +0100 Subject: [PATCH] refactor: use helper function for current/previous year --- cypress/helpers/period.js | 5 +++++ cypress/integration/options/cumulativeValues.cy.js | 5 +++-- cypress/integration/options/limitValues.cy.js | 3 ++- cypress/integration/options/totals.cy.js | 7 ++++--- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 cypress/helpers/period.js diff --git a/cypress/helpers/period.js b/cypress/helpers/period.js new file mode 100644 index 000000000..2af779fcf --- /dev/null +++ b/cypress/helpers/period.js @@ -0,0 +1,5 @@ +const getPreviousYearStr = () => (new Date().getFullYear() - 1).toString() + +const getCurrentYearStr = () => new Date().getFullYear().toString() + +export { getPreviousYearStr, getCurrentYearStr } diff --git a/cypress/integration/options/cumulativeValues.cy.js b/cypress/integration/options/cumulativeValues.cy.js index 23ec403c1..2758ae8b8 100644 --- a/cypress/integration/options/cumulativeValues.cy.js +++ b/cypress/integration/options/cumulativeValues.cy.js @@ -54,6 +54,7 @@ import { } from '../../elements/pivotTable.js' import { goToStartPage } from '../../elements/startScreen.js' import { changeVisType } from '../../elements/visualizationTypeSelector.js' +import { getPreviousYearStr } from '../../helpers/period.js' import { TEST_DATA_ELEMENTS } from '../../utils/data.js' const cumulativeValuesOptionEl = 'option-cumulative-values' @@ -176,7 +177,7 @@ describe('Options - Cumulative values', () => { openContextMenu(DIMENSION_ID_PERIOD) clickContextMenuMove(DIMENSION_ID_PERIOD, AXIS_ID_COLUMNS) - const year = (new Date().getFullYear() - 1).toString() + const year = getPreviousYearStr() openDimension(DIMENSION_ID_PERIOD) unselectAllItemsByButton() @@ -253,7 +254,7 @@ describe('Options - Cumulative values', () => { selectDataItems(['BCG doses']) clickDimensionModalHideButton() - const year = (new Date().getFullYear() - 1).toString() + const year = getPreviousYearStr() openDimension(DIMENSION_ID_PERIOD) unselectAllItemsByButton() selectFixedPeriodYear(year) diff --git a/cypress/integration/options/limitValues.cy.js b/cypress/integration/options/limitValues.cy.js index 54db5bb2a..3f05d3c76 100644 --- a/cypress/integration/options/limitValues.cy.js +++ b/cypress/integration/options/limitValues.cy.js @@ -38,9 +38,10 @@ import { goToStartPage, } from '../../elements/startScreen.js' import { changeVisType } from '../../elements/visualizationTypeSelector.js' +import { getPreviousYearStr } from '../../helpers/period.js' const TEST_INDICATOR = 'ANC visits total' -const year = (new Date().getFullYear() - 1).toString() +const year = getPreviousYearStr() const expectTableValueToBe = (value, position) => cy .getBySel('visualization-container') diff --git a/cypress/integration/options/totals.cy.js b/cypress/integration/options/totals.cy.js index 8649dcd29..2f8acdea1 100644 --- a/cypress/integration/options/totals.cy.js +++ b/cypress/integration/options/totals.cy.js @@ -43,6 +43,7 @@ import { } from '../../elements/pivotTable.js' import { goToStartPage } from '../../elements/startScreen.js' import { changeVisType } from '../../elements/visualizationTypeSelector.js' +import { getPreviousYearStr } from '../../helpers/period.js' import { TEST_CUSTOM_DIMENSIONS } from '../../utils/data.js' const AREA_DIMENSION = TEST_CUSTOM_DIMENSIONS.find((dim) => dim.name === 'Area') @@ -69,7 +70,7 @@ describe('Options - Column totals', () => { selectDataElements(['ART enrollment stage 1']) clickDimensionModalHideButton() - const year = (new Date().getFullYear() - 1).toString() + const year = getPreviousYearStr() openDimension(DIMENSION_ID_PERIOD) unselectAllItemsByButton() selectFixedPeriodYear(year) @@ -97,7 +98,7 @@ describe('Options - Column totals', () => { ]) clickDimensionModalHideButton() - const year = (new Date().getFullYear() - 1).toString() + const year = getPreviousYearStr() openDimension(DIMENSION_ID_PERIOD) unselectAllItemsByButton() selectFixedPeriodYear(year) @@ -161,7 +162,7 @@ describe('Options - Row totals', () => { selectDataItems(['BCG doses']) clickDimensionModalHideButton() - const year = (new Date().getFullYear() - 1).toString() + const year = getPreviousYearStr() openDimension(DIMENSION_ID_PERIOD) unselectAllItemsByButton() selectFixedPeriodYear(year)