|
| 1 | +import { devices, expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +const MOBILE_VIEWPORT = devices['iPhone 14 Pro Max']; |
| 4 | + |
| 5 | +test.describe('Mobile map native experience', () => { |
| 6 | + const { defaultBrowserType: _bt, ...mobileContext } = MOBILE_VIEWPORT; |
| 7 | + |
| 8 | + test.describe('timezone-based startup region', () => { |
| 9 | + test('America/New_York → america view', async ({ browser }) => { |
| 10 | + const context = await browser.newContext({ |
| 11 | + ...mobileContext, |
| 12 | + timezoneId: 'America/New_York', |
| 13 | + locale: 'en-US', |
| 14 | + }); |
| 15 | + const page = await context.newPage(); |
| 16 | + await page.addInitScript(() => { |
| 17 | + (window as any).__testResolvedLocation = true; |
| 18 | + }); |
| 19 | + await page.goto('/'); |
| 20 | + await page.waitForTimeout(3000); |
| 21 | + const region = await page.evaluate(() => { |
| 22 | + const select = document.getElementById('regionSelect') as HTMLSelectElement | null; |
| 23 | + return select?.value ?? null; |
| 24 | + }); |
| 25 | + expect(region).toBe('america'); |
| 26 | + await context.close(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('Europe/London → eu view', async ({ browser }) => { |
| 30 | + const context = await browser.newContext({ |
| 31 | + ...mobileContext, |
| 32 | + timezoneId: 'Europe/London', |
| 33 | + locale: 'en-GB', |
| 34 | + }); |
| 35 | + const page = await context.newPage(); |
| 36 | + await page.goto('/'); |
| 37 | + await page.waitForTimeout(3000); |
| 38 | + const region = await page.evaluate(() => { |
| 39 | + const select = document.getElementById('regionSelect') as HTMLSelectElement | null; |
| 40 | + return select?.value ?? null; |
| 41 | + }); |
| 42 | + expect(region).toBe('eu'); |
| 43 | + await context.close(); |
| 44 | + }); |
| 45 | + |
| 46 | + test('Asia/Tokyo → asia view', async ({ browser }) => { |
| 47 | + const context = await browser.newContext({ |
| 48 | + ...mobileContext, |
| 49 | + timezoneId: 'Asia/Tokyo', |
| 50 | + locale: 'ja-JP', |
| 51 | + }); |
| 52 | + const page = await context.newPage(); |
| 53 | + await page.goto('/'); |
| 54 | + await page.waitForTimeout(3000); |
| 55 | + const region = await page.evaluate(() => { |
| 56 | + const select = document.getElementById('regionSelect') as HTMLSelectElement | null; |
| 57 | + return select?.value ?? null; |
| 58 | + }); |
| 59 | + expect(region).toBe('asia'); |
| 60 | + await context.close(); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + test.describe('URL restore', () => { |
| 65 | + test.use(mobileContext); |
| 66 | + |
| 67 | + test('lat/lon override view center', async ({ page }) => { |
| 68 | + await page.goto('/?view=eu&lat=48.86&lon=2.35&zoom=5'); |
| 69 | + await page.waitForTimeout(3000); |
| 70 | + const url = page.url(); |
| 71 | + const params = new URL(url).searchParams; |
| 72 | + const lat = params.get('lat'); |
| 73 | + const lon = params.get('lon'); |
| 74 | + if (lat && lon) { |
| 75 | + expect(parseFloat(lat)).toBeCloseTo(48.86, 0); |
| 76 | + expect(parseFloat(lon)).toBeCloseTo(2.35, 0); |
| 77 | + } else { |
| 78 | + const region = await page.evaluate(() => { |
| 79 | + const select = document.getElementById('regionSelect') as HTMLSelectElement | null; |
| 80 | + return select?.value ?? null; |
| 81 | + }); |
| 82 | + expect(region).not.toBe('eu'); |
| 83 | + } |
| 84 | + }); |
| 85 | + |
| 86 | + test('zero-degree coordinates center at equator/prime meridian', async ({ page }) => { |
| 87 | + await page.goto('/?lat=0&lon=0&zoom=4'); |
| 88 | + await page.waitForTimeout(3000); |
| 89 | + const url = page.url(); |
| 90 | + const params = new URL(url).searchParams; |
| 91 | + const lat = params.get('lat'); |
| 92 | + const lon = params.get('lon'); |
| 93 | + expect(lat).not.toBeNull(); |
| 94 | + expect(lon).not.toBeNull(); |
| 95 | + if (lat && lon) { |
| 96 | + expect(Math.abs(parseFloat(lat))).toBeLessThan(5); |
| 97 | + expect(Math.abs(parseFloat(lon))).toBeLessThan(5); |
| 98 | + } |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + test.describe('touch interactions', () => { |
| 103 | + test.use(mobileContext); |
| 104 | + |
| 105 | + test('single-finger pan does not scroll page', async ({ page }) => { |
| 106 | + await page.goto('/'); |
| 107 | + await page.waitForTimeout(3000); |
| 108 | + const mapEl = page.locator('#mapContainer'); |
| 109 | + await expect(mapEl).toBeVisible({ timeout: 10000 }); |
| 110 | + |
| 111 | + const scrollBefore = await page.evaluate(() => window.scrollY); |
| 112 | + |
| 113 | + const box = await mapEl.boundingBox(); |
| 114 | + if (box) { |
| 115 | + const startX = box.x + box.width / 2; |
| 116 | + const startY = box.y + box.height / 2; |
| 117 | + await page.touchscreen.tap(startX, startY); |
| 118 | + await page.mouse.move(startX, startY); |
| 119 | + await page.touchscreen.tap(startX, startY + 50); |
| 120 | + } |
| 121 | + |
| 122 | + const scrollAfter = await page.evaluate(() => window.scrollY); |
| 123 | + expect(scrollAfter).toBe(scrollBefore); |
| 124 | + }); |
| 125 | + }); |
| 126 | + |
| 127 | + test.describe('breakpoint consistency at 768px', () => { |
| 128 | + test('JS and CSS agree at exactly 768px', async ({ browser }) => { |
| 129 | + const context = await browser.newContext({ |
| 130 | + viewport: { width: 768, height: 1024 }, |
| 131 | + locale: 'en-US', |
| 132 | + }); |
| 133 | + const page = await context.newPage(); |
| 134 | + await page.goto('/'); |
| 135 | + await page.waitForTimeout(2000); |
| 136 | + |
| 137 | + const result = await page.evaluate(() => { |
| 138 | + const jsMobile = window.innerWidth <= 768; |
| 139 | + const el = document.createElement('div'); |
| 140 | + el.style.display = 'none'; |
| 141 | + document.body.appendChild(el); |
| 142 | + const cssMobile = window.matchMedia('(max-width: 768px)').matches; |
| 143 | + el.remove(); |
| 144 | + return { jsMobile, cssMobile }; |
| 145 | + }); |
| 146 | + |
| 147 | + expect(result.jsMobile).toBe(result.cssMobile); |
| 148 | + await context.close(); |
| 149 | + }); |
| 150 | + }); |
| 151 | +}); |
0 commit comments