Skip to content

Commit

Permalink
Add tests for <map-layer media="..."> attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
prushforth committed Dec 19, 2024
1 parent 7eb1f65 commit af3aed6
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions test/e2e/elements/map-layer/map-layer-media.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { test, expect, chromium } from '@playwright/test';

test.describe('map-layer media attribute', () => {
let page;
let context;
let viewer;
test.beforeAll(async function () {
context = await chromium.launchPersistentContext('');
page =
context.pages().find((page) => page.url() === 'about:blank') ||
(await context.newPage());
await page.goto('map-layer-media.html');
await page.waitForTimeout(1000);
viewer = page.getByTestId('viewer');
});
test('On initial load, a matching media queried layer is enabled', async ()=>{
const matchedQueryLayer = page.getByTestId('initial-mq');
// map loads at z=2, query matches 0 <= z <= 3
await expect(matchedQueryLayer).not.toHaveAttribute('disabled', '');
});
test(`A visible (enabled) map-layer with no media query should remain enabled \
when a matching mq is added`, async ()=> {
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
await viewer.evaluate((v) => v.zoomTo(v.lat,v.lon,4));
await page.waitForTimeout(200);
// should still be enabled:
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
});
test(`A visible (enabled) map-layer with no media query should be disabled \
when a non-matching media query attribute is set`, async ()=> {
await expect(viewer).toHaveAttribute('zoom','4');
const presentInLayerControl = await viewer.evaluate((v) => {
let lc = v._layerControl;
let layers = lc._layers.map((e) => e.layer._layerEl);
let noInitialQueryLayer = v.querySelector('[data-testid=no-initial-mq]');
return layers.some((e) => e === noInitialQueryLayer);
});
expect(presentInLayerControl).toBe(true);
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
await noInitialQueryLayer.evaluate((l) => l.media = '(0 <= map-zoom <=3)');
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
});
test(`A mq-disabled layer is removed from the layer control`,async ()=>{
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
await expect(noInitialQueryLayer).toHaveAttribute('media','(0 <= map-zoom <=3)');
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
const presentInLayerControl = await viewer.evaluate((v) => {
let lc = v._layerControl;
let layers = lc._layers.map((e) => e.layer._layerEl);
let noInitialQueryLayer = v.querySelector('[data-testid=no-initial-mq]');
return layers.some((e) => e === noInitialQueryLayer);
});
expect(presentInLayerControl).toBe(false);
});
test(`A layer disabled due to mq would otherwise be enabled is \
enabled and added to the layer control when mq removed`, async () =>{
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
await expect(noInitialQueryLayer).toHaveAttribute('media','(0 <= map-zoom <=3)');
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
await noInitialQueryLayer.evaluate((l) => l.removeAttribute('media'));
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');
const presentInLayerControl = await viewer.evaluate((v) => {
let lc = v._layerControl;
let layers = lc._layers.map((e) => e.layer._layerEl);
let noInitialQueryLayer = v.querySelector('[data-testid=no-initial-mq]');
return layers.some((e) => e === noInitialQueryLayer);
});
expect(presentInLayerControl).toBe(true);

});
test(`An empty media query is the same as no media query`, async () =>{
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
await noInitialQueryLayer.evaluate((l)=> l.setAttribute('media', ' '));
await expect(noInitialQueryLayer).not.toHaveAttribute('disabled','');

});
test(`An invalid media query is the same as a non-matching media query`, async () =>{
const noInitialQueryLayer = page.getByTestId('no-initial-mq');
await noInitialQueryLayer.evaluate((l)=> l.setAttribute('media', '(foo '));
await expect(noInitialQueryLayer).toHaveAttribute('disabled','');
});
});

0 comments on commit af3aed6

Please sign in to comment.