Path: blob/main/test/componentFixtures/playwright/tests/imageCarousel.spec.ts
13527 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { test, expect } from '@playwright/test';6import { openFixture } from './utils.js';78test.describe('Image Carousel', () => {910test('clicking next arrow advances to the next image', async ({ page }) => {11await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');1213const counter = page.locator('.image-counter');14await expect(counter).toHaveText('1 / 5');1516const nextBtn = page.locator('button.next-arrow');17await nextBtn.click();1819await expect(counter).toHaveText('2 / 5');20});2122test('clicking previous arrow goes back', async ({ page }) => {23await openFixture(page, 'imageCarousel/imageCarousel/SingleSectionMiddleImage/Dark');2425const counter = page.locator('.image-counter');26// Starts at image 3 (index 2)27await expect(counter).toHaveText('3 / 5');2829const prevBtn = page.locator('button.prev-arrow');30await prevBtn.click();3132await expect(counter).toHaveText('2 / 5');33});3435test('previous button is disabled on first image', async ({ page }) => {36await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');3738const prevBtn = page.locator('button.prev-arrow');39await expect(prevBtn).toBeDisabled();4041const nextBtn = page.locator('button.next-arrow');42await expect(nextBtn).toBeEnabled();43});4445test('next button is disabled on last image', async ({ page }) => {46await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');4748const nextBtn = page.locator('button.next-arrow');4950// Click through to the last image (5 images, need 4 clicks)51for (let i = 0; i < 4; i++) {52await nextBtn.click();53}5455await expect(nextBtn).toBeDisabled();5657const counter = page.locator('.image-counter');58await expect(counter).toHaveText('5 / 5');59});6061test('caption updates when navigating', async ({ page }) => {62await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');6364const caption = page.locator('.caption-text');65// First image: "A red image"66await expect(caption).toHaveText('A red image');6768await page.locator('button.next-arrow').click();69// Second image: "A green image"70await expect(caption).toHaveText('A green image');7172await page.locator('button.next-arrow').click();73// Third image has no caption — element should be hidden74await expect(caption).toBeHidden();75});7677test('clicking a thumbnail selects that image', async ({ page }) => {78await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');7980const thumbnails = page.locator('button.thumbnail');81const counter = page.locator('.image-counter');8283// Click the third thumbnail84await thumbnails.nth(2).click();85await expect(counter).toHaveText('3 / 5');8687// The clicked thumbnail should be active88await expect(thumbnails.nth(2)).toHaveClass(/active/);89});9091test('keyboard left/right arrow navigation works', async ({ page }) => {92await openFixture(page, 'imageCarousel/imageCarousel/SingleSection/Dark');9394const counter = page.locator('.image-counter');95await expect(counter).toHaveText('1 / 5');9697// Focus the slideshow container for keyboard events98await page.locator('.slideshow-container').focus();99100await page.keyboard.press('ArrowRight');101await expect(counter).toHaveText('2 / 5');102103await page.keyboard.press('ArrowRight');104await expect(counter).toHaveText('3 / 5');105106await page.keyboard.press('ArrowLeft');107await expect(counter).toHaveText('2 / 5');108});109110test('single image carousel disables both nav buttons', async ({ page }) => {111await openFixture(page, 'imageCarousel/imageCarousel/SingleImage/Dark');112113const prevBtn = page.locator('button.prev-arrow');114const nextBtn = page.locator('button.next-arrow');115116await expect(prevBtn).toBeDisabled();117await expect(nextBtn).toBeDisabled();118119const counter = page.locator('.image-counter');120await expect(counter).toHaveText('1 / 1');121});122});123124125