-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathcarousel.browser-test.tsx
More file actions
580 lines (452 loc) · 24.9 KB
/
carousel.browser-test.tsx
File metadata and controls
580 lines (452 loc) · 24.9 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
import { expect, test } from '@semcore/testing-utils/playwright';
import type { Page } from '@semcore/testing-utils/playwright';
import { loadPage } from '@semcore/testing-utils/shared/helpers';
import { TAG } from '@semcore/testing-utils/shared/tags';
export const locators = {
button: (page: Page, name?: string, index?: number) => {
const base = page.getByRole('button', { name });
return typeof index === 'number' ? base.nth(index) : base;
},
modal: (page: Page, index?: number) => {
const base = page.getByRole('dialog');
return typeof index === 'number' ? base.nth(index) : base;
},
tabpanel: (page: Page, index?: number) => {
const base = page.getByRole('tabpanel');
return typeof index === 'number' ? base.nth(index) : base;
},
tab: (page: Page, index?: number) => {
const base = page.getByRole('tab');
return typeof index === 'number' ? base.nth(index) : base;
}, region: (page: Page, index?: number) => {
const base = page.getByRole('region');
return typeof index === 'number' ? base.nth(index) : base;
},
tablist: (page: Page, index?: number) => {
const base = page.getByRole('tablist');
return typeof index === 'number' ? base.nth(index) : base;
},
img: (page: Page, index?: number) =>
page.locator('div[role="tabpanel"] img[role="button"]'),
};
/* =====================================================
@visual
Visual states, hover and focus styles, paddings, margins, and snapshots.
===================================================== */
test.describe(`${TAG.VISUAL} `, () => {
const indicators = [
{ indicators: 'default', zoomWidth: 300, defaultIndex: undefined, index: undefined },
{ indicators: 'hide', zoomWidth: 300, defaultIndex: undefined, index: 1 },
{ indicators: 'preview', zoomWidth: 500, defaultIndex: 2, undefined: undefined },
];
indicators.forEach((item) => {
test(`Verify Carousel with indicators= ${item.indicators}, zoomiWidth= ${item.zoomWidth} and defaultIndex=${item.defaultIndex} or index = =${item.index}`, {
tag: [TAG.PRIORITY_HIGH,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_props.tsx', 'en', item);
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await test.step('Verify Prev and Next buttons Focus and Hover styles', async () => {
await page.keyboard.press('Tab');
await page.getByText('Previous slide').waitFor({ state: 'visible' });
await locators.button(page, 'Next slide').hover();
await page.getByText('Next slide').waitFor({ state: 'visible' });
await expect(page).toHaveScreenshot();
});
await test.step('Verify Carousel area focus', async () => {
await page.keyboard.press('Tab');
await expect(page).toHaveScreenshot();
});
if (await locators.tablist(page).isVisible()) {
await test.step('Verify Tabs hover and focus styles', async () => {
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
const tab = page.getByRole('tab');
await tab.nth(2).hover();
await expect(page).toHaveScreenshot();
await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Shift+Tab');
});
}
await test.step('Verify zoom prev and next hover styles', async () => {
await page.keyboard.press('Space');
await locators.modal(page).waitFor({ state: 'visible' });
await locators.img(page).nth(4).waitFor({ state: 'visible' });
await expect(page).toHaveScreenshot();
await page.keyboard.press('Tab');
await page.getByText('Previous slide').waitFor({ state: 'visible' });
await locators.button(page, 'Next slide').nth(1).hover();
await page.getByText('Next slide').waitFor({ state: 'visible' });
await expect(page).toHaveScreenshot();
});
await test.step('Verify Tabs in zoom mode hover and focus styles', async () => {
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
const tab = page.getByRole('tab');
if (await locators.tablist(page).count() === 2) {
await tab.nth(5).hover();
} else {
await tab.nth(2).hover();
}
await expect(page).toHaveScreenshot();
});
});
});
const bounded = [
{ indicators: 'default', bounded: true, defaultIndex: 0 },
{ indicators: 'preview', bounded: true, defaultIndex: 2 },
];
bounded.forEach((item) => {
test(`Verify Carousel prev and next buttons when indicators= ${item.indicators}, bounded= ${item.bounded}`, {
tag: [TAG.PRIORITY_HIGH,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_props.tsx', 'en', item);
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await test.step('Verify Prev and Next buttons when one is disabled', async () => {
await expect(page).toHaveScreenshot();
});
await test.step('VerifyPrev and Next buttons when one is disabled in zoom mode', async () => {
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.keyboard.press('Space');
await locators.img(page).nth(4).waitFor({ state: 'visible' });
await expect(page).toHaveScreenshot();
});
});
});
test('Verify carousel with indicators only', {
tag: [TAG.PRIORITY_HIGH,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_indicators_only.tsx', 'en');
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await expect(page).toHaveScreenshot();
});
test('Verify carousel with custom Prev and Next', {
tag: [TAG.PRIORITY_MEDIUM,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_prev_next.tsx', 'en');
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await expect(page).toHaveScreenshot();
});
});
/* =====================================================
@functional
Keyboard and mouse interactions - no snapshots here.
We verify states, visibility, and attributes.
===================================================== */
test.describe(`${TAG.FUNCTIONAL}`, () => {
test('Verify keyboard interactions with indicators and zoom', {
tag: [TAG.PRIORITY_HIGH,
TAG.KEYBOARD,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_props.tsx', 'en');
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await test.step('Verify prev button focused first', async () => {
await page.keyboard.press('Tab');
await expect(locators.button(page, 'Previous slide')).toBeFocused();
await expect(page.locator('[data-ui-name="Carousel.Prev"]')).toHaveAttribute('aria-controls');
});
await test.step('Verify carousel focused after prev button', async () => {
await page.keyboard.press('Tab');
await expect(locators.tabpanel(page, 0)).toBeFocused();
await expect(locators.region(page)).toHaveAttribute('aria-roledescription', 'carousel');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '-1');
});
await test.step('Verify Arrow Left switch between tabs', async () => {
await page.keyboard.press('ArrowLeft');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Arrow Right switch between tabs', async () => {
await page.keyboard.press('ArrowRight');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '-1');
});
await test.step('Verify next button focused by tab', async () => {
await page.keyboard.press('Tab');
await expect(locators.button(page, 'Next slide')).toBeFocused();
await expect(page.locator('[data-ui-name="Carousel.Next"]')).toHaveAttribute('aria-controls');
});
await test.step('Verify Next switches between tabs', async () => {
await page.keyboard.press('Space');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '-1');
});
await test.step('Verify indicators focused by tab', async () => {
await page.keyboard.press('Tab');
await expect(locators.tablist(page)).toBeFocused();
await expect(locators.tablist(page)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Arrow Right switch between tabs when indicators focused', async () => {
await page.keyboard.press('ArrowRight');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Zoom mode opened by Space', async () => {
await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Space');
await locators.modal(page).waitFor({ state: 'visible' });
await expect(page.locator('[data-ui-name="Modal.Close"]')).toBeFocused();
});
await test.step('Verify Zoom mode closed by Escape', async () => {
await page.keyboard.press('Escape');
await expect(locators.modal(page)).not.toBeVisible();
});
await test.step('Verify Zoom mode opened by Enter', async () => {
await page.keyboard.press('Enter');
await locators.modal(page).waitFor({ state: 'visible' });
await expect(locators.button(page, 'Close')).toBeFocused();
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Prev Button in zoom mode focused by Tab and switch tabs by Enter', async () => {
await page.keyboard.press('Tab');
await expect(locators.button(page, 'Previous slide').nth(1)).toBeFocused();
await page.keyboard.press('Enter');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '-1');
});
await test.step('Verify tabpanel focused and Right Arrow switch the tab', async () => {
await page.keyboard.press('Tab');
await expect(locators.tabpanel(page, 4)).toBeFocused();
await page.keyboard.press('ArrowRight');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Next Button in zoom mode focused by Tab and switch tabs by Enter', async () => {
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await expect(locators.button(page, 'Next slide').nth(1)).toBeFocused();
await page.keyboard.press('Enter');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '-1');
});
await test.step('Verify indicators in zoom mode focused by Tab and switch tabs by Arrows', async () => {
await page.keyboard.press('Tab');
await expect(locators.tablist(page, 1)).toBeFocused();
await page.keyboard.press('ArrowLeft');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify indicators in zoom mode focused by Tab and switch tabs by Arrows', async () => {
await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Enter');
await expect(locators.modal(page)).not.toBeVisible();
});
});
test('Verify mouse interactions with Carousel with indicators and zoom', {
tag: [TAG.PRIORITY_HIGH,
TAG.MOUSE,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_props.tsx', 'en');
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await test.step('Verify prev button activating switch tabs', async () => {
await locators.button(page, 'Previous slide').click();
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify next button activating switch tabs', async () => {
await locators.button(page, 'Next slide').click();
await expect(locators.region(page)).toHaveAttribute('aria-roledescription', 'carousel');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '-1');
});
await test.step('Verify clicking on tab switch tabs', async () => {
await locators.tab(page, 2).click();
await expect(locators.region(page)).toHaveAttribute('aria-roledescription', 'carousel');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Zoom mode opened by click on tab panel', async () => {
await locators.tabpanel(page, 2).click();
await locators.modal(page).waitFor({ state: 'visible' });
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Zoom mode closed by click anywhere on the screen', async () => {
await page.mouse.click(0, 0);
await expect(locators.modal(page)).not.toBeVisible();
});
await test.step('Verify tabs switch by click on Prev button im zoom mode', async () => {
await locators.tabpanel(page, 2).click();
await locators.modal(page).waitFor({ state: 'visible' });
await locators.button(page, 'Previous slide').nth(1).click();
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '-1');
});
await test.step('Verify tabs switch by click on Next button im zoom mode', async () => {
await locators.button(page, 'Next slide').nth(1).click();
await expect(locators.tabpanel(page, 3)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 3)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 4)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 5)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify Zoom mode closed by click on Close', async () => {
await page.locator('[data-ui-name="Modal.Close"]').click();
await expect(locators.modal(page)).not.toBeVisible();
});
await test.step('Verify Zoom mode closed by click on tabpanel', async () => {
await locators.tabpanel(page, 2).click();
await locators.modal(page).waitFor({ state: 'visible' });
await locators.tabpanel(page, 5).click();
await expect(locators.modal(page)).not.toBeVisible();
});
});
test('Verify mouse and keyboard interactions when zoom:false (modal not opened)', {
tag: [TAG.PRIORITY_HIGH,
TAG.KEYBOARD, TAG.MOUSE,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_props.tsx', 'en', { zoom: false });
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await test.step('Verify Modal not opened by keyboard', async () => {
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await expect(locators.tabpanel(page, 0)).toBeFocused();
await page.keyboard.press('Enter');
await expect(locators.modal(page)).not.toBeVisible();
});
await test.step('Verify Modal not opened by mouse click', async () => {
const box = await locators.tabpanel(page, 0).boundingBox();
if (box) {
await page.mouse.click(box.x + 10, box.y + 10);
}
await expect(locators.modal(page)).not.toBeVisible();
});
});
test('Verify keyboard interactions when Carousel with indicators only', {
tag: [TAG.PRIORITY_HIGH,
TAG.KEYBOARD,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_indicators_only.tsx', 'en');
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await test.step('Verify tabpanel focused by Tab', async () => {
await page.keyboard.press('Tab');
await expect(locators.tabpanel(page, 0)).toBeFocused();
});
await test.step('Verify tabs switch by Arrow', async () => {
await page.keyboard.press('ArrowLeft');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '0');
});
await test.step('Verify tab switch by clicking on indicators', async () => {
await locators.tab(page, 0).click();
await expect(locators.tabpanel(page, 0)).toHaveAttribute('aria-current', 'true');
await expect(locators.tabpanel(page, 0)).toHaveAttribute('tabindex', '0');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 1)).toHaveAttribute('tabindex', '-1');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('aria-current', 'false');
await expect(locators.tabpanel(page, 2)).toHaveAttribute('tabindex', '-1');
});
});
test('Verify CSS override for preview indicator sizes', {
tag: [TAG.PRIORITY_HIGH,
'@carousel'],
}, async ({ page }) => {
await loadPage(page, 'stories/components/carousel/tests/examples/carousel_with_props.tsx', 'en', {
indicators: 'preview',
zoom: false,
});
await locators.img(page).nth(0).waitFor({ state: 'visible' });
await test.step('Verify default preview indicator size is 100px', async () => {
const indicator = locators.tab(page, 0);
const box = await indicator.boundingBox();
expect(box?.width).toBeCloseTo(100, 0);
expect(box?.height).toBeCloseTo(100, 0);
await expect(indicator).toHaveAttribute('aria-roledescription', 'slide');
});
await test.step('Verify CSS override changes indicator size', async () => {
await page.addStyleTag({
content: `
[aria-roledescription="slide"] {
width: 150px !important;
height: 150px !important;
}
`,
});
// Wait for styles to apply
await page.waitForTimeout(100);
const indicator = locators.tab(page, 0);
const box = await indicator.boundingBox();
// the size overridden
expect(box?.width).toBeCloseTo(150, 0);
expect(box?.height).toBeCloseTo(150, 0);
});
});
});