Skip to content

Commit 3e7a714

Browse files
committed
Add preferred-content tests for multiple content preferences
1 parent 7037525 commit 3e7a714

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

test/e2e/basics/preferred-content.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@
55
<meta name="viewport" content="width=device-width,initial-scale=1">
66
<title>Preferred Content Test</title>
77
<script type="module" src="../../../src/dist/mapml.js"></script>
8+
<script>
9+
document.addEventListener('DOMContentLoaded',(e)=>{
10+
let l, map = document.querySelector('mapml-viewer'),
11+
prefersEverything = map.matchMedia('(prefers-map-content: image) and (prefers-map-content: tile) and (prefers-map-content: feature) and (prefers-map-content: table)').matches === 'true',
12+
t = document.querySelector('template'),
13+
prefersFeaturesOnly = map.matchMedia('(prefers-map-content: feature) and ( not ((prefers-map-content: image) or (prefers-map-content: tile)))').matches === 'true',
14+
prefersTiles = map.matchMedia('(prefers-map-content: tile');
15+
if (prefersFeaturesOnly) {
16+
l = t.content.querySelector('#features').cloneNode(true);
17+
} else if (prefersImages) {
18+
l = t.content.querySelector('#wms').cloneNode(true);
19+
} else if (prefersTiles) {
20+
l = t.content.querySelector('#tiles').cloneNode(true);
21+
}
22+
map.appendChild(l);
23+
});
24+
</script>
825
</head>
926
<body>
10-
<mapml-viewer style="height: 500px;width:500px;" projection="CBMTILE" zoom="8" lat="46.51231982020816" lon="-63.25669692277839" controls>
27+
<mapml-viewer data-testid="viewer" style="height: 500px;width:500px;" projection="CBMTILE" zoom="8" lat="46.51231982020816" lon="-63.25669692277839" controls>
1128
<map-layer data-testid="test-layer" label="Provinces and Territories" src="../data/cbmt-cbmtile.mapml" checked></map-layer>
1229
</mapml-viewer>
1330
</body>

test/e2e/basics/preferred-content.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test.describe("Preferred content test", () => {
3434
test("User prefers feature content type", async () => {
3535
// "page" is the extension popup, hasn't been closed so still open in a
3636
// browser tab somewhere...
37+
await page.bringToFront();
3738
await page.keyboard.press("Tab");
3839
await page.keyboard.press("Tab");
3940
await page.keyboard.press("Tab");
@@ -55,5 +56,56 @@ test.describe("Preferred content test", () => {
5556
const label = await layer.evaluate((l) => l._layerControlLabel.textContent);
5657
expect(label).toEqual('Feature content');
5758
});
59+
60+
test("Multiple preferences can be expressed by user", async () => {
61+
await page.bringToFront();
62+
await page.keyboard.press("Tab");
63+
await page.keyboard.press("Tab");
64+
await page.keyboard.press("Tab");
65+
await page.keyboard.press("Tab");
66+
await page.keyboard.press("Tab");
67+
await page.keyboard.press("Tab");
68+
await page.keyboard.press("Tab");
69+
await page.keyboard.press("Tab");
70+
// features is currently selected, so need a tricky set of key presses
71+
await page.keyboard.press("ArrowUp");
72+
await page.keyboard.press("ArrowUp");
73+
await page.keyboard.press("Shift+ArrowDown");
74+
await page.keyboard.press("Shift+ArrowDown");
75+
await page.keyboard.press("Shift+ArrowDown");
76+
let newPage = await context.newPage();
77+
await newPage.goto("test/e2e/basics/preferred-content.html", { waitUntil: "domcontentloaded" });
78+
await newPage.waitForTimeout(1000);
79+
let map = newPage.getByTestId('viewer');
80+
const matches = await map.evaluate((map)=>{
81+
return map.matchMedia('(prefers-map-content: image) and (prefers-map-content: tile) and (prefers-map-content: feature) and (prefers-map-content: table)').matches;
82+
});
83+
expect(matches).toBe(true);
84+
});
85+
test("Multiple disjoint preferences can be expressed by user", async () => {
86+
await page.bringToFront();
87+
await page.keyboard.press("Tab");
88+
await page.keyboard.press("Tab");
89+
await page.keyboard.press("Tab");
90+
await page.keyboard.press("Tab");
91+
await page.keyboard.press("Tab");
92+
await page.keyboard.press("Tab");
93+
await page.keyboard.press("Tab");
94+
await page.keyboard.press("Tab");
95+
await page.keyboard.press("ArrowUp");
96+
await page.keyboard.press("ArrowUp");
97+
await page.keyboard.press(" "); // select tiles option
98+
await page.keyboard.press("Control+ArrowDown");
99+
await page.keyboard.press("Control+ArrowDown");
100+
await page.keyboard.press(" "); // select tables option
101+
let newPage = await context.newPage();
102+
await newPage.goto("test/e2e/basics/preferred-content.html", { waitUntil: "domcontentloaded" });
103+
await newPage.waitForTimeout(1000);
104+
let map = newPage.getByTestId('viewer');
105+
const matches = await map.evaluate((map)=>{
106+
return map.matchMedia('(not (prefers-map-content: image)) and (prefers-map-content: tile) and (not (prefers-map-content: feature)) and (prefers-map-content: table)').matches;
107+
});
108+
expect(matches).toBe(true);
109+
});
58110

59111
});

0 commit comments

Comments
 (0)