|
1 | 1 | import { test, expect } from '@playwright/test'; |
| 2 | +import { TEST_URL, waitForMapLoad } from './helper'; |
2 | 3 |
|
3 | | -test.describe('External Style Support', () => { |
4 | | - test('should render map with external OSM Bright style', async ({ page }) => { |
5 | | - await page.goto('/e2e/external-style.html'); |
| 4 | +const EXTERNAL_STYLE_URL = 'https://tile.openstreetmap.jp/styles/osm-bright/style.json'; |
6 | 5 |
|
7 | | - // Wait for map to be loaded |
8 | | - await page.waitForFunction(() => { |
9 | | - const container = document.querySelector('#map'); |
10 | | - return container && (container as any).geoloniaMap; |
11 | | - }); |
| 6 | +test.describe('External Style Support', () => { |
| 7 | + test('data-style で外部スタイルを指定しても地図が表示されること', async ({ page }) => { |
| 8 | + await page.goto(`${TEST_URL}/external-style.html`); |
| 9 | + await waitForMapLoad(page, '#map'); |
12 | 10 |
|
13 | | - // Check if map is rendered |
14 | | - const mapCanvas = await page.locator('#map canvas.maplibregl-canvas'); |
| 11 | + const mapCanvas = page.locator('#map canvas.maplibregl-canvas'); |
15 | 12 | await expect(mapCanvas).toBeVisible(); |
16 | | - |
17 | | - // Verify that the map has loaded |
18 | | - const isMapLoaded = await page.evaluate(() => { |
19 | | - const container = document.querySelector('#map') as any; |
20 | | - const map = container.geoloniaMap; |
21 | | - return map && map.loaded(); |
22 | | - }); |
23 | | - |
24 | | - expect(isMapLoaded).toBe(true); |
25 | 13 | }); |
26 | 14 |
|
27 | | - test('should warn about missing API key but still work with external style', async ({ |
28 | | - page, |
29 | | - }) => { |
30 | | - const consoleMessages: string[] = []; |
31 | | - page.on('console', (msg) => { |
32 | | - if (msg.type() === 'warning') { |
33 | | - consoleMessages.push(msg.text()); |
34 | | - } |
35 | | - }); |
36 | | - |
37 | | - await page.goto('/e2e/external-style.html'); |
38 | | - |
39 | | - // Wait for map to be loaded |
40 | | - await page.waitForFunction(() => { |
41 | | - const container = document.querySelector('#map'); |
42 | | - return container && (container as any).geoloniaMap; |
43 | | - }); |
44 | | - |
45 | | - // Check if warning about API key was shown |
46 | | - const hasApiKeyWarning = consoleMessages.some((msg) => |
47 | | - msg.includes('API key not found'), |
| 15 | + test('data-style で指定した外部スタイルURLにアクセスしていること', async ({ page }) => { |
| 16 | + const styleRequest = page.waitForRequest((req) => |
| 17 | + req.url().includes(EXTERNAL_STYLE_URL), |
48 | 18 | ); |
49 | | - expect(hasApiKeyWarning).toBe(true); |
50 | | - }); |
51 | | - |
52 | | - test('should log external style loading info', async ({ page }) => { |
53 | | - const consoleMessages: string[] = []; |
54 | | - page.on('console', (msg) => { |
55 | | - if (msg.type() === 'log') { |
56 | | - consoleMessages.push(msg.text()); |
57 | | - } |
58 | | - }); |
59 | 19 |
|
60 | | - await page.goto('/e2e/external-style.html'); |
| 20 | + await page.goto(`${TEST_URL}/external-style.html`); |
61 | 21 |
|
62 | | - // Wait for map to be loaded |
63 | | - await page.waitForFunction(() => { |
64 | | - const container = document.querySelector('#map'); |
65 | | - return container && (container as any).geoloniaMap; |
66 | | - }); |
67 | | - |
68 | | - // Check if external style loading log was shown |
69 | | - const hasExternalStyleLog = consoleMessages.some((msg) => |
70 | | - msg.includes('Loading external style from'), |
71 | | - ); |
72 | | - expect(hasExternalStyleLog).toBe(true); |
| 22 | + const req = await styleRequest; |
| 23 | + expect(req.url()).toBe(EXTERNAL_STYLE_URL); |
73 | 24 | }); |
74 | 25 | }); |
0 commit comments