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

feature/generated-interactive-accessibility-tutorial #72

Merged
merged 10 commits into from
Oct 29, 2024
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stassi/leaf",
"version": "0.0.71",
"version": "0.0.72",
"description": "Leaflet adapter.",
"keywords": [
"cartography",
Expand Down Expand Up @@ -93,7 +93,7 @@
"jest-environment-puppeteer": "^10.1.4",
"jest-puppeteer": "^10.1.4",
"prettier": "3.3.3",
"puppeteer": "^23.6.0",
"puppeteer": "^23.6.1",
"rollup": "^4.24.2",
"rollup-plugin-modify": "^3.0.0",
"rollup-plugin-styles": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Leaflet</h1>
(<a href="https://leafletjs.com/examples/accessibility/" target="_blank">tutorial</a>)
<ol type="a">
<li>
<a href="tutorial/accessibility/interactive.html">Interactive</a>
<a href="tutorial/dist/accessibility-interactive.html">Interactive</a>
</li>
<li>
<a href="tutorial/accessibility/decorative.html">Decorative</a>
Expand Down
17 changes: 0 additions & 17 deletions public/tutorial/accessibility/interactive.html

This file was deleted.

25 changes: 0 additions & 25 deletions public/tutorial/accessibility/script/interactive.js

This file was deleted.

5 changes: 5 additions & 0 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ const aliasOptions: RollupAliasOptions = {
input: 'src/tutorial/custom-icons/custom-icons.ts',
title: 'Markers With Custom Icons',
},
{
fileName: 'accessibility-interactive.html',
input: 'src/tutorial/accessibility/interactive.ts',
title: 'Accessible maps: Interactive',
},
].map(
({
fileName,
Expand Down
96 changes: 59 additions & 37 deletions src/tutorial/accessibility/interactive.test.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,72 @@
import {
activeElementClassName,
expectImagesLoaded,
expectOpenStreetMapTilesLoaded,
pressEnter,
pressTab,
setBrowserConfiguration,
} from 'test-utilities'

describe('interactive accessibility tutorial', (): void => {
beforeAll(async (): Promise<void> => {
await page.goto('http://localhost:3001/tutorial/accessibility/interactive')
})

describe('map', (): void => {
// eslint-disable-next-line jest/prefer-lowercase-title -- official case
describe('OpenStreetMap tiles', (): void => {
/* eslint-disable-next-line jest/expect-expect --
describe.each([1, 2])(
'device scale factor: %d',
(deviceScaleFactor: number): void => {
beforeAll(
setBrowserConfiguration({
deviceScaleFactor,
url: 'http://localhost:3001/tutorial/dist/accessibility-interactive',
}),
)

describe('map', (): void => {
// eslint-disable-next-line jest/prefer-lowercase-title -- official case
describe('OpenStreetMap tiles', (): void => {
/* eslint-disable-next-line jest/expect-expect --
`expectOpenStreetMapTilesLoaded` returns assertions */
it('should load', expectOpenStreetMapTilesLoaded())
})

describe('marker', (): void => {
describe('on focus', (): void => {
describe('on `Enter`-press', (): void => {
it('should display popup text "Kyiv, Ukraine is the birthplace of Leaflet!"', async (): Promise<void> => {
let markerFocused = false

while (!markerFocused) {
await pressTab()

if (
(await activeElementClassName()).includes('leaflet-marker-icon')
) {
markerFocused = true
}
}

await pressEnter()

expect(
await page.$eval(
'.leaflet-popup-content',
({ textContent }: Element): string | null => textContent,
),
).toBe('Kyiv, Ukraine is the birthplace of Leaflet!')
it('should load', expectOpenStreetMapTilesLoaded())
})

describe('marker', (): void => {
describe('images', (): void => {
describe.each([
`../../../leaflet/images/marker-icon${deviceScaleFactor === 2 ? '-2x' : ''}.png`,
'../../../leaflet/images/marker-shadow.png',
])('src="%s"', (src: string): void => {
/* eslint-disable-next-line jest/expect-expect --
`expectImagesLoaded` returns assertions */
it('should load', expectImagesLoaded(src))
})
})

describe('on focus', (): void => {
describe('on `Enter`-press', (): void => {
it('should display popup text "Kyiv, Ukraine is the birthplace of Leaflet!"', async (): Promise<void> => {
let markerFocused = false

while (!markerFocused) {
await pressTab()

if (
(await activeElementClassName()).includes(
'leaflet-marker-icon',
)
)
markerFocused = true
}

await pressEnter()

expect(
await page.$eval(
'.leaflet-popup-content',
({ textContent }: Element): string | null => textContent,
),
).toBe('Kyiv, Ukraine is the birthplace of Leaflet!')
})
})
})
})
})
})
})
},
)
})
35 changes: 35 additions & 0 deletions src/tutorial/accessibility/interactive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'leaflet/dist/leaflet.css'
import '../style/theme.css'
import '../style/medium.css'

import { type Map } from '@stassi/leaf'

const altText = 'Kyiv',
map: Map = await (
await import('../../leaf/map/map.js')
).map({
center: [50.4501, 30.5234],
id: 'map',
zoom: 4,
})

await (
await import('../../leaf/marker.js')
).marker({
altText,
iconOptions: {
iconUrl: '../../../leaflet/images/marker-icon.png',
iconUrlRetina: '../../../leaflet/images/marker-icon-2x.png',
shadowUrl: '../../../leaflet/images/marker-shadow.png',
},
latitudeLongitude: [50.4501, 30.5234],
map,
popupContent: `${altText}, Ukraine is the birthplace of Leaflet!`,
})

await (
await import('../../leaf/tile-layer/tile-layer-osm.js')
).tileLayerOsm({
map,
zoomMax: 19,
})