Skip to content

Commit 357b403

Browse files
committed
Fix tests
1 parent ed8ca15 commit 357b403

File tree

2 files changed

+90
-105
lines changed

2 files changed

+90
-105
lines changed

src/mapml/handlers/AnnounceMovement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export var AnnounceMovement = L.Handler.extend({
9191

9292
}
9393
else{
94-
let prevZoom = this._history[this._historyIndex - 1].zoom;
94+
let prevZoom = this._history[this._historyIndex - 1] ? this._history[this._historyIndex - 1].zoom : this._history[this._historyIndex].zoom;
9595
if(mapZoom === this._map._layersMaxZoom && mapZoom !== prevZoom){
9696
output.innerText = "At maximum zoom level, zoom in disabled " + standard;
9797
}
Lines changed: 89 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,90 @@
1-
const playwright = require("playwright");
2-
jest.setTimeout(50000);
3-
(async () => {
4-
for (const browserType of BROWSER) {
5-
describe(
6-
"Announce movement test " + browserType,
7-
()=> {
8-
beforeAll(async () => {
9-
browser = await playwright[browserType].launch({
10-
headless: ISHEADLESS,
11-
slowMo: 100,
12-
});
13-
context = await browser.newContext();
14-
page = await context.newPage();
15-
if (browserType === "firefox") {
16-
await page.waitForNavigation();
17-
}
18-
await page.goto(PATH + "mapml-viewer.html");
19-
});
20-
afterAll(async function () {
21-
await browser.close();
22-
});
23-
24-
test("[" + browserType + "]" + " Output values are correct during regular movement", async ()=>{
25-
await page.keyboard.press("Tab");
26-
await page.keyboard.press("ArrowUp");
27-
await page.waitForTimeout(100);
28-
29-
const movedUp = await page.$eval(
30-
"body > mapml-viewer div > output",
31-
(output) => output.innerHTML
32-
);
33-
expect(movedUp).toEqual("zoom level 0 column 3 row 3");
34-
35-
for(let i = 0; i < 2; i++){
36-
await page.keyboard.press("ArrowLeft");
37-
await page.waitForTimeout(100);
38-
}
39-
40-
const movedLeft = await page.$eval(
41-
"body > mapml-viewer div > output",
42-
(output) => output.innerHTML
43-
);
44-
expect(movedLeft).toEqual("zoom level 0 column 2 row 3");
45-
46-
await page.keyboard.press("Equal");
47-
await page.waitForTimeout(100);
48-
49-
const zoomedIn = await page.$eval(
50-
"body > mapml-viewer div > output",
51-
(output) => output.innerHTML
52-
);
53-
expect(zoomedIn).toEqual("zoom level 1 column 4 row 6");
54-
});
55-
56-
test("[" + browserType + "]" + " Output values are correct at bounds and bounces back", async ()=>{
57-
//Zoom out to min layer bound
58-
await page.keyboard.press("Minus");
59-
await page.waitForTimeout(100);
60-
61-
const minZoom = await page.$eval(
62-
"body > mapml-viewer div > output",
63-
(output) => output.innerHTML
64-
);
65-
expect(minZoom).toEqual("At minimum zoom level, zoom out disabled zoom level 0 column 2 row 3");
66-
67-
//Pan out of west bounds, expect the map to bounce back
68-
for(let i = 0; i < 4; i++){
69-
await page.waitForTimeout(100);
70-
await page.keyboard.press("ArrowLeft");
71-
}
72-
73-
const westBound = await page.waitForFunction(() =>
74-
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Reached west bound, panning west disabled",
75-
{}, {timeout: 1000}
76-
);
77-
expect(await westBound.jsonValue()).toEqual(true);
78-
79-
const bouncedBack = await page.$eval(
80-
"body > mapml-viewer div > output",
81-
(output) => output.innerHTML
82-
);
83-
expect(bouncedBack).toEqual("zoom level 0 column 1 row 3");
84-
85-
//Zoom in out of bounds, expect the map to zoom back
86-
await page.keyboard.press("Equal");
87-
88-
const zoomedOutOfBounds = await page.waitForFunction(() =>
89-
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Zoomed out of bounds, returning to",
90-
{}, {timeout: 1000}
91-
);
92-
expect(await zoomedOutOfBounds.jsonValue()).toEqual(true);
93-
94-
const zoomedBack = await page.$eval(
95-
"body > mapml-viewer div > output",
96-
(output) => output.innerHTML
97-
);
98-
expect(zoomedBack).toEqual("zoom level 0 column 1 row 3");
99-
100-
});
101-
102-
}
1+
describe("Announce movement test", ()=> {
2+
beforeAll(async () => {
3+
await page.goto(PATH + "mapml-viewer.html");
4+
});
5+
6+
afterAll(async function () {
7+
await context.close();
8+
});
9+
10+
test("Output values are correct during regular movement", async ()=>{
11+
await page.keyboard.press("Tab");
12+
await page.waitForTimeout(500);
13+
await page.keyboard.press("ArrowUp");
14+
await page.waitForTimeout(1000);
15+
16+
const movedUp = await page.$eval(
17+
"body > mapml-viewer div > output",
18+
(output) => output.innerHTML
10319
);
104-
}
105-
})();
20+
expect(movedUp).toEqual("zoom level 0 column 3 row 3");
21+
22+
for(let i = 0; i < 2; i++){
23+
await page.keyboard.press("ArrowLeft");
24+
await page.waitForTimeout(1000);
25+
}
26+
27+
const movedLeft = await page.$eval(
28+
"body > mapml-viewer div > output",
29+
(output) => output.innerHTML
30+
);
31+
expect(movedLeft).toEqual("zoom level 0 column 2 row 3");
32+
33+
await page.keyboard.press("Equal");
34+
await page.waitForTimeout(1000);
35+
36+
const zoomedIn = await page.$eval(
37+
"body > mapml-viewer div > output",
38+
(output) => output.innerHTML
39+
);
40+
expect(zoomedIn).toEqual("zoom level 1 column 4 row 6");
41+
});
42+
43+
test("Output values are correct at bounds and bounces back", async ()=>{
44+
//Zoom out to min layer bound
45+
await page.keyboard.press("Minus");
46+
await page.waitForTimeout(1000);
47+
48+
const minZoom = await page.$eval(
49+
"body > mapml-viewer div > output",
50+
(output) => output.innerHTML
51+
);
52+
expect(minZoom).toEqual("At minimum zoom level, zoom out disabled zoom level 0 column 2 row 3");
53+
54+
//Pan out of west bounds, expect the map to bounce back
55+
for(let i = 0; i < 4; i++){
56+
await page.waitForTimeout(1000);
57+
await page.keyboard.press("ArrowLeft");
58+
}
59+
60+
const westBound = await page.waitForFunction(() =>
61+
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Reached west bound, panning west disabled",
62+
{}, {timeout: 1000}
63+
);
64+
expect(await westBound.jsonValue()).toEqual(true);
65+
66+
await page.waitForTimeout(1000);
67+
const bouncedBack = await page.$eval(
68+
"body > mapml-viewer div > output",
69+
(output) => output.innerHTML
70+
);
71+
expect(bouncedBack).toEqual("zoom level 0 column 1 row 3");
72+
73+
//Zoom in out of bounds, expect the map to zoom back
74+
await page.keyboard.press("Equal");
75+
76+
const zoomedOutOfBounds = await page.waitForFunction(() =>
77+
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Zoomed out of bounds, returning to",
78+
{}, {timeout: 1000}
79+
);
80+
expect(await zoomedOutOfBounds.jsonValue()).toEqual(true);
81+
82+
await page.waitForTimeout(1000);
83+
const zoomedBack = await page.$eval(
84+
"body > mapml-viewer div > output",
85+
(output) => output.innerHTML
86+
);
87+
expect(zoomedBack).toEqual("zoom level 0 column 1 row 3");
88+
89+
});
90+
});

0 commit comments

Comments
 (0)