-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Accordion-test.avt.e2e.js
147 lines (131 loc) · 4.08 KB
/
Accordion-test.avt.e2e.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
import { expect, test } from '@playwright/test';
import { visitStory } from '../../test-utils/storybook';
test.describe('@avt Accordion', () => {
test('@avt-default-state', async ({ page }) => {
await visitStory(page, {
component: 'Accordion',
id: 'components-accordion--default',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('Accordion @avt-default-state');
});
test('@avt-advanced-states skeleton', async ({ page }) => {
await visitStory(page, {
component: 'Accordion',
id: 'components-accordion--skeleton',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations(
'Accordion @avt-advanced-states skeleton'
);
});
test('@avt-advanced-states with layer', async ({ page }) => {
await visitStory(page, {
component: 'Accordion',
id: 'components-accordion--with-layer',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations(
'Accordion @avt-advanced-states with layer'
);
});
test('@avt-keyboard-nav', async ({ page }) => {
await visitStory(page, {
component: 'Accordion',
id: 'components-accordion--default',
globals: {
theme: 'white',
},
});
const accordion_btn1 = page.getByRole('button', {
name: 'Section 1 title',
});
const accordion_btn2 = page.getByRole('button', {
name: 'Section 2 title',
});
await expect(accordion_btn1).toBeVisible();
await page.keyboard.press('Tab');
// Check the focus on Accordion 1
await expect(accordion_btn1).toBeFocused();
await page.keyboard.press('Enter');
// Open the Accordion 1
await expect(accordion_btn1).toHaveAttribute('aria-expanded', 'true');
await page.keyboard.press('Enter');
await expect(accordion_btn1).toHaveAttribute('aria-expanded', 'false');
await page.keyboard.press('Tab');
// Check the focus and open state on Accordion 2
await expect(accordion_btn2).toBeFocused();
await page.keyboard.press('Space');
await expect(accordion_btn2).toHaveAttribute('aria-expanded', 'true');
await page.keyboard.press('Escape');
await expect(accordion_btn2).toHaveAttribute('aria-expanded', 'false');
});
test('@avt-advanced-states mouse click', async ({ page }) => {
await visitStory(page, {
component: 'Accordion',
id: 'components-accordion--default',
globals: {
theme: 'white',
},
});
const accordion_btn1 = page.getByRole('button', {
name: 'Section 1 title',
});
await accordion_btn1.click();
await expect(accordion_btn1).toHaveAttribute('aria-expanded', 'true');
// Checking for ACViolation
await expect(page).toHaveNoACViolations(
'Accordion @avt-advanced-states mouse click'
);
await accordion_btn1.click();
await expect(accordion_btn1).toHaveAttribute('aria-expanded', 'false');
});
test('@avt-advanced-states mouse hover', async ({ page }) => {
await visitStory(page, {
component: 'Accordion',
id: 'components-accordion--default',
globals: {
theme: 'white',
},
});
const accordion_btn1 = page.getByRole('button', {
name: 'Section 1 title',
});
await accordion_btn1.hover();
await expect(page).toHaveNoACViolations(
'Accordion @avt-advanced-states mouse hover'
);
});
test('@avt-advanced-states disabled', async ({ page }) => {
await visitStory(page, {
component: 'Accordion',
id: 'components-accordion--playground',
globals: {
theme: 'white',
},
args: {
disabled: true,
},
});
const accordion_btn1 = page.getByRole('button', {
name: 'Section 1 title',
});
await expect(accordion_btn1).toBeDisabled();
await expect(page).toHaveNoACViolations(
'Accordion @avt-advanced-states disabled'
);
});
});