Skip to content

Commit

Permalink
refactor: use helper function for current/previous year
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Jan 8, 2025
1 parent 546b487 commit e7a6d78
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cypress/helpers/period.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const getPreviousYearStr = () => (new Date().getFullYear() - 1).toString()

const getCurrentYearStr = () => new Date().getFullYear().toString()

export { getPreviousYearStr, getCurrentYearStr }
5 changes: 3 additions & 2 deletions cypress/integration/options/cumulativeValues.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cypress/integration/options/limitValues.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 4 additions & 3 deletions cypress/integration/options/totals.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e7a6d78

Please sign in to comment.