Skip to content

Commit

Permalink
Run prettier --write
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Aug 14, 2023
1 parent f9f4702 commit 9540bef
Show file tree
Hide file tree
Showing 49 changed files with 948 additions and 614 deletions.
6 changes: 1 addition & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ module.exports = {
parserOptions: {
ecmaVersion: 'latest'
},
plugins: [
'import',
'n',
'promise'
],
plugins: ['import', 'n', 'promise'],
rules: {
// Check import or require statements are A-Z ordered
'import/order': [
Expand Down
2 changes: 1 addition & 1 deletion __tests__/accessibility-audit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { AxePuppeteer } = require('@axe-core/puppeteer')

const { goTo } = require('../lib/puppeteer-helpers.js')

async function analyze (page, path) {
async function analyze(page, path) {
await goTo(page, path)

const axe = new AxePuppeteer(page)
Expand Down
7 changes: 4 additions & 3 deletions __tests__/back-to-top.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ describe('Back to top', () => {
let $backToTopLink
let pageHeight

async function setup (page) {
async function setup(page) {
$module = await page.$('[data-module="app-back-to-top"]')
$backToTopLink = await $module.$('a')

// Scrollable height of body
pageHeight = await page.$eval('body', ($element) => $element.scrollHeight) ?? 0
pageHeight =
(await page.$eval('body', ($element) => $element.scrollHeight)) ?? 0
}

function scrollTo (page, scrollY) {
function scrollTo(page, scrollY) {
return page.evaluate((y) => window.scroll(0, y), scrollY)
}

Expand Down
55 changes: 41 additions & 14 deletions __tests__/component-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ describe('Component page', () => {
it('should contain a "Nunjucks" tab heading', async () => {
await goTo(page, '/components/back-link/')

const nunjucksTabHeadings = await page.evaluate(() => Array.from(document.querySelectorAll('.js-tabs__item a'))
.filter(element => element.textContent === 'Nunjucks')
const nunjucksTabHeadings = await page.evaluate(() =>
Array.from(document.querySelectorAll('.js-tabs__item a')).filter(
(element) => element.textContent === 'Nunjucks'
)
)

expect(nunjucksTabHeadings[0]).toBeTruthy()
Expand All @@ -15,18 +17,26 @@ describe('Component page', () => {
await goTo(page, '/components/back-link/')

// Get "aria-controls" attributes from "Nunjucks" tab headings
const nunjucksTabHeadingControls = await page.evaluateHandle(() => Array.from(document.querySelectorAll('.js-tabs__item a'))
.filter(element => element.textContent === 'Nunjucks')
.map(element => element.getAttribute('aria-controls'))
const nunjucksTabHeadingControls = await page.evaluateHandle(() =>
Array.from(document.querySelectorAll('.js-tabs__item a'))
.filter((element) => element.textContent === 'Nunjucks')
.map((element) => element.getAttribute('aria-controls'))
)

const tabContentIds = await nunjucksTabHeadingControls.jsonValue() // Returns Puppeteer JSONHandle

const id = tabContentIds[0]

// Get summary text of details element in "Nunjucks" tab
const nunjucksTabHeadings = await page.evaluate(id => Array.from(document.getElementById(id).querySelectorAll('.govuk-details__summary-text'))
.map(element => element.textContent.trim()), id)
const nunjucksTabHeadings = await page.evaluate(
(id) =>
Array.from(
document
.getElementById(id)
.querySelectorAll('.govuk-details__summary-text')
).map((element) => element.textContent.trim()),
id
)

expect(nunjucksTabHeadings).toContain('Nunjucks macro options')
})
Expand All @@ -35,18 +45,32 @@ describe('Component page', () => {
await goTo(page, '/components/back-link/')

// Get "aria-controls" attributes from "Nunjucks" tab headings
const nunjucksTabHeadingControls = await page.evaluateHandle(() => Array.from(document.querySelectorAll('.js-tabs__item a'))
.filter(element => element.textContent === 'Nunjucks')
.map(element => element.getAttribute('aria-controls')))
const nunjucksTabHeadingControls = await page.evaluateHandle(() =>
Array.from(document.querySelectorAll('.js-tabs__item a'))
.filter((element) => element.textContent === 'Nunjucks')
.map((element) => element.getAttribute('aria-controls'))
)

const tabContentIds = await nunjucksTabHeadingControls.jsonValue() // Returns Puppeteer JSONHandle
const id = tabContentIds[0]

// Get table headings of table inside details element in "Nunjucks" tab
const nunjucksTableHeadings = await page.evaluate(id => Array.from(document.getElementById(id).querySelector('.govuk-details__text .govuk-table .govuk-table__head').querySelectorAll('.govuk-table__header'))
.map(element => element.textContent.trim()), id)
const nunjucksTableHeadings = await page.evaluate(
(id) =>
Array.from(
document
.getElementById(id)
.querySelector(
'.govuk-details__text .govuk-table .govuk-table__head'
)
.querySelectorAll('.govuk-table__header')
).map((element) => element.textContent.trim()),
id
)

expect(nunjucksTableHeadings.sort()).toEqual(['Name', 'Type', 'Description'].sort())
expect(nunjucksTableHeadings.sort()).toEqual(
['Name', 'Type', 'Description'].sort()
)
})

it('macro options should be opened and in view when linked to', async () => {
Expand All @@ -61,7 +85,10 @@ describe('Component page', () => {
})

it('macro options subtable should be opened and in view when linked to', async () => {
await goTo(page, '/components/text-input/#options-text-input-example--label')
await goTo(
page,
'/components/text-input/#options-text-input-example--label'
)

// Check if example's macro options details element is open
await page.waitForSelector('#options-text-input-example-details[open=open]')
Expand Down
26 changes: 19 additions & 7 deletions __tests__/cookie-banner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Cookie banner', () => {
url: `http://localhost:${ports.preview}`
}

async function setup (page) {
async function setup(page) {
$module = await page.$('[data-module="govuk-cookie-banner"]')
$message = await $module.$('.js-cookie-banner-message')

Expand All @@ -27,8 +27,12 @@ describe('Cookie banner', () => {
$buttonReject = await $module.$('.js-cookie-banner-reject')

// Accept or reject confirmation messages
$confirmationAccept = await $module.$('.js-cookie-banner-confirmation-accept')
$confirmationReject = await $module.$('.js-cookie-banner-confirmation-reject')
$confirmationAccept = await $module.$(
'.js-cookie-banner-confirmation-accept'
)
$confirmationReject = await $module.$(
'.js-cookie-banner-confirmation-reject'
)
}

beforeEach(async () => {
Expand Down Expand Up @@ -117,7 +121,9 @@ describe('Cookie banner', () => {

it('moves user focus to the confirmation message', async () => {
await $buttonAccept.click()
await expect(getAttribute($confirmationAccept, 'tabindex')).resolves.toEqual('-1')
await expect(
getAttribute($confirmationAccept, 'tabindex')
).resolves.toEqual('-1')
})
})

Expand Down Expand Up @@ -148,13 +154,17 @@ describe('Cookie banner', () => {

it('moves user focus to the confirmation message', async () => {
await $buttonReject.click()
await expect(getAttribute($confirmationReject, 'tabindex')).resolves.toEqual('-1')
await expect(
getAttribute($confirmationReject, 'tabindex')
).resolves.toEqual('-1')
})
})

describe('hide button', () => {
it('hides the accept confirmation message', async () => {
const $buttonAcceptHide = await $module.$('.js-cookie-banner-hide--accept')
const $buttonAcceptHide = await $module.$(
'.js-cookie-banner-hide--accept'
)

// Accept cookies
await $buttonAccept.click()
Expand All @@ -172,7 +182,9 @@ describe('Cookie banner', () => {
})

it('hides the reject confirmation message', async () => {
const $buttonRejectHide = await $module.$('.js-cookie-banner-hide--reject')
const $buttonRejectHide = await $module.$(
'.js-cookie-banner-hide--reject'
)

// Reject cookies
await $buttonReject.click()
Expand Down
Loading

0 comments on commit 9540bef

Please sign in to comment.