Skip to content

Commit af3aed6

Browse files
committed
Add tests for <map-layer media="..."> attribute
1 parent 7eb1f65 commit af3aed6

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { test, expect, chromium } from '@playwright/test';
2+
3+
test.describe('map-layer media attribute', () => {
4+
let page;
5+
let context;
6+
let viewer;
7+
test.beforeAll(async function () {
8+
context = await chromium.launchPersistentContext('');
9+
page =
10+
context.pages().find((page) => page.url() === 'about:blank') ||
11+
(await context.newPage());
12+
await page.goto('map-layer-media.html');
13+
await page.waitForTimeout(1000);
14+
viewer = page.getByTestId('viewer');
15+
});
16+
test('On initial load, a matching media queried layer is enabled', async ()=>{
17+
const matchedQueryLayer = page.getByTestId('initial-mq');
18+
// map loads at z=2, query matches 0 <= z <= 3
19+
await expect(matchedQueryLayer).not.toHaveAttribute('disabled', '');
20+
});
21+
test(`A visible (enabled) map-layer with no media query should remain enabled \
22+
when a matching mq is added`, async ()=> {
23+
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
24+
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
25+
await viewer.evaluate((v) => v.zoomTo(v.lat,v.lon,4));
26+
await page.waitForTimeout(200);
27+
// should still be enabled:
28+
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
29+
});
30+
test(`A visible (enabled) map-layer with no media query should be disabled \
31+
when a non-matching media query attribute is set`, async ()=> {
32+
await expect(viewer).toHaveAttribute('zoom','4');
33+
const presentInLayerControl = await viewer.evaluate((v) => {
34+
let lc = v._layerControl;
35+
let layers = lc._layers.map((e) => e.layer._layerEl);
36+
let noInitialQueryLayer = v.querySelector('[data-testid=no-initial-mq]');
37+
return layers.some((e) => e === noInitialQueryLayer);
38+
});
39+
expect(presentInLayerControl).toBe(true);
40+
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
41+
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
42+
await noInitialQueryLayer.evaluate((l) => l.media = '(0 <= map-zoom <=3)');
43+
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
44+
});
45+
test(`A mq-disabled layer is removed from the layer control`,async ()=>{
46+
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
47+
await expect(noInitialQueryLayer).toHaveAttribute('media','(0 <= map-zoom <=3)');
48+
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
49+
const presentInLayerControl = await viewer.evaluate((v) => {
50+
let lc = v._layerControl;
51+
let layers = lc._layers.map((e) => e.layer._layerEl);
52+
let noInitialQueryLayer = v.querySelector('[data-testid=no-initial-mq]');
53+
return layers.some((e) => e === noInitialQueryLayer);
54+
});
55+
expect(presentInLayerControl).toBe(false);
56+
});
57+
test(`A layer disabled due to mq would otherwise be enabled is \
58+
enabled and added to the layer control when mq removed`, async () =>{
59+
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
60+
await expect(noInitialQueryLayer).toHaveAttribute('media','(0 <= map-zoom <=3)');
61+
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
62+
await noInitialQueryLayer.evaluate((l) => l.removeAttribute('media'));
63+
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
64+
const presentInLayerControl = await viewer.evaluate((v) => {
65+
let lc = v._layerControl;
66+
let layers = lc._layers.map((e) => e.layer._layerEl);
67+
let noInitialQueryLayer = v.querySelector('[data-testid=no-initial-mq]');
68+
return layers.some((e) => e === noInitialQueryLayer);
69+
});
70+
expect(presentInLayerControl).toBe(true);
71+
72+
});
73+
test(`An empty media query is the same as no media query`, async () =>{
74+
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
75+
await noInitialQueryLayer.evaluate((l)=> l.setAttribute('media', ' '));
76+
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
77+
78+
});
79+
test(`An invalid media query is the same as a non-matching media query`, async () =>{
80+
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
81+
await noInitialQueryLayer.evaluate((l)=> l.setAttribute('media', '(foo '));
82+
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
83+
});
84+
});

0 commit comments

Comments
 (0)