Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions frontend/src/dmarc/__tests__/DmarcByDomainPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ const i18n = setupI18n({
matchMediaSize()

describe('<DmarcByDomainPage />', () => {
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 = [
{
Expand All @@ -38,7 +46,7 @@ describe('<DmarcByDomainPage />', () => {
variables: {
first: 10,
month: 'LAST30DAYS',
year: currentYear,
year: currentYear.toString(),
orderBy: {
field: 'TOTAL_MESSAGES',
direction: 'DESC',
Expand All @@ -54,7 +62,7 @@ describe('<DmarcByDomainPage />', () => {
variables: {
first: 10,
month: 'AUGUST',
year: '2021',
year: getDynamicYear(),
orderBy: {
field: 'TOTAL_MESSAGES',
direction: 'DESC',
Expand Down Expand Up @@ -181,7 +189,7 @@ describe('<DmarcByDomainPage />', () => {
name: /showing data for period:/i,
})

userEvent.selectOptions(periodSelector, `AUGUST, 2021`)
userEvent.selectOptions(periodSelector, `AUGUST, ${getDynamicYear()}`)

await findByText(/another.domain/)
})
Expand Down
48 changes: 32 additions & 16 deletions frontend/src/dmarc/__tests__/DmarcReportPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -79,7 +91,7 @@ describe('<DmarcReportPage />', () => {
variables: {
domain: 'test-domain',
month: 'LAST30DAYS',
year: '2021',
year: String(currentYear),
first: 50,
after: '',
},
Expand All @@ -92,7 +104,7 @@ describe('<DmarcReportPage />', () => {
variables: {
domain: 'test-domain',
month: 'AUGUST',
year: '2021',
year: getDynamicYear(),
first: 50,
after: '',
},
Expand All @@ -115,7 +127,7 @@ describe('<DmarcReportPage />', () => {
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/domains/test-domain/dmarc-report/LAST30DAYS/2021',
`/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`,
]}
initialIndex={0}
>
Expand Down Expand Up @@ -145,7 +157,7 @@ describe('<DmarcReportPage />', () => {
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/domains/test-domain/dmarc-report/LAST30DAYS/2021',
`/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`,
]}
initialIndex={0}
>
Expand Down Expand Up @@ -175,7 +187,7 @@ describe('<DmarcReportPage />', () => {
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/domains/test-domain/dmarc-report/LAST30DAYS/2021',
`/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`,
]}
initialIndex={0}
>
Expand Down Expand Up @@ -205,7 +217,7 @@ describe('<DmarcReportPage />', () => {
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/domains/test-domain/dmarc-report/LAST30DAYS/2021',
`/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`,
]}
initialIndex={0}
>
Expand All @@ -227,7 +239,9 @@ describe('<DmarcReportPage />', () => {
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(
Expand Down Expand Up @@ -258,19 +272,21 @@ describe('<DmarcReportPage />', () => {
})

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(
Expand Down Expand Up @@ -302,7 +318,7 @@ describe('<DmarcReportPage />', () => {
})

expect(history.location.pathname).toEqual(
'/domains/test-domain/dmarc-report/LAST30DAYS/2021',
`/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`,
)

// check current state of data
Expand Down Expand Up @@ -333,10 +349,10 @@ describe('<DmarcReportPage />', () => {
).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
Expand Down Expand Up @@ -390,7 +406,7 @@ describe('<DmarcReportPage />', () => {
variables: {
domain: 'test-domain',
month: 'LAST30DAYS',
year: '2021',
year: String(currentYear),
first: 50,
after: '',
},
Expand Down Expand Up @@ -420,7 +436,7 @@ describe('<DmarcReportPage />', () => {
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/domains/test-domain/dmarc-report/LAST30DAYS/2021',
`/domains/test-domain/dmarc-report/LAST30DAYS/${currentYear}`,
]}
initialIndex={0}
>
Expand Down