Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Fix focus #1325

Merged
merged 5 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
29 changes: 15 additions & 14 deletions f2/src/__tests__/BusinessPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<BusinessPage />', () => {
afterEach(cleanup)
beforeEach(() => (global.scrollTo = jest.fn()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The window object that the app uses only exists when running in a browser, not when running in jest. So for the tests to use window.scrollTo(), we make the function manually by setting it to a fake jest function. And for some reason we set global.scrollTo rather than window.scrollTo 🤷‍♂

afterEach(cleanup)

it('renders', () => {
render(
<MemoryRouter initialEntries={['/']}>
<ThemeProvider theme={canada}>
<StateProvider initialState={initialState} reducer={reducer}>
<I18nProvider i18n={i18n}>
<BusinessPage />
</I18nProvider>
</StateProvider>
</ThemeProvider>
</MemoryRouter>,
)
})
it('renders', () => {
render(
<MemoryRouter initialEntries={['/']}>
<ThemeProvider theme={canada}>
<StateProvider initialState={initialState} reducer={reducer}>
<I18nProvider i18n={i18n}>
<BusinessPage />
</I18nProvider>
</StateProvider>
</ThemeProvider>
</MemoryRouter>,
)
})
})
1 change: 1 addition & 0 deletions f2/src/__tests__/CancelPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<CancelPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
1 change: 1 addition & 0 deletions f2/src/__tests__/ConfirmCancelPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<ConfirmCancelPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
1 change: 1 addition & 0 deletions f2/src/__tests__/ConfirmationSummary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<ConfirmationSummary />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
1 change: 1 addition & 0 deletions f2/src/__tests__/ContactInfoPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<ContactInfoPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
3 changes: 2 additions & 1 deletion f2/src/__tests__/DevicesPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<DevicesPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand All @@ -28,4 +29,4 @@ describe('<DevicesPage />', () => {
</MemoryRouter>,
)
})
})
})
1 change: 1 addition & 0 deletions f2/src/__tests__/FeedbackPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<FeedbackPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
29 changes: 15 additions & 14 deletions f2/src/__tests__/InformationPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<InformationPage />', () => {
afterEach(cleanup)
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
render(
<MemoryRouter initialEntries={['/']}>
<ThemeProvider theme={canada}>
<StateProvider initialState={initialState} reducer={reducer}>
<I18nProvider i18n={i18n}>
<InformationPage />
</I18nProvider>
</StateProvider>
</ThemeProvider>
</MemoryRouter>,
)
})
it('renders', () => {
render(
<MemoryRouter initialEntries={['/']}>
<ThemeProvider theme={canada}>
<StateProvider initialState={initialState} reducer={reducer}>
<I18nProvider i18n={i18n}>
<InformationPage />
</I18nProvider>
</StateProvider>
</ThemeProvider>
</MemoryRouter>,
)
})
})
1 change: 1 addition & 0 deletions f2/src/__tests__/LandingPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<LandingPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
1 change: 1 addition & 0 deletions f2/src/__tests__/LocationPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<LocationPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
3 changes: 2 additions & 1 deletion f2/src/__tests__/PrivacyConsentPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<PrivacyConsentPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand All @@ -28,4 +29,4 @@ describe('<PrivacyConsentPage />', () => {
</MemoryRouter>,
)
})
})
})
1 change: 1 addition & 0 deletions f2/src/__tests__/WhatHappenedPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<WhatHappenedPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
1 change: 1 addition & 0 deletions f2/src/__tests__/WhatWasAffectedPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<ImpactStatementPage />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
1 change: 1 addition & 0 deletions f2/src/components/footer/__tests__/Footer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<Footer />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders children correctly', () => {
Expand Down
1 change: 1 addition & 0 deletions f2/src/components/layout/__tests__/Layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, cleanup } from '@testing-library/react'
import { Layout } from '..'

describe('<Layout />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders', () => {
Expand Down
7 changes: 6 additions & 1 deletion f2/src/components/layout/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import { Container } from '../container'

Expand All @@ -10,6 +10,11 @@ export const Layout = ({ fluid, columns, ...props }) => {
xl: columns.xl * 100 + '%',
}

// scroll to the top of the page when this Layout renders
useEffect(() => {
window.scrollTo(0, 0)
})

return (
<Container
{...(fluid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<PhaseBanner />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('properly renders alpha banner', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ i18n.load('en', { en })
i18n.activate('en')

describe('<WarningBanner />', () => {
beforeEach(() => (global.scrollTo = jest.fn()))
afterEach(cleanup)

it('renders correctly', () => {
Expand Down