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/device-pixel-ratio-from-scale-factor #70

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 11 additions & 11 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stassi/leaf",
"version": "0.0.69",
"version": "0.0.70",
"description": "Leaflet adapter.",
"keywords": [
"cartography",
Expand Down
20 changes: 20 additions & 0 deletions src/test-utilities/browser-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function setBrowserConfiguration({
deviceScaleFactor = 1,
url,
}: {
url: string
} & Partial<{
deviceScaleFactor: number
}>): () => Promise<void> {
return async (): Promise<void> => {
await page.evaluateOnNewDocument((devicePixelRatio: number): void => {
Object.defineProperty(window, 'devicePixelRatio', {
get: (): number => devicePixelRatio,
})
}, deviceScaleFactor)

await page.setViewport({ deviceScaleFactor, height: 600, width: 800 })

await page.goto(url)
}
}
11 changes: 7 additions & 4 deletions src/tutorial/custom-icons/custom-icons.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { expectImagesLoaded } from 'test-utilities/expect/loaded/images.js'
import { expectOpenStreetMapTilesLoaded } from 'test-utilities/expect/loaded/open-street-map-tiles.js'
import { setBrowserConfiguration } from 'test-utilities/browser-configuration.js'

describe('custom icons tutorial', (): void => {
describe.each([1, 2])(
'device scale factor: %d',
(deviceScaleFactor: number): void => {
beforeAll(async (): Promise<void> => {
await page.setViewport({ deviceScaleFactor, height: 600, width: 800 })
await page.goto('http://localhost:3001/tutorial/dist/custom-icons')
})
beforeAll(
setBrowserConfiguration({
deviceScaleFactor,
url: 'http://localhost:3001/tutorial/dist/custom-icons',
}),
)

describe('map', (): void => {
// eslint-disable-next-line jest/prefer-lowercase-title -- official case
Expand Down
11 changes: 7 additions & 4 deletions src/tutorial/quick-start/quick-start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { type BoundingBox } from 'puppeteer'

import { expectImagesLoaded } from 'test-utilities/expect/loaded/images.js'
import { expectOpenStreetMapTilesLoaded } from 'test-utilities/expect/loaded/open-street-map-tiles.js'
import { setBrowserConfiguration } from 'test-utilities/browser-configuration.js'

describe('quick start tutorial', (): void => {
describe.each([1, 2])(
'device scale factor: %d',
(deviceScaleFactor: number): void => {
beforeAll(async (): Promise<void> => {
await page.setViewport({ deviceScaleFactor, height: 600, width: 800 })
await page.goto('http://localhost:3001/tutorial/dist/quick-start')
})
beforeAll(
setBrowserConfiguration({
deviceScaleFactor,
url: 'http://localhost:3001/tutorial/dist/quick-start',
}),
)

describe('map', (): void => {
describe('on initial page load', (): void => {
Expand Down