|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { devices, expect, test } from '@playwright/test' |
| 7 | +import { login } from '../support/nc-login' |
| 8 | +import { setAppConfig } from '../support/nc-provisioning' |
7 | 9 |
|
8 | 10 | test.use({ |
9 | 11 | ...devices['Pixel 7'], |
10 | 12 | }) |
11 | 13 |
|
12 | 14 | test('PDF viewer allows horizontal scrolling on mobile viewport', async ({ page }) => { |
13 | | - // Navigate to a test page with a wide PDF |
14 | | - await page.goto('./apps/libresign') |
15 | | - |
16 | | - // Wait for the app to load |
17 | | - await expect(page.locator('[class*="pdf-editor"]')).toBeVisible({ timeout: 10000 }) |
18 | | - |
19 | | - // Verify the PDF elements root container exists and is scrollable |
20 | | - const pdfRoot = page.locator('.pdf-elements-root') |
21 | | - await expect(pdfRoot).toBeVisible() |
22 | | - |
23 | | - // Check that overflow-x is set to auto (not hidden) |
| 15 | + await login( |
| 16 | + page.request, |
| 17 | + process.env.NEXTCLOUD_ADMIN_USER ?? 'admin', |
| 18 | + process.env.NEXTCLOUD_ADMIN_PASSWORD ?? 'admin', |
| 19 | + ) |
| 20 | + |
| 21 | + await setAppConfig( |
| 22 | + page.request, |
| 23 | + 'libresign', 'add_footer', '1', |
| 24 | + ) |
| 25 | + |
| 26 | + await setAppConfig( |
| 27 | + page.request, |
| 28 | + 'libresign', 'footer_template_is_default', '0', |
| 29 | + ) |
| 30 | + |
| 31 | + await page.goto('./settings/admin/libresign') |
| 32 | + const pdfRoot = page.locator('.footer-template-section .pdf-elements-root').first() |
| 33 | + await expect(pdfRoot).toBeVisible({ timeout: 15000 }) |
| 34 | + |
| 35 | + // Check that overflow-x is set to auto (not hidden). |
24 | 36 | const computedStyle = await pdfRoot.evaluate((el) => { |
25 | 37 | return window.getComputedStyle(el).overflowX |
26 | 38 | }) |
27 | | - |
| 39 | + |
28 | 40 | expect(computedStyle).not.toBe('hidden') |
29 | 41 | expect(['auto', 'scroll']).toContain(computedStyle) |
30 | | - |
31 | | - // Verify touch-action is set correctly for touch events |
| 42 | + |
| 43 | + // Verify touch-action is set correctly for touch gestures. |
32 | 44 | const touchAction = await pdfRoot.evaluate((el) => { |
33 | 45 | return window.getComputedStyle(el).touchAction |
34 | 46 | }) |
35 | | - |
| 47 | + |
36 | 48 | expect(touchAction).toContain('pan') |
37 | 49 | expect(touchAction).not.toContain('pinch-zoom') |
| 50 | + |
| 51 | + // Validate real horizontal scrolling capability, not only style declarations. |
| 52 | + const before = await pdfRoot.evaluate((el) => { |
| 53 | + el.scrollLeft = 0 |
| 54 | + return { |
| 55 | + scrollLeft: el.scrollLeft, |
| 56 | + scrollWidth: el.scrollWidth, |
| 57 | + clientWidth: el.clientWidth, |
| 58 | + } |
| 59 | + }) |
| 60 | + |
| 61 | + expect(before.scrollWidth).toBeGreaterThan(before.clientWidth) |
| 62 | + |
| 63 | + const box = await pdfRoot.boundingBox() |
| 64 | + expect(box).not.toBeNull() |
| 65 | + |
| 66 | + if (!box) { |
| 67 | + throw new Error('PDF scroll container bounding box is not available') |
| 68 | + } |
| 69 | + |
| 70 | + const y = box.y + (box.height / 2) |
| 71 | + await page.mouse.move(box.x + box.width - 12, y) |
| 72 | + await page.mouse.down() |
| 73 | + await page.mouse.move(box.x + 12, y, { steps: 12 }) |
| 74 | + await page.mouse.up() |
| 75 | + |
| 76 | + const afterGesture = await pdfRoot.evaluate((el) => el.scrollLeft) |
| 77 | + // In Playwright mobile emulation, mouse drag may not trigger native touch scrolling. |
| 78 | + // Keep this as an observation, while asserting actual scrollability below. |
| 79 | + expect(afterGesture).toBeGreaterThanOrEqual(0) |
| 80 | + |
| 81 | + const afterScrollLeft = await pdfRoot.evaluate((el) => { |
| 82 | + const target = Math.max(el.scrollLeft + 1, el.scrollWidth - el.clientWidth) |
| 83 | + el.scrollLeft = target |
| 84 | + return el.scrollLeft |
| 85 | + }) |
| 86 | + |
| 87 | + expect(afterScrollLeft).toBeGreaterThan(before.scrollLeft) |
38 | 88 | }) |
0 commit comments