diff --git a/frontend/src/dmarc/__tests__/DmarcByDomainPage.test.js b/frontend/src/dmarc/__tests__/DmarcByDomainPage.test.js index 7946839d82..9567138b74 100644 --- a/frontend/src/dmarc/__tests__/DmarcByDomainPage.test.js +++ b/frontend/src/dmarc/__tests__/DmarcByDomainPage.test.js @@ -29,7 +29,15 @@ const i18n = setupI18n({ matchMediaSize() describe('', () => { - const currentYear = new Date().getFullYear().toString() + const currentYear = new Date().getFullYear() + const getDynamicYear = () => { + const currentMonth = new Date().getMonth() + if (currentMonth >= 8) { + return String(currentYear) + } else { + return String(currentYear - 1) + } + } const mocks = [ { @@ -38,7 +46,7 @@ describe('', () => { variables: { first: 10, month: 'LAST30DAYS', - year: currentYear, + year: currentYear.toString(), orderBy: { field: 'TOTAL_MESSAGES', direction: 'DESC', @@ -54,7 +62,7 @@ describe('', () => { variables: { first: 10, month: 'AUGUST', - year: '2021', + year: getDynamicYear(), orderBy: { field: 'TOTAL_MESSAGES', direction: 'DESC', @@ -181,7 +189,7 @@ describe('', () => { name: /showing data for period:/i, }) - userEvent.selectOptions(periodSelector, `AUGUST, 2021`) + userEvent.selectOptions(periodSelector, `AUGUST, ${getDynamicYear()}`) await findByText(/another.domain/) }) diff --git a/frontend/src/dmarc/__tests__/DmarcReportPage.test.js b/frontend/src/dmarc/__tests__/DmarcReportPage.test.js index 9d351b067f..30248cfc19 100644 --- a/frontend/src/dmarc/__tests__/DmarcReportPage.test.js +++ b/frontend/src/dmarc/__tests__/DmarcReportPage.test.js @@ -43,6 +43,18 @@ class ResizeObserver { window.ResizeObserver = ResizeObserver // ** +const d = new Date() +const currentYear = d.getFullYear() +// dynamic year value, changes in September +const getDynamicYear = () => { + const currentMonth = d.getMonth() + if (currentMonth >= 8) { + return String(currentYear) + } else { + return String(currentYear - 1) + } +} + const i18n = setupI18n({ locale: 'en', messages: { @@ -79,7 +91,7 @@ describe('', () => { variables: { domain: 'test-domain', month: 'LAST30DAYS', - year: '2021', + year: String(currentYear), first: 50, after: '', }, @@ -92,7 +104,7 @@ describe('', () => { variables: { domain: 'test-domain', month: 'AUGUST', - year: '2021', + year: getDynamicYear(), first: 50, after: '', }, @@ -115,7 +127,7 @@ describe('', () => { @@ -145,7 +157,7 @@ describe('', () => { @@ -175,7 +187,7 @@ describe('', () => { @@ -205,7 +217,7 @@ describe('', () => { @@ -227,7 +239,9 @@ describe('', () => { describe('changes period tables', () => { it('the url changes', async () => { const history = createMemoryHistory({ - initialEntries: ['/domains/test-domain/dmarc-report/LAST30DAYS/2021'], + initialEntries: [ + `/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`, + ], initialIndex: 0, }) const { getByRole, findByRole } = render( @@ -258,19 +272,21 @@ describe('', () => { }) expect(history.location.pathname).toEqual( - '/domains/test-domain/dmarc-report/LAST30DAYS/2021', + `/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`, ) - userEvent.selectOptions(periodSelector, 'AUGUST, 2021') + userEvent.selectOptions(periodSelector, `AUGUST, ${getDynamicYear()}`) expect(history.location.pathname).toEqual( - '/domains/test-domain/dmarc-report/AUGUST/2021', + `/domains/test-domain/dmarc-report/AUGUST/${getDynamicYear()}`, ) }) it('the data changes', async () => { const history = createMemoryHistory({ - initialEntries: ['/domains/test-domain/dmarc-report/LAST30DAYS/2021'], + initialEntries: [ + `/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`, + ], initialIndex: 0, }) const { getByRole, findByRole, queryByText } = render( @@ -302,7 +318,7 @@ describe('', () => { }) expect(history.location.pathname).toEqual( - '/domains/test-domain/dmarc-report/LAST30DAYS/2021', + `/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`, ) // check current state of data @@ -333,10 +349,10 @@ describe('', () => { ).not.toBeInTheDocument() // change date - userEvent.selectOptions(periodSelector, 'AUGUST, 2021') + userEvent.selectOptions(periodSelector, `AUGUST, ${getDynamicYear()}`) expect(history.location.pathname).toEqual( - '/domains/test-domain/dmarc-report/AUGUST/2021', + `/domains/test-domain/dmarc-report/AUGUST/${getDynamicYear()}`, ) // page is loaded @@ -390,7 +406,7 @@ describe('', () => { variables: { domain: 'test-domain', month: 'LAST30DAYS', - year: '2021', + year: String(currentYear), first: 50, after: '', }, @@ -420,7 +436,7 @@ describe('', () => {