Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-focus after a layer in checked/unchecked in the layer menu, added tests #1009

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export var createLayerControlHTML = async function () {
layerItemName.layer = this._layer;
const changeCheck = function () {
this.checked = !this.checked;
this._layerControlCheckbox.focus();
};
input.addEventListener('change', changeCheck.bind(this));
if (this._layer._legendUrl) {
Expand Down
38 changes: 38 additions & 0 deletions test/e2e/core/kbdFocusLayerMenu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>Keyboard Focus Layer Menu test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module" src="mapml.js"></script>
<style>
html, body {
width: 100%;
height: 100%
}

mapml-viewer {
width: 100%;
height: 100%;
}
</style>
</head>

<body>
<mapml-viewer projection="OSMTILE" zoom="14" lat="45.406314" lon="-75.6883335" controls=""
controlslist="geolocation">
<map-layer data-testid="osm-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>
75 changes: 75 additions & 0 deletions test/e2e/core/kbdFocusLayerMenu.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { test, expect, chromium } from '@playwright/test';

test.describe('Focus stays on checkboxes when using keyboard navigation', () => {
yushan-mu marked this conversation as resolved.
Show resolved Hide resolved
let page;
let context;
test.beforeAll(async () => {
context = await chromium.launchPersistentContext('', {
slowMo: 250
});
page =
context.pages().find((page) => page.url() === 'about:blank') ||
(await context.newPage());
page = await context.newPage();
await page.goto('kbdFocusLayerMenu.html');
});

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

test('Focus stays on checkbox after checking and unchecking layers in the layer menu', async () => {
const layer = await page.locator('map-layer');
let layerChecked = await layer.getAttribute('checked');
expect(layerChecked).not.toBeNull();

// use keyboard to uncheck layer
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');

// layer should be unchecked
layerChecked = await layer.getAttribute('checked');
expect(layerChecked).toBeNull();

// pressing space again should check the layer
await page.keyboard.press('Space');
layerChecked = await layer.getAttribute('checked');
expect(layerChecked).not.toBeNull();
});

test('Focus stays on checkbox after checking and unchecking extents in the layer menu', async () => {
const extent = await page.locator('map-extent');
let extentChecked = await extent.getAttribute('checked');
expect(extentChecked).not.toBeNull();

// use keyboard to uncheck map-extent
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('Enter');
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.keyboard.press('Space');

// extent should be unchecked
extentChecked = await extent.getAttribute('checked');
expect(extentChecked).toBeNull();

// pressing space again should check the extent
await page.keyboard.press('Space');
extentChecked = await extent.getAttribute('checked');
expect(extentChecked).not.toBeNull();
});
});