89 lines
3.2 KiB
TypeScript
89 lines
3.2 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import {
|
|
captureBrowserFailures,
|
|
gotoLiveView,
|
|
projectEmail,
|
|
registerAndConfirm,
|
|
} from "./helpers";
|
|
|
|
test("request location picker separates approximate, exact, and hidden disclosure", async ({
|
|
browser,
|
|
request,
|
|
}, testInfo) => {
|
|
const user = await registerAndConfirm(
|
|
browser,
|
|
request,
|
|
projectEmail("location-picker", testInfo.project.name),
|
|
"Location Picker",
|
|
);
|
|
const assertBrowserClean = captureBrowserFailures(user.page);
|
|
const origin = new URL(process.env.BASE_URL!).origin;
|
|
|
|
await user.context.grantPermissions(["geolocation"], { origin });
|
|
await user.context.setGeolocation({
|
|
latitude: 50.450123,
|
|
longitude: 30.523456,
|
|
accuracy: 5,
|
|
});
|
|
await gotoLiveView(user.page, "/requests/new");
|
|
|
|
const workspace = user.page.locator("#request-location-workspace");
|
|
const latitude = workspace.locator("#request-latitude");
|
|
const longitude = workspace.locator("#request-longitude");
|
|
|
|
await workspace.getByRole("button", { name: "Use my location" }).click();
|
|
await expect(workspace.locator("#request-location-status")).toHaveText(
|
|
"Area selected. Drag the green pin or click the map to move it.",
|
|
);
|
|
await expect(latitude).not.toHaveValue("50.450123");
|
|
await expect(longitude).not.toHaveValue("30.523456");
|
|
|
|
const map = workspace.locator("#request-location-map");
|
|
const approximateMarker = workspace.locator(".maplibregl-marker");
|
|
|
|
if ((await map.locator("canvas").count()) === 0) {
|
|
await expect(map).toContainText("The map is unavailable");
|
|
await expect(approximateMarker).toHaveCount(0);
|
|
await expect(workspace.locator(".request-location-map-hint")).toBeHidden();
|
|
} else {
|
|
const approximateLatitude = await latitude.inputValue();
|
|
await expect(approximateMarker).toBeVisible();
|
|
const markerBox = await approximateMarker.boundingBox();
|
|
expect(markerBox).not.toBeNull();
|
|
await user.page.mouse.move(
|
|
markerBox!.x + markerBox!.width / 2,
|
|
markerBox!.y + markerBox!.height / 2,
|
|
);
|
|
await user.page.mouse.down();
|
|
await user.page.mouse.move(
|
|
markerBox!.x + markerBox!.width / 2 + 48,
|
|
markerBox!.y + markerBox!.height / 2 + 24,
|
|
{ steps: 5 },
|
|
);
|
|
await user.page.mouse.up();
|
|
await expect(latitude).not.toHaveValue(approximateLatitude);
|
|
}
|
|
|
|
await workspace
|
|
.locator('input[name="help_request[location_visibility]"][value="exact_public"]')
|
|
.check();
|
|
await expect(workspace.getByText("This point is public")).toBeVisible();
|
|
await workspace.getByRole("button", { name: "Use my location" }).click();
|
|
await expect(workspace.locator("#request-location-status")).toHaveText(
|
|
"Exact point selected. Drag the red pin or click the map to move it.",
|
|
);
|
|
await expect(latitude).toHaveValue("50.450123");
|
|
await expect(longitude).toHaveValue("30.523456");
|
|
|
|
await workspace
|
|
.locator('input[name="help_request[location_visibility]"][value="hidden"]')
|
|
.check();
|
|
await expect(workspace.getByRole("heading", { name: "No coordinates will be stored" }))
|
|
.toBeVisible();
|
|
await expect(latitude).toHaveValue("");
|
|
await expect(longitude).toHaveValue("");
|
|
|
|
assertBrowserClean();
|
|
await user.context.close();
|
|
});
|