-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added map-change event for extents (#1005)
* added map-change event for extents, added test cases for map-change events * Added timeout * Changed to headed mode, added different methods of changing checking/unchecking * Cleaned up some parts * Modified logic so that map-change is only called when layer/extent is checked/unchecked on the layer menu * Edited comments, removed timeout * Added test for checking/unchecking with keyboard
- Loading branch information
Showing
5 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>map-change event</title> | ||
<!-- the layer in this map should continue to be visible when you change | ||
the viewer projection from OSMTILE to CBMTILE. --> | ||
<script type="module" src="/mapml.js"></script> | ||
<style> | ||
mapml-viewer { | ||
width: 100%; | ||
height: 100vh | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<mapml-viewer projection="OSMTILE" zoom="14" lat="45.406314" lon="-75.6883335" controls="" | ||
controlslist="geolocation"> | ||
<map-layer label="OpenStreetMap" checked=""> | ||
<map-link rel="license" title="© OpenStreetMap contributors CC BY-SA" | ||
href="https://www.openstreetmap.org/copyright"></map-link> | ||
<map-extent units="OSMTILE" checked="checked"> | ||
<map-input name="z" type="zoom" value="18" min="0" max="18"></map-input> | ||
<map-input name="x" type="location" units="tilematrix" axis="column" min="0" max="262144"></map-input> | ||
<map-input name="y" type="location" units="tilematrix" axis="row" min="0" max="262144"></map-input> | ||
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link> | ||
</map-extent> | ||
</map-layer> | ||
</mapml-viewer> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { test, expect, chromium } from '@playwright/test'; | ||
|
||
test.describe('Map-change event are only fired when layers/extents are checked or unchecked in the layer menu ', () => { | ||
let page; | ||
let context; | ||
test.beforeAll(async () => { | ||
context = await chromium.launchPersistentContext('', { | ||
headless: false, | ||
slowMo: 250 | ||
}); | ||
page = | ||
context.pages().find((page) => page.url() === 'about:blank') || | ||
(await context.newPage()); | ||
await page.goto('events/map-change-event.html'); | ||
}); | ||
|
||
test.afterAll(async function () { | ||
await context.close(); | ||
}); | ||
|
||
test('Map-change event for layers work', async () => { | ||
let layerClicked = 0; | ||
page.on('console', (msg) => { | ||
if (msg.text() === 'Layer clicked') { | ||
layerClicked++; | ||
} | ||
}); | ||
|
||
// check and uncheck layers in the DOM shouldn't call map-change | ||
await page.evaluate(() => { | ||
const layer = document.querySelector('map-layer'); | ||
layer.addEventListener('map-change', () => { | ||
console.log('Layer clicked'); | ||
}); | ||
layer.checked = false; | ||
layer.checked = true; | ||
}); | ||
expect(layerClicked).toBe(0); | ||
|
||
// check and uncheck layers using removeAttribute and setAttribute | ||
// shouldn't call map-change | ||
await page.evaluate(() => { | ||
const layer = document.querySelector('map-layer'); | ||
layer.removeAttribute('checked'); | ||
layer.setAttribute('checked', ''); | ||
}); | ||
expect(layerClicked).toBe(0); | ||
|
||
// check and uncheck layers in the layer menu should call map-change | ||
await page.hover('.leaflet-top.leaflet-right'); | ||
const button = await page.locator('.leaflet-control-layers-selector'); | ||
await button.click(); | ||
await button.click(); | ||
|
||
expect(layerClicked).toBe(2); | ||
|
||
// using keyboard to check and uncheck layers in the layer menu should | ||
// call map-change | ||
await page.locator('mapml-viewer').click(); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Enter'); | ||
await page.keyboard.press('Space'); | ||
await page.keyboard.press('Space'); | ||
|
||
expect(layerClicked).toBe(4); | ||
}); | ||
|
||
test('Map-change event for sub-layers work', async () => { | ||
let extentClicked = 0; | ||
page.on('console', (msg) => { | ||
if (msg.text() === 'Sub-layer clicked') { | ||
extentClicked++; | ||
} | ||
}); | ||
|
||
// check and uncheck extents in the DOM shouldn't call map-change | ||
await page.evaluate(() => { | ||
const extent = document.querySelector('map-extent'); | ||
extent.addEventListener('map-change', () => { | ||
console.log('Sub-layer clicked'); | ||
}); | ||
extent.checked = false; | ||
extent.checked = true; | ||
}); | ||
expect(extentClicked).toBe(0); | ||
|
||
// check and uncheck extents using removeAttribute and setAttribute | ||
// shouldn't call map-change | ||
await page.evaluate(() => { | ||
const extent = document.querySelector('map-extent'); | ||
extent.removeAttribute('checked'); | ||
extent.setAttribute('checked', ''); | ||
}); | ||
expect(extentClicked).toBe(0); | ||
|
||
// check and uncheck extents in the layer menu should call map-change | ||
const layerSettings = await page.locator( | ||
'.mapml-layer-item-settings-control' | ||
); | ||
await page.hover('.leaflet-top.leaflet-right'); | ||
await layerSettings.first().click(); | ||
const extentControls = await page.locator('.mapml-layer-extent'); | ||
const button = await extentControls.locator('.mapml-layer-item-toggle'); | ||
await button.click(); | ||
await button.click(); | ||
|
||
expect(extentClicked).toBe(2); | ||
|
||
// using keyboard to check and uncheck extents in the layer menu should | ||
// call map-change | ||
await page.locator('mapml-viewer').click(); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Enter'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Space'); | ||
await page.keyboard.press('Space'); | ||
|
||
expect(extentClicked).toBe(4); | ||
}); | ||
}); |