Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/componentFixtures/playwright/tests/imageCarousel.spec.ts
13527 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { test, expect } from '@playwright/test';
7
import { openFixture } from './utils.js';
8
9
test.describe('Image Carousel', () => {
10
11
test('clicking next arrow advances to the next image', async ({ page }) => {
12
await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');
13
14
const counter = page.locator('.image-counter');
15
await expect(counter).toHaveText('1 / 5');
16
17
const nextBtn = page.locator('button.next-arrow');
18
await nextBtn.click();
19
20
await expect(counter).toHaveText('2 / 5');
21
});
22
23
test('clicking previous arrow goes back', async ({ page }) => {
24
await openFixture(page, 'imageCarousel/imageCarousel/SingleSectionMiddleImage/Dark');
25
26
const counter = page.locator('.image-counter');
27
// Starts at image 3 (index 2)
28
await expect(counter).toHaveText('3 / 5');
29
30
const prevBtn = page.locator('button.prev-arrow');
31
await prevBtn.click();
32
33
await expect(counter).toHaveText('2 / 5');
34
});
35
36
test('previous button is disabled on first image', async ({ page }) => {
37
await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');
38
39
const prevBtn = page.locator('button.prev-arrow');
40
await expect(prevBtn).toBeDisabled();
41
42
const nextBtn = page.locator('button.next-arrow');
43
await expect(nextBtn).toBeEnabled();
44
});
45
46
test('next button is disabled on last image', async ({ page }) => {
47
await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');
48
49
const nextBtn = page.locator('button.next-arrow');
50
51
// Click through to the last image (5 images, need 4 clicks)
52
for (let i = 0; i < 4; i++) {
53
await nextBtn.click();
54
}
55
56
await expect(nextBtn).toBeDisabled();
57
58
const counter = page.locator('.image-counter');
59
await expect(counter).toHaveText('5 / 5');
60
});
61
62
test('caption updates when navigating', async ({ page }) => {
63
await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');
64
65
const caption = page.locator('.caption-text');
66
// First image: "A red image"
67
await expect(caption).toHaveText('A red image');
68
69
await page.locator('button.next-arrow').click();
70
// Second image: "A green image"
71
await expect(caption).toHaveText('A green image');
72
73
await page.locator('button.next-arrow').click();
74
// Third image has no caption — element should be hidden
75
await expect(caption).toBeHidden();
76
});
77
78
test('clicking a thumbnail selects that image', async ({ page }) => {
79
await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');
80
81
const thumbnails = page.locator('button.thumbnail');
82
const counter = page.locator('.image-counter');
83
84
// Click the third thumbnail
85
await thumbnails.nth(2).click();
86
await expect(counter).toHaveText('3 / 5');
87
88
// The clicked thumbnail should be active
89
await expect(thumbnails.nth(2)).toHaveClass(/active/);
90
});
91
92
test('keyboard left/right arrow navigation works', async ({ page }) => {
93
await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');
94
95
const counter = page.locator('.image-counter');
96
await expect(counter).toHaveText('1 / 5');
97
98
// Focus the slideshow container for keyboard events
99
await page.locator('.slideshow-container').focus();
100
101
await page.keyboard.press('ArrowRight');
102
await expect(counter).toHaveText('2 / 5');
103
104
await page.keyboard.press('ArrowRight');
105
await expect(counter).toHaveText('3 / 5');
106
107
await page.keyboard.press('ArrowLeft');
108
await expect(counter).toHaveText('2 / 5');
109
});
110
111
test('single image carousel disables both nav buttons', async ({ page }) => {
112
await openFixture(page, 'imageCarousel/imageCarousel/SingleImage/Dark');
113
114
const prevBtn = page.locator('button.prev-arrow');
115
const nextBtn = page.locator('button.next-arrow');
116
117
await expect(prevBtn).toBeDisabled();
118
await expect(nextBtn).toBeDisabled();
119
120
const counter = page.locator('.image-counter');
121
await expect(counter).toHaveText('1 / 1');
122
});
123
});
124
125