|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const pages = [ |
| 4 | + '/', |
| 5 | + '/gallery/', |
| 6 | + '/gallery/gallery-slideshow-resources-images-sample/', |
| 7 | + '/gallery/gallery-slideshow-sample-1/', |
| 8 | + '/gallery/gallery-slideshow-sample-2/', |
| 9 | + '/gallery/gallery-slideshow-sample-3/', |
| 10 | +]; |
| 11 | + |
| 12 | +const viewports = [ |
| 13 | + { width: 1280, height: 720, name: 'Desktop' }, |
| 14 | + { width: 412, height: 915, name: 'Mobile Portrait' }, |
| 15 | + { width: 915, height: 412, name: 'Mobile Landscape' }, |
| 16 | +]; |
| 17 | + |
| 18 | +for (const page of pages) { |
| 19 | + for (const viewport of viewports) { |
| 20 | + test.describe(`${viewport.name} view - ${page}`, () => { |
| 21 | + test.beforeEach(async ({ page }) => { |
| 22 | + await page.setViewportSize({ width: viewport.width, height: viewport.height }); |
| 23 | + await page.goto(page); |
| 24 | + }); |
| 25 | + |
| 26 | + test('should display the slideshow gallery correctly', async ({ page }) => { |
| 27 | + const gallery = await page.$('.slideshow-gallery'); |
| 28 | + expect(gallery).not.toBeNull(); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should navigate through images using next and previous buttons', async ({ page }) => { |
| 32 | + const nextButton = await page.$('.slideshow-next-button'); |
| 33 | + const prevButton = await page.$('.slideshow-prev-button'); |
| 34 | + expect(nextButton).not.toBeNull(); |
| 35 | + expect(prevButton).not.toBeNull(); |
| 36 | + |
| 37 | + await nextButton.click(); |
| 38 | + const currentIndex = await page.$eval('.lightbox-current-index', el => el.textContent); |
| 39 | + expect(currentIndex).toBe('2'); |
| 40 | + |
| 41 | + await prevButton.click(); |
| 42 | + const newIndex = await page.$eval('.lightbox-current-index', el => el.textContent); |
| 43 | + expect(newIndex).toBe('1'); |
| 44 | + }); |
| 45 | + |
| 46 | + test('should display fullscreen button and work correctly', async ({ page }) => { |
| 47 | + const fullscreenButton = await page.$('.slideshow-fullscreen-button'); |
| 48 | + expect(fullscreenButton).not.toBeNull(); |
| 49 | + |
| 50 | + await fullscreenButton.click(); |
| 51 | + const isFullscreen = await page.evaluate(() => document.fullscreenElement !== null); |
| 52 | + expect(isFullscreen).toBe(true); |
| 53 | + }); |
| 54 | + |
| 55 | + test('should display thumbnails and navigate to corresponding image', async ({ page }) => { |
| 56 | + const thumbnails = await page.$$('.slideshow-thumbnail-image'); |
| 57 | + expect(thumbnails.length).toBeGreaterThan(0); |
| 58 | + |
| 59 | + await thumbnails[1].click(); |
| 60 | + const currentIndex = await page.$eval('.lightbox-current-index', el => el.textContent); |
| 61 | + expect(currentIndex).toBe('2'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('should display captions and descriptions correctly', async ({ page }) => { |
| 65 | + const captions = await page.$$('.figure-caption'); |
| 66 | + expect(captions.length).toBeGreaterThan(0); |
| 67 | + |
| 68 | + for (const caption of captions) { |
| 69 | + const text = await caption.textContent(); |
| 70 | + expect(text).not.toBeNull(); |
| 71 | + expect(text.length).toBeGreaterThan(0); |
| 72 | + } |
| 73 | + }); |
| 74 | + }); |
| 75 | + } |
| 76 | +} |
0 commit comments