Skip to content

Commit 394bb70

Browse files
committed
Add tests for when viewport is resized
In anticipation of testing the presence of `aria-hidden`
1 parent b5db129 commit 394bb70

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

packages/govuk-frontend/src/govuk/components/service-navigation/service-navigation.puppeteer.test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,79 @@ describe('/components/service-navigation', () => {
240240
expect(toggleExpandedAttribute).toBe('false')
241241
})
242242
})
243+
244+
describe('on wide viewports', () => {
245+
beforeAll(async () => {
246+
// First let's reset the viewport to a desktop one
247+
await page.setViewport({
248+
width: 1280,
249+
height: 720
250+
})
251+
})
252+
253+
afterAll(async () => {
254+
// After tests have run reset teh viewport to a phone
255+
await page.emulate(iPhone)
256+
})
257+
258+
describe('on page load', () => {
259+
beforeAll(async () => {
260+
await render(page, 'service-navigation', examples.default)
261+
})
262+
263+
it('shows the navigation', async () => {
264+
const navigationHiddenAttribute = await page.$eval(
265+
navigationSelector,
266+
(el) => el.hasAttribute('hidden')
267+
)
268+
269+
expect(navigationHiddenAttribute).toBeFalsy()
270+
})
271+
272+
it('keeps the toggle button hidden', async () => {
273+
const buttonHiddenAttribute = await page.$eval(
274+
toggleButtonSelector,
275+
(el) => el.hasAttribute('hidden')
276+
)
277+
278+
expect(buttonHiddenAttribute).toBeTruthy()
279+
})
280+
})
281+
282+
describe('when page is resized to a narrow viewport', () => {
283+
beforeAll(async () => {
284+
await render(page, 'service-navigation', examples.default)
285+
286+
// Once the page is loaded resize the viewport to a narrow one
287+
// Only set the width and height to avoid the page getting wiped
288+
await page.setViewport({
289+
width: iPhone.viewport.width,
290+
height: iPhone.viewport.height
291+
})
292+
293+
// Wait that the page got updated after the resize,
294+
// as sometimes the tests run too early
295+
await page.waitForSelector(`${navigationSelector}[hidden]`)
296+
})
297+
298+
it('hides the navigation', async () => {
299+
const navigationHiddenAttribute = await page.$eval(
300+
`${navigationSelector}`,
301+
(el) => el.hasAttribute('hidden')
302+
)
303+
304+
expect(navigationHiddenAttribute).toBeTruthy()
305+
})
306+
307+
it('reveals the toggle button', async () => {
308+
const buttonHiddenAttribute = await page.$eval(
309+
toggleButtonSelector,
310+
(el) => el.hasAttribute('hidden')
311+
)
312+
313+
expect(buttonHiddenAttribute).toBeFalsy()
314+
})
315+
})
316+
})
243317
})
244318
})

0 commit comments

Comments
 (0)