Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-lu-uw committed Nov 18, 2021
1 parent ed8ca15 commit 357b403
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/mapml/handlers/AnnounceMovement.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export var AnnounceMovement = L.Handler.extend({

}
else{
let prevZoom = this._history[this._historyIndex - 1].zoom;
let prevZoom = this._history[this._historyIndex - 1] ? this._history[this._historyIndex - 1].zoom : this._history[this._historyIndex].zoom;
if(mapZoom === this._map._layersMaxZoom && mapZoom !== prevZoom){
output.innerText = "At maximum zoom level, zoom in disabled " + standard;
}
Expand Down
193 changes: 89 additions & 104 deletions test/e2e/core/announceMovement.test.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,90 @@
const playwright = require("playwright");
jest.setTimeout(50000);
(async () => {
for (const browserType of BROWSER) {
describe(
"Announce movement test " + browserType,
()=> {
beforeAll(async () => {
browser = await playwright[browserType].launch({
headless: ISHEADLESS,
slowMo: 100,
});
context = await browser.newContext();
page = await context.newPage();
if (browserType === "firefox") {
await page.waitForNavigation();
}
await page.goto(PATH + "mapml-viewer.html");
});
afterAll(async function () {
await browser.close();
});

test("[" + browserType + "]" + " Output values are correct during regular movement", async ()=>{
await page.keyboard.press("Tab");
await page.keyboard.press("ArrowUp");
await page.waitForTimeout(100);

const movedUp = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(movedUp).toEqual("zoom level 0 column 3 row 3");

for(let i = 0; i < 2; i++){
await page.keyboard.press("ArrowLeft");
await page.waitForTimeout(100);
}

const movedLeft = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(movedLeft).toEqual("zoom level 0 column 2 row 3");

await page.keyboard.press("Equal");
await page.waitForTimeout(100);

const zoomedIn = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(zoomedIn).toEqual("zoom level 1 column 4 row 6");
});

test("[" + browserType + "]" + " Output values are correct at bounds and bounces back", async ()=>{
//Zoom out to min layer bound
await page.keyboard.press("Minus");
await page.waitForTimeout(100);

const minZoom = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(minZoom).toEqual("At minimum zoom level, zoom out disabled zoom level 0 column 2 row 3");

//Pan out of west bounds, expect the map to bounce back
for(let i = 0; i < 4; i++){
await page.waitForTimeout(100);
await page.keyboard.press("ArrowLeft");
}

const westBound = await page.waitForFunction(() =>
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Reached west bound, panning west disabled",
{}, {timeout: 1000}
);
expect(await westBound.jsonValue()).toEqual(true);

const bouncedBack = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(bouncedBack).toEqual("zoom level 0 column 1 row 3");

//Zoom in out of bounds, expect the map to zoom back
await page.keyboard.press("Equal");

const zoomedOutOfBounds = await page.waitForFunction(() =>
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Zoomed out of bounds, returning to",
{}, {timeout: 1000}
);
expect(await zoomedOutOfBounds.jsonValue()).toEqual(true);

const zoomedBack = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(zoomedBack).toEqual("zoom level 0 column 1 row 3");

});

}
describe("Announce movement test", ()=> {
beforeAll(async () => {
await page.goto(PATH + "mapml-viewer.html");
});

afterAll(async function () {
await context.close();
});

test("Output values are correct during regular movement", async ()=>{
await page.keyboard.press("Tab");
await page.waitForTimeout(500);
await page.keyboard.press("ArrowUp");
await page.waitForTimeout(1000);

const movedUp = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
}
})();
expect(movedUp).toEqual("zoom level 0 column 3 row 3");

for(let i = 0; i < 2; i++){
await page.keyboard.press("ArrowLeft");
await page.waitForTimeout(1000);
}

const movedLeft = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(movedLeft).toEqual("zoom level 0 column 2 row 3");

await page.keyboard.press("Equal");
await page.waitForTimeout(1000);

const zoomedIn = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(zoomedIn).toEqual("zoom level 1 column 4 row 6");
});

test("Output values are correct at bounds and bounces back", async ()=>{
//Zoom out to min layer bound
await page.keyboard.press("Minus");
await page.waitForTimeout(1000);

const minZoom = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(minZoom).toEqual("At minimum zoom level, zoom out disabled zoom level 0 column 2 row 3");

//Pan out of west bounds, expect the map to bounce back
for(let i = 0; i < 4; i++){
await page.waitForTimeout(1000);
await page.keyboard.press("ArrowLeft");
}

const westBound = await page.waitForFunction(() =>
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Reached west bound, panning west disabled",
{}, {timeout: 1000}
);
expect(await westBound.jsonValue()).toEqual(true);

await page.waitForTimeout(1000);
const bouncedBack = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(bouncedBack).toEqual("zoom level 0 column 1 row 3");

//Zoom in out of bounds, expect the map to zoom back
await page.keyboard.press("Equal");

const zoomedOutOfBounds = await page.waitForFunction(() =>
document.querySelector("body > mapml-viewer").shadowRoot.querySelector("div > output").innerHTML === "Zoomed out of bounds, returning to",
{}, {timeout: 1000}
);
expect(await zoomedOutOfBounds.jsonValue()).toEqual(true);

await page.waitForTimeout(1000);
const zoomedBack = await page.$eval(
"body > mapml-viewer div > output",
(output) => output.innerHTML
);
expect(zoomedBack).toEqual("zoom level 0 column 1 row 3");

});
});

0 comments on commit 357b403

Please sign in to comment.