|
1 | 1 | // @ts-check |
2 | 2 | const { test, expect } = require('@playwright/test'); |
3 | | -const { BASE_URL, clearProjectsDB } = require('../helpers'); |
4 | | - |
5 | | -/** |
6 | | - * Create a project the same way a user does: type a IIIF info.json URL on the |
7 | | - * home page, click "Create my own project", fill the title, then click |
8 | | - * "Create my new project". Returns the project id parsed from the URL the app |
9 | | - * lands on (so the test can clean it up afterwards if needed). |
10 | | - * |
11 | | - * @param {import('@playwright/test').Page} page |
12 | | - * @param {string} iiifUrl |
13 | | - */ |
14 | | -async function createProjectFromIIIF(page, iiifUrl) { |
15 | | - await page.goto(`${BASE_URL}/#/`); |
16 | | - |
17 | | - const urlInput = page.getByRole('textbox', { name: 'https://iiif.emf.fr/iiif/3/' }); |
18 | | - await urlInput.click(); |
19 | | - await urlInput.fill(iiifUrl); |
20 | | - |
21 | | - await page.getByRole('button', { name: 'Create my own project' }).click(); |
22 | | - |
23 | | - const title = page.getByRole('textbox', { name: 'Title' }); |
24 | | - await title.click(); |
25 | | - await title.fill('Navigator test'); |
26 | | - |
27 | | - await page.getByRole('button', { name: 'Create my new project' }).click(); |
28 | | - |
29 | | - await page.waitForURL(/\/project\/([^/]+)\/edit/, { timeout: 30000 }); |
30 | | - const match = page.url().match(/\/project\/([^/]+)\/edit/); |
31 | | - if (!match) throw new Error(`Unexpected post-create URL: ${page.url()}`); |
32 | | - return match[1]; |
33 | | -} |
34 | | - |
35 | | -test.describe('AdnoNavigator positioning (via real UI flow)', () => { |
36 | | - // Real IIIF info.json from the Tabula Peutingeriana — extremely wide rouleau. |
37 | | - const HORIZONTAL_IIIF = 'https://iiif.omnesviae.org/image/peutinger.tiff/info.json'; |
38 | | - // Real IIIF info.json from Manchester (MS Latin 2) — extremely tall rouleau. |
39 | | - const VERTICAL_IIIF = 'https://image.digitalcollections.manchester.ac.uk/iiif/MS-LATIN-00002-000-00001.jp2/info.json'; |
40 | | - // Normal-ratio IIIF info.json, already used by other specs (SuomiNPP earth, square-ish). |
41 | | - const NORMAL_IIIF = 'https://iiif.emf.fr/iiif/3/SuomiNPP_earth_full.jp2/info.json'; |
| 3 | +const { BASE_URL, clearProjectsDB, seedProject } = require('../helpers'); |
| 4 | +const wideFixture = require('./wide.fixture.json'); |
| 5 | +const tallFixture = require('./tall.fixture.json'); |
| 6 | +const normalFixture = require('./normal.fixture.json'); |
42 | 7 |
|
| 8 | +test.describe('AdnoNavigator positioning', () => { |
43 | 9 | test.afterEach(async ({ page }) => { |
44 | | - // Wipe only this context's IndexedDB so the test leaves no residue. |
45 | | - // Playwright already isolates contexts per test; this is the explicit |
46 | | - // belt-and-suspenders the suite contracts for. |
47 | 10 | await clearProjectsDB(page); |
48 | 11 | }); |
49 | 12 |
|
50 | | - test('horizontal rouleau (Peutinger): navigator anchors bottom-center', async ({ page }) => { |
51 | | - await createProjectFromIIIF(page, HORIZONTAL_IIIF); |
| 13 | + test('horizontal rouleau: navigator anchors bottom-center', async ({ page }) => { |
| 14 | + await seedProject(page, wideFixture); |
| 15 | + await page.goto(`${BASE_URL}/#/project/${wideFixture.id}/view`); |
52 | 16 |
|
53 | 17 | const wrap = page.locator('.adno-navigator-wrap'); |
54 | 18 | await expect(wrap).toBeVisible({ timeout: 30000 }); |
55 | 19 | await expect(wrap).toHaveClass(/adno-navigator-wrap--bottom-center/); |
56 | 20 | }); |
57 | 21 |
|
58 | | - test('vertical rouleau (Manchester MS Latin 2): navigator anchors right-vertical', async ({ page }) => { |
59 | | - await createProjectFromIIIF(page, VERTICAL_IIIF); |
| 22 | + test('vertical rouleau: navigator anchors right-vertical', async ({ page }) => { |
| 23 | + await seedProject(page, tallFixture); |
| 24 | + await page.goto(`${BASE_URL}/#/project/${tallFixture.id}/view`); |
60 | 25 |
|
61 | 26 | const wrap = page.locator('.adno-navigator-wrap'); |
62 | 27 | await expect(wrap).toBeVisible({ timeout: 30000 }); |
63 | 28 | await expect(wrap).toHaveClass(/adno-navigator-wrap--right-vertical/); |
64 | 29 | }); |
65 | 30 |
|
66 | | - test('regular image (SuomiNPP): navigator stays bottom-right', async ({ page }) => { |
67 | | - await createProjectFromIIIF(page, NORMAL_IIIF); |
| 31 | + test('regular image: navigator stays bottom-right', async ({ page }) => { |
| 32 | + await seedProject(page, normalFixture); |
| 33 | + await page.goto(`${BASE_URL}/#/project/${normalFixture.id}/view`); |
68 | 34 |
|
69 | 35 | const wrap = page.locator('.adno-navigator-wrap'); |
70 | 36 | await expect(wrap).toBeVisible({ timeout: 30000 }); |
71 | 37 | await expect(wrap).toHaveClass(/adno-navigator-wrap--bottom-right/); |
72 | 38 | }); |
73 | 39 |
|
74 | 40 | test('view mode honours showNavigator: toggling it off hides the navigator', async ({ page }) => { |
75 | | - // 1. Create the project as a user would. |
76 | | - await createProjectFromIIIF(page, NORMAL_IIIF); |
77 | | - |
78 | | - // 2. Switch from edit mode to view mode using the navbar toggle. |
79 | | - const editViewToggle = page.locator('.toggle-success').first(); |
80 | | - await editViewToggle.click(); |
81 | | - await page.waitForURL(/\/project\/[^/]+\/view/, { timeout: 15000 }); |
| 41 | + await seedProject(page, normalFixture); |
| 42 | + await page.goto(`${BASE_URL}/#/project/${normalFixture.id}/view`); |
82 | 43 |
|
83 | | - // 3. Navigator should be visible by default in view mode (showNavigator=true). |
84 | 44 | await expect(page.locator('.adno-navigator-wrap')).toBeVisible({ timeout: 30000 }); |
85 | 45 |
|
86 | | - // 4. Open the settings modal and flip showNavigator off. |
87 | 46 | await page.locator('button.navbar-button svg[data-icon="gear"]').first().click(); |
88 | 47 | await page.locator('.toggle-navigator').first().click(); |
89 | 48 | await page.getByRole('button', { name: /save/i }).click(); |
90 | 49 |
|
91 | | - // 5. Navigator should disappear. |
92 | 50 | await expect(page.locator('.adno-navigator-wrap')).toHaveCount(0); |
93 | 51 | }); |
94 | 52 | }); |
0 commit comments