Skip to content

Commit 7bbb0b1

Browse files
authored
Merge pull request #7 from d-oit/add-playwright-tests
Add playwright tests for example site pages
2 parents 434f70f + 3796956 commit 7bbb0b1

File tree

5 files changed

+136
-2
lines changed

5 files changed

+136
-2
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ jobs:
3939

4040
- name: Run tests
4141
run: npm run test
42+
43+
- name: Run Playwright tests
44+
run: npm run test:playwright

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
npm test
2+
npm run test:playwright

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"postinstall": "echo TODO: add postinstall instructions",
2525
"test": "npm run -s build",
2626
"upgrade": "npx npm-check-updates -u && npm run -s mod:update",
27-
"prepare": "node .husky/install.mjs"
27+
"prepare": "node .husky/install.mjs",
28+
"test:playwright": "playwright test"
2829
},
2930
"repository": {
3031
"type": "git",
@@ -47,7 +48,8 @@
4748
"hugo-bin": "^0.137.1",
4849
"husky": "^9.1.7",
4950
"rimraf": "^6.0.1",
50-
"semantic-release": "^24.2.0"
51+
"semantic-release": "^24.2.0",
52+
"playwright": "^1.20.0"
5153
},
5254
"hugo-bin": {
5355
"buildTags": "extended"

playwright.config.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: './tests',
5+
timeout: 30000,
6+
expect: {
7+
timeout: 5000,
8+
},
9+
reporter: 'html',
10+
use: {
11+
actionTimeout: 0,
12+
baseURL: 'http://localhost:3000',
13+
trace: 'on-first-retry',
14+
},
15+
projects: [
16+
{
17+
name: 'Desktop Chrome',
18+
use: {
19+
...devices['Desktop Chrome'],
20+
viewport: { width: 1280, height: 720 },
21+
},
22+
},
23+
{
24+
name: 'Desktop Firefox',
25+
use: {
26+
...devices['Desktop Firefox'],
27+
viewport: { width: 1280, height: 720 },
28+
},
29+
},
30+
{
31+
name: 'Desktop Safari',
32+
use: {
33+
...devices['Desktop Safari'],
34+
viewport: { width: 1280, height: 720 },
35+
},
36+
},
37+
{
38+
name: 'Mobile Chrome',
39+
use: {
40+
...devices['Pixel 5'],
41+
viewport: { width: 412, height: 915 },
42+
},
43+
},
44+
{
45+
name: 'Mobile Safari',
46+
use: {
47+
...devices['iPhone 12'],
48+
viewport: { width: 390, height: 844 },
49+
},
50+
},
51+
],
52+
});

tests/exampleSite.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)