86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import { apiPathPattern, mockApi, seedAuthenticatedState } from "./support/network.js";
|
|
|
|
const adminPermissions = ["admin", "department_access_1", "department_access_2"];
|
|
|
|
const json = (body: unknown, status = 200) => ({
|
|
status,
|
|
contentType: "application/json",
|
|
body: JSON.stringify(body),
|
|
});
|
|
|
|
test("mobile redirect waits for delayed departments before selecting nearest POS department", async ({
|
|
context,
|
|
page,
|
|
}, testInfo) => {
|
|
test.skip(!/mobile/i.test(testInfo.project.name), "Mobile redirect regression");
|
|
|
|
await context.grantPermissions(["geolocation"]);
|
|
await context.setGeolocation({
|
|
latitude: 55.6761,
|
|
longitude: 12.5683,
|
|
});
|
|
await page.addInitScript(() => {
|
|
const location = {
|
|
coords: {
|
|
latitude: 55.6761,
|
|
longitude: 12.5683,
|
|
accuracy: 1,
|
|
altitude: null,
|
|
altitudeAccuracy: null,
|
|
heading: null,
|
|
speed: null,
|
|
},
|
|
timestamp: Date.now(),
|
|
};
|
|
const notify = (success: PositionCallback) => {
|
|
window.setTimeout(() => {
|
|
success({
|
|
...location,
|
|
timestamp: Date.now(),
|
|
} as GeolocationPosition);
|
|
}, 50);
|
|
};
|
|
|
|
Object.defineProperty(navigator, "geolocation", {
|
|
configurable: true,
|
|
value: {
|
|
getCurrentPosition: notify,
|
|
watchPosition: (success: PositionCallback) => {
|
|
notify(success);
|
|
return 1;
|
|
},
|
|
clearWatch: () => {},
|
|
},
|
|
});
|
|
});
|
|
|
|
await seedAuthenticatedState(page, "default-mobile-redirect-token");
|
|
await mockApi(page, {
|
|
authenticated: true,
|
|
permissions: adminPermissions,
|
|
});
|
|
|
|
let departmentsRequestCount = 0;
|
|
await page.route(apiPathPattern("/departments"), async (route) => {
|
|
departmentsRequestCount += 1;
|
|
if (departmentsRequestCount === 1) {
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
}
|
|
|
|
await route.fulfill(
|
|
json({
|
|
data: [
|
|
{ id: 1, name: "Far", latitude: 55.1, longitude: 12.1 },
|
|
{ id: 2, name: "Near", latitude: 55.6762, longitude: 12.5684 },
|
|
],
|
|
})
|
|
);
|
|
});
|
|
|
|
await page.goto("/redirect", { waitUntil: "domcontentloaded" });
|
|
|
|
await expect(page).toHaveURL(/\/admin\/2\/modules\/pos(?:[?#].*)?$/, { timeout: 15_000 });
|
|
expect(departmentsRequestCount).toBeGreaterThan(0);
|
|
});
|