Skip to content

Commit

Permalink
Merge pull request #70 from Stassi/feature/device-pixel-ratio-from-sc…
Browse files Browse the repository at this point in the history
…ale-factor

feature/device-pixel-ratio-from-scale-factor
  • Loading branch information
Stassi authored Oct 28, 2024
2 parents d936f02 + b31caf4 commit 90fd6bf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
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

0 comments on commit 90fd6bf

Please sign in to comment.