-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test autofocusing behaviour of notification banner
Test if the element has the correct tabindex and can be focused. Test that element is not focused if it has the data-disable-auto-focus attribute or it doesn’t have role=alert.
- Loading branch information
1 parent
5cf522d
commit d9cc60a
Showing
4 changed files
with
90 additions
and
140 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/govuk/components/notification-banner/notification-banner.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-env jest */ | ||
|
||
const configPaths = require('../../../../config/paths.json') | ||
const PORT = configPaths.ports.test | ||
|
||
const baseUrl = 'http://localhost:' + PORT | ||
|
||
describe('/components/notification-banner/with-type-as-success', () => { | ||
it('has the correct tabindex to be focused with JavaScript', async () => { | ||
await page.goto(baseUrl + '/components/notification-banner/with-type-as-success/preview', { waitUntil: 'load' }) | ||
|
||
const tabindex = await page.$eval('.govuk-notification-banner', el => el.getAttribute('tabindex')) | ||
|
||
expect(tabindex).toEqual('-1') | ||
}) | ||
|
||
it('is automatically focused when the page loads', async () => { | ||
await page.goto(baseUrl + '/components/notification-banner/with-type-as-success/preview', { waitUntil: 'load' }) | ||
|
||
const activeElement = await page.evaluate(() => document.activeElement.dataset.module) | ||
|
||
expect(activeElement).toBe('govuk-notification-banner') | ||
}) | ||
}) | ||
|
||
describe('components/notification-banner/auto-focus-disabled,-with-type-as-success/', () => { | ||
describe('when auto-focus is disabled', () => { | ||
it('does not have a tabindex attribute', async () => { | ||
await page.goto(`${baseUrl}/components/notification-banner/auto-focus-disabled,-with-type-as-success/preview`, { waitUntil: 'load' }) | ||
|
||
const tabindex = await page.$eval('.govuk-notification-banner', el => el.getAttribute('tabindex')) | ||
|
||
expect(tabindex).toBeFalsy() | ||
}) | ||
|
||
it('does not focus the notification banner', async () => { | ||
await page.goto(`${baseUrl}/components/notification-banner/auto-focus-disabled,-with-type-as-success/preview`, { waitUntil: 'load' }) | ||
|
||
const activeElement = await page.evaluate(() => document.activeElement.dataset.module) | ||
|
||
expect(activeElement).not.toBe('govuk-notification-banner') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('components/notification-banner/role=alert-overridden-to-role=region,-with-type-as-success', () => { | ||
describe('when role is not alert', () => { | ||
it('does not have a tabindex attribute', async () => { | ||
await page.goto(`${baseUrl}/components/notification-banner/role=alert-overridden-to-role=region,-with-type-as-success/preview`, { waitUntil: 'load' }) | ||
|
||
const tabindex = await page.$eval('.govuk-notification-banner', el => el.getAttribute('tabindex')) | ||
|
||
expect(tabindex).toBeFalsy() | ||
}) | ||
|
||
it('does not focus the notification banner', async () => { | ||
await page.goto(`${baseUrl}/components/notification-banner/role=alert-overridden-to-role=region,-with-type-as-success/preview`, { waitUntil: 'load' }) | ||
|
||
const activeElement = await page.evaluate(() => document.activeElement.dataset.module) | ||
|
||
expect(activeElement).not.toBe('govuk-notification-banner') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters