|
1 | 1 | import { test, expect } from '@playwright/test'; |
2 | | -import { TEST_URL, LOAD_TIMEOUT } from './helper'; |
3 | 2 |
|
4 | 3 | test.describe('External Style Support', () => { |
5 | 4 | test('should render map with external OSM Bright style', async ({ page }) => { |
6 | | - await page.goto(`${TEST_URL}/external-style.html`); |
| 5 | + await page.goto('/e2e/external-style.html'); |
7 | 6 |
|
8 | | - // Wait for map object to be created |
| 7 | + // Wait for map to be loaded |
9 | 8 | await page.waitForFunction(() => { |
10 | 9 | const container = document.querySelector('#map'); |
11 | 10 | return container && (container as any).geoloniaMap; |
12 | | - }, { timeout: LOAD_TIMEOUT }); |
| 11 | + }); |
13 | 12 |
|
14 | | - // Check that the map container and canvas are visible |
15 | | - const mapContainer = page.locator('#map'); |
16 | | - await expect(mapContainer).toBeVisible(); |
17 | | - const mapCanvas = page.locator('#map canvas.maplibregl-canvas'); |
| 13 | + // Check if map is rendered |
| 14 | + const mapCanvas = await page.locator('#map canvas.maplibregl-canvas'); |
18 | 15 | await expect(mapCanvas).toBeVisible(); |
19 | 16 |
|
20 | | - // Verify that the map instance has the correct center from data attributes |
21 | | - const center = await page.evaluate(() => { |
| 17 | + // Verify that the map has loaded |
| 18 | + const isMapLoaded = await page.evaluate(() => { |
22 | 19 | const container = document.querySelector('#map') as any; |
23 | | - return container.geoloniaMap.getCenter(); |
| 20 | + const map = container.geoloniaMap; |
| 21 | + return map && map.loaded(); |
24 | 22 | }); |
25 | | - expect(center.lat).toBeCloseTo(35.6812, 1); |
26 | | - expect(center.lng).toBeCloseTo(139.7671, 1); |
| 23 | + |
| 24 | + expect(isMapLoaded).toBe(true); |
27 | 25 | }); |
28 | 26 |
|
29 | | - test('should not throw errors when using external style without API key', async ({ page }) => { |
30 | | - const consoleErrors: string[] = []; |
| 27 | + test('should warn about missing API key but still work with external style', async ({ |
| 28 | + page, |
| 29 | + }) => { |
| 30 | + const consoleMessages: string[] = []; |
31 | 31 | page.on('console', (msg) => { |
32 | | - if (msg.type() === 'error') { |
33 | | - consoleErrors.push(msg.text()); |
| 32 | + if (msg.type() === 'warning') { |
| 33 | + consoleMessages.push(msg.text()); |
34 | 34 | } |
35 | 35 | }); |
36 | 36 |
|
37 | | - await page.goto(`${TEST_URL}/external-style.html`); |
| 37 | + await page.goto('/e2e/external-style.html'); |
38 | 38 |
|
| 39 | + // Wait for map to be loaded |
39 | 40 | await page.waitForFunction(() => { |
40 | 41 | const container = document.querySelector('#map'); |
41 | 42 | return container && (container as any).geoloniaMap; |
42 | | - }, { timeout: LOAD_TIMEOUT }); |
| 43 | + }); |
43 | 44 |
|
44 | | - // External style should work without API key errors |
45 | | - const hasApiKeyError = consoleErrors.some((msg) => |
46 | | - msg.includes('API key'), |
| 45 | + // Check if warning about API key was shown |
| 46 | + const hasApiKeyWarning = consoleMessages.some((msg) => |
| 47 | + msg.includes('API key not found'), |
47 | 48 | ); |
48 | | - expect(hasApiKeyError).toBe(false); |
| 49 | + expect(hasApiKeyWarning).toBe(true); |
49 | 50 | }); |
50 | 51 |
|
51 | | - test('should display map tiles from external source', async ({ page }) => { |
52 | | - await page.goto(`${TEST_URL}/external-style.html`); |
| 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 | + |
| 60 | + await page.goto('/e2e/external-style.html'); |
53 | 61 |
|
| 62 | + // Wait for map to be loaded |
54 | 63 | await page.waitForFunction(() => { |
55 | 64 | const container = document.querySelector('#map'); |
56 | 65 | return container && (container as any).geoloniaMap; |
57 | | - }, { timeout: LOAD_TIMEOUT }); |
58 | | - |
59 | | - // Verify canvas has rendered content (not blank) |
60 | | - const isNotBlank = await page.evaluate(() => { |
61 | | - const canvas = document.querySelector('#map canvas.maplibregl-canvas') as HTMLCanvasElement; |
62 | | - const gl = canvas.getContext('webgl2') || canvas.getContext('webgl'); |
63 | | - if (!gl) return false; |
64 | | - |
65 | | - const width = canvas.width; |
66 | | - const height = Math.floor(canvas.height / 2); |
67 | | - const pixels = new Uint8Array(width * height * 4); |
68 | | - gl.readPixels(0, Math.floor(canvas.height / 2), width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels); |
69 | | - |
70 | | - let nonWhiteCount = 0; |
71 | | - const totalPixels = pixels.length / 4; |
72 | | - for (let i = 0; i < pixels.length; i += 4) { |
73 | | - if (pixels[i] < 250 || pixels[i + 1] < 250 || pixels[i + 2] < 250) { |
74 | | - nonWhiteCount++; |
75 | | - if (nonWhiteCount > totalPixels * 0.01) return true; |
76 | | - } |
77 | | - } |
78 | | - return nonWhiteCount > 0; |
79 | 66 | }); |
80 | 67 |
|
81 | | - expect(isNotBlank).toBe(true); |
| 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); |
82 | 73 | }); |
83 | 74 | }); |
0 commit comments