-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16fc974
commit 55266ec
Showing
13 changed files
with
1,052 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@withease/web-api': minor | ||
--- | ||
|
||
Add `trackGeolocation` integration |
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,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>web-api demo</title> | ||
<base href="/" /> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="icon" type="image/x-icon" href="favicon.ico" /> | ||
</head> | ||
<body> | ||
<section> | ||
<h2>Geolocation</h2> | ||
|
||
<p>latitude: <span id="latitude" /></p> | ||
<p>longitude: <span id="longitude" /></p> | ||
|
||
<button id="get-location">Get Location</button> | ||
|
||
<button id="start-watching">Start Watching</button> | ||
<button id="stop-watching">Stop Watching</button> | ||
</section> | ||
<script type="module" src="/src/geolocation.ts"></script> | ||
</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
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,22 @@ | ||
import { trackGeolocation } from '@withease/web-api'; | ||
|
||
const latitudeElement = document.querySelector('#latitude')!; | ||
const longitudeElement = document.querySelector('#longitude')!; | ||
const getLocationButton = document.querySelector('#get-location')!; | ||
const startWatchingButton = document.querySelector('#start-watching')!; | ||
const stopWatchingButton = document.querySelector('#stop-watching')!; | ||
|
||
const { $latitude, $longitude, request, watching } = trackGeolocation({}); | ||
|
||
$latitude.watch((latitude) => { | ||
console.log('latitude', latitude); | ||
latitudeElement.textContent = JSON.stringify(latitude); | ||
}); | ||
$longitude.watch((longitude) => { | ||
console.log('longitude', longitude); | ||
longitudeElement.textContent = JSON.stringify(longitude); | ||
}); | ||
|
||
getLocationButton.addEventListener('click', () => request()); | ||
startWatchingButton.addEventListener('click', () => watching.start()); | ||
stopWatchingButton.addEventListener('click', () => watching.stop()); |
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,63 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
const GEOLOCATION_PAGE = '/geolocation.html'; | ||
|
||
test.use({ | ||
geolocation: { longitude: 41.890221, latitude: 12.492348 }, | ||
permissions: ['geolocation'], | ||
}); | ||
|
||
test('request', async ({ page, context }) => { | ||
await page.goto(GEOLOCATION_PAGE); | ||
|
||
const latitudeContainer = await page.$('#latitude'); | ||
const longitudeContainer = await page.$('#longitude'); | ||
const getLocationButton = await page.$('#get-location'); | ||
|
||
// By default it should be null | ||
expect(await latitudeContainer!.textContent()).toBe('null'); | ||
expect(await longitudeContainer!.textContent()).toBe('null'); | ||
|
||
// After requesting the location, it should be updated | ||
await getLocationButton!.click(); | ||
expect(await latitudeContainer!.textContent()).toBe('12.492348'); | ||
expect(await longitudeContainer!.textContent()).toBe('41.890221'); | ||
|
||
// Change geolocation, values should NOT be updated | ||
await context.setGeolocation({ longitude: 22.492348, latitude: 32.890221 }); | ||
expect(await latitudeContainer!.textContent()).toBe('12.492348'); | ||
expect(await longitudeContainer!.textContent()).toBe('41.890221'); | ||
// Request the location again, values should be updated | ||
await getLocationButton!.click(); | ||
expect(await latitudeContainer!.textContent()).toBe('32.890221'); | ||
expect(await longitudeContainer!.textContent()).toBe('22.492348'); | ||
}); | ||
|
||
test('watch', async ({ page, context }) => { | ||
await page.goto(GEOLOCATION_PAGE); | ||
|
||
const latitudeContainer = await page.$('#latitude'); | ||
const longitudeContainer = await page.$('#longitude'); | ||
const startWatchingButton = await page.$('#start-watching'); | ||
const stopWatchingButton = await page.$('#stop-watching'); | ||
|
||
// By default it should be null | ||
expect(await latitudeContainer!.textContent()).toBe('null'); | ||
expect(await longitudeContainer!.textContent()).toBe('null'); | ||
|
||
// After watching the location, it should be updated immediately | ||
await startWatchingButton!.click(); | ||
expect(await latitudeContainer!.textContent()).toBe('12.492348'); | ||
expect(await longitudeContainer!.textContent()).toBe('41.890221'); | ||
|
||
// Change geolocation, values should be updated immediately | ||
await context.setGeolocation({ longitude: 22.492348, latitude: 32.890221 }); | ||
expect(await latitudeContainer!.textContent()).toBe('32.890221'); | ||
expect(await longitudeContainer!.textContent()).toBe('22.492348'); | ||
|
||
// Stop watching and change geolocation, values should NOT be updated | ||
await stopWatchingButton!.click(); | ||
await context.setGeolocation({ longitude: 42.492348, latitude: 52.890221 }); | ||
expect(await latitudeContainer!.textContent()).toBe('32.890221'); | ||
expect(await longitudeContainer!.textContent()).toBe('22.492348'); | ||
}); |
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,19 @@ | ||
<script setup> | ||
import { trackGeolocation } from '@withease/web-api'; | ||
import { useUnit } from 'effector-vue/composition'; | ||
const geo = trackGeolocation(); | ||
const { latitude, longitude, request } = useUnit({ | ||
latitude: geo.$latitude, | ||
longitude: geo.$longitude, | ||
request: geo.request, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<p>latitude: {{ latitude }}</p> | ||
<p>longitude: {{ longitude }}</p> | ||
|
||
<button v-on:click="request">Request geolocation</button> | ||
</template> |
Oops, something went wrong.