-
Notifications
You must be signed in to change notification settings - Fork 227
/
tabs.test.js
106 lines (85 loc) · 4.38 KB
/
tabs.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const { setupPage } = require('../lib/jest-utilities.js')
const configPaths = require('../lib/paths.js')
const PORT = configPaths.testPort
let page
const baseUrl = 'http://localhost:' + PORT
beforeAll(async () => {
page = await setupPage()
})
afterAll(async () => {
await page.close()
})
describe('Component page', () => {
describe('when JavaScript is unavailable or fails', () => {
it('falls back to making the containers visible', async () => {
await page.setJavaScriptEnabled(false)
await page.goto(baseUrl + '/components/back-link/', { waitUntil: 'load' })
const isContainerVisible = await page.waitForSelector('.js-tabs__container', { visible: true, timeout: 1000 })
expect(isContainerVisible).toBeTruthy()
})
})
describe('when JavaScript is available', () => {
describe('when tab item is pressed', () => {
it('should indicate the open state of the tab', async () => {
await page.setJavaScriptEnabled(true)
await page.goto(baseUrl + '/components/back-link/', { waitUntil: 'load' })
await page.click('.js-tabs__item a')
const toggleButtonIsOpen = await page.evaluate(() => document.body.querySelector('.app-tabs__item').classList.contains('app-tabs__item--current'))
expect(toggleButtonIsOpen).toBeTruthy()
})
it('should indicate the selected state of the tab using aria-expanded', async () => {
await page.goto(baseUrl + '/components/back-link/', { waitUntil: 'load' })
await page.click('.js-tabs__item a')
const toggleButtonAriaExpanded = await page.evaluate(() => document.body.querySelector('.js-tabs__item a').getAttribute('aria-expanded'))
expect(toggleButtonAriaExpanded).toBe('true')
})
})
describe('when the tab closed and clicked twice', () => {
it('should indicate the closed state of the tab', async () => {
await page.setJavaScriptEnabled(true)
await page.goto(baseUrl + '/components/back-link/', { waitUntil: 'load' })
await page.click('.js-tabs__item a')
await page.click('.js-tabs__item a')
const toggleButtonIsOpen = await page.evaluate(() => document.body.querySelector('.app-tabs__item').classList.contains('app-tabs__item--current'))
expect(toggleButtonIsOpen).toBeFalsy()
})
it('should indicate the closed state by setting aria-expanded attribute to false', async () => {
await page.goto(baseUrl + '/components/back-link/', { waitUntil: 'load' })
await page.click('.js-tabs__item a')
await page.click('.js-tabs__item a')
const toggleButtonAriaExpanded = await page.evaluate(() => document.body.querySelector('.js-tabs__item a').getAttribute('aria-expanded'))
expect(toggleButtonAriaExpanded).toBe('false')
})
})
})
})
describe('Patterns page', () => {
describe('when JavaScript is available', () => {
describe('when "hideTab" parameter is set to true', () => {
it('the tab list is not rendered', async () => {
await page.goto(baseUrl + '/patterns/question-pages/', { waitUntil: 'load' })
const expandedTabContentWithNoTab = await page.evaluate(() => document.body.querySelector('#section-headings-question-pages-example-open .app-tabs'))
expect(expandedTabContentWithNoTab).toBeNull()
})
it('close button is not shown on the code block', async () => {
await page.goto(baseUrl + '/patterns/question-pages/', { waitUntil: 'load' })
const expandedTabContentWithNoTabCloseButton = await page.evaluate(() => document.body.querySelector('.js-tabs__container--no-tabs .js-tabs__close'))
expect(expandedTabContentWithNoTabCloseButton).toBeNull()
})
})
})
})
describe('Styles -> Images page', () => {
describe('when both nunjucks and html parameters are set to "false"', () => {
it('the tab list items are not rendered', async () => {
await page.goto(baseUrl + '/styles/images/', { waitUntil: 'load' })
const tabListItems = await page.evaluate(() => document.body.querySelector('#example-default .app-tabs'))
expect(tabListItems).toBeFalsy()
})
it('the tab heading items are not rendered', async () => {
await page.goto(baseUrl + '/styles/images/', { waitUntil: 'load' })
const tabHeadingItems = await page.evaluate(() => document.body.querySelector('#example-default .app-tabs__heading'))
expect(tabHeadingItems).toBeFalsy()
})
})
})