|
1 | 1 | import { test, expect } from "@playwright/test"; |
2 | 2 |
|
3 | | -test("Slideshow 0", async ({ page }) => { |
4 | | - await page.goto("/template/slideshow-0"); |
| 3 | +test.describe("slideshow-0: UI tests", () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await page.goto("/template/slideshow-0"); |
| 6 | + }); |
5 | 7 |
|
6 | | - // TODO |
| 8 | + test("Slides/image change every 5 seconds", async ({ page }) => { |
| 9 | + const slideChangeInterval = 6000; |
| 10 | + const imagePaths = [ |
| 11 | + "/fixtures/template/images/mountain1.jpeg", |
| 12 | + "/fixtures/template/images/mountain2.jpeg", |
| 13 | + "/fixtures/template/images/mountain3.jpeg", |
| 14 | + "/fixtures/template/images/mountain4.jpeg", |
| 15 | + ]; |
| 16 | + |
| 17 | + const getActiveSlide = () => |
| 18 | + page.locator('.fade-container[data-active="true"]'); |
| 19 | + const getInactiveSlides = () => |
| 20 | + page.locator('.fade-container[data-active="false"]'); |
| 21 | + |
| 22 | + let previousIndex = null; |
| 23 | + |
| 24 | + for (const expectedImage of imagePaths) { |
| 25 | + const activeSlide = await getActiveSlide(); |
| 26 | + const activeIndex = await activeSlide.getAttribute("data-index"); |
| 27 | + |
| 28 | + if (previousIndex !== null) { |
| 29 | + expect(activeIndex).not.toBe(previousIndex); |
| 30 | + } |
| 31 | + previousIndex = activeIndex; |
| 32 | + |
| 33 | + await expect(activeSlide).toHaveCSS("opacity", "1"); |
| 34 | + |
| 35 | + const image = activeSlide.locator(".image"); |
| 36 | + await expect(image).toHaveCSS( |
| 37 | + "background-image", |
| 38 | + new RegExp(expectedImage), |
| 39 | + ); |
| 40 | + |
| 41 | + const inactiveSlides = getInactiveSlides(); |
| 42 | + const count = await inactiveSlides.count(); |
| 43 | + for (let i = 0; i < count; i++) { |
| 44 | + await expect(inactiveSlides.nth(i)).toHaveCSS("opacity", "0"); |
| 45 | + } |
| 46 | + |
| 47 | + if (expectedImage !== imagePaths[imagePaths.length - 1]) { |
| 48 | + await page.waitForTimeout(slideChangeInterval); |
| 49 | + } |
| 50 | + } |
| 51 | + }); |
| 52 | + |
| 53 | + test("Should apply logo classes", async ({ page }) => { |
| 54 | + const img = page.locator("img"); |
| 55 | + expect(img).toHaveAttribute( |
| 56 | + "class", |
| 57 | + "logo logo-margin l logo-position-bottom-right", |
| 58 | + ); |
| 59 | + }); |
7 | 60 | }); |
8 | 61 |
|
9 | | -test("Slideshow 1", async ({ page }) => { |
10 | | - await page.goto("/template/slideshow-1-no-stuff"); |
| 62 | +test.describe("slideshow-1-no-stuff: UI Tests", async () => { |
| 63 | + test.beforeEach(async ({ page }) => { |
| 64 | + await page.goto("/template/slideshow-1-no-stuff"); |
| 65 | + }); |
11 | 66 |
|
12 | | - // TODO |
| 67 | + test("Should not show logo", async ({ page }) => { |
| 68 | + const img = page.locator("img"); |
| 69 | + expect(img).toHaveCount(0); |
| 70 | + }); |
13 | 71 | }); |
14 | 72 |
|
15 | | -test("Slideshow 2", async ({ page }) => { |
16 | | - await page.goto("/template/slideshow-2"); |
| 73 | +test.describe("slideshow-2: UI Tests", async () => { |
| 74 | + test.beforeEach(async ({ page }) => { |
| 75 | + await page.goto("/template/slideshow-2"); |
| 76 | + }); |
17 | 77 |
|
18 | | - // TODO |
| 78 | + test("Should apply logo classes", async ({ page }) => { |
| 79 | + const img = page.locator("img"); |
| 80 | + expect(img).toHaveAttribute("class", "logo l logo-position-top-right"); |
| 81 | + }); |
19 | 82 | }); |
0 commit comments