Skip to content

Commit

Permalink
Continue with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Nov 6, 2024
1 parent 54ee731 commit 6a78503
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 71 deletions.
26 changes: 14 additions & 12 deletions tests/edits.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { expect, test, type Page } from "@playwright/test";
import { resetSketch, clickMap } from "./shared.js";

let page: Page;

test.beforeEach(async ({ browser }) => {
page = await resetSketch(browser);
test.beforeEach(async ({ page }) => {
await resetSketch(page);
});

test("edit a freehand area, then cancel", async () => {
test("edit a freehand area, then cancel", async ({ page }) => {
await page.getByRole("button", { name: "New area (freehand)" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
Expand All @@ -20,10 +18,10 @@ test("edit a freehand area, then cancel", async () => {
await expect(page.getByRole("button", { name: "Cancel" })).toBeVisible();

await page.keyboard.down("Escape");
await expectListMode();
await expectListMode(page);
});

test("edit a snapped area, then cancel", async () => {
test("edit a snapped area, then cancel", async ({ page }) => {
await page.getByRole("button", { name: "New area (snapped)" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
Expand All @@ -36,14 +34,14 @@ test("edit a snapped area, then cancel", async () => {
await expect(page.getByRole("button", { name: "Cancel" })).toBeVisible();

await page.keyboard.down("Escape");
await expectListMode();
await expectListMode(page);
});

// TODO Edit each type of object without saving, and verify the edits are
// retained. Or cancel and make sure they're reverted. (How to test for
// geometry changes?)

test("edit a route, then cancel", async () => {
test("edit a route, then cancel", async ({ page }) => {
await page.getByRole("button", { name: "New route" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
Expand All @@ -57,10 +55,10 @@ test("edit a route, then cancel", async () => {
await expect(page.getByRole("button", { name: "Cancel" })).toBeVisible();

await page.keyboard.down("Escape");
await expectListMode();
await expectListMode(page);
});

test("the viewport changes only once when opening a form", async () => {
test("the viewport changes only once when opening a form", async ({ page }) => {
let defaultViewport = new URL(page.url()).hash;

// Create a point, and make sure the viewport hasn't changed
Expand All @@ -76,6 +74,10 @@ test("the viewport changes only once when opening a form", async () => {
let pointViewport = new URL(page.url()).hash;
await expect(pointViewport).not.toEqual(defaultViewport);

// The cursor is on the marker, so scrolling won't work unless we move first.
// Clicking has no effect.
await clickMap(page, 400, 400);

// Zoom in on the map without closing the form. The viewport should again differ.
await page.getByRole("region", { name: "Map" }).hover();
await page.mouse.wheel(0, -100);
Expand All @@ -92,6 +94,6 @@ test("the viewport changes only once when opening a form", async () => {
});

// Assert the page is in the main list mode.
async function expectListMode() {
async function expectListMode(page: Page) {
await expect(page.getByRole("button", { name: "New point" })).toBeEnabled();
}
18 changes: 12 additions & 6 deletions tests/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expect, test } from "@playwright/test";
import { clickMap } from "./shared.js";
import { resetSketch, clickMap } from "./shared.js";

// This is separate from modes.spec.ts to avoid the common beforeAll
test("other tools work when route tool doesn't load", async ({ page }) => {
// Do this first
await page.route(
"https://atip.uk/route-snappers/v3/LAD_Adur.bin.gz",
(route) =>
route.fulfill({
status: 404,
}),
);
await page.goto("/scheme.html?authority=LAD_Adur");
await resetSketch(page);

await expect(page.getByText("Failed to load route snapper")).toBeVisible();

Expand All @@ -23,7 +23,7 @@ test("other tools work when route tool doesn't load", async ({ page }) => {
await expect(page.getByRole("link", { name: "Pointless" })).toBeVisible();
});

test("Redirected to homepage with error when incorrect authority given to scheme page", async ({
test("Redirected to homepage with error when incorrect params given to scheme page", async ({
page,
}) => {
await page.goto("/scheme.html?authority=Adu");
Expand All @@ -32,12 +32,18 @@ test("Redirected to homepage with error when incorrect authority given to scheme
await expect(page).toHaveURL(
/.*\?error=Authority\+name\+not\+found%3A\+Adu&style=streets/,
);

await page.goto("/scheme.html?authority=LAD_Adur&file=missing");

await expect(
page.getByText("File missing in authority LAD_Adur not found:"),
).toBeVisible();
});

test("Upload file with invalid boundary", async ({ page }) => {
test("Import file with invalid boundary", async ({ page }) => {
await page.goto("/");
await page
.getByLabel("Or upload an ATIP GeoJSON file")
.getByLabel("Or import a GeoJSON file")
.setInputFiles("tests/data/out_of_bounds.geojson");

await expect(
Expand Down
6 changes: 3 additions & 3 deletions tests/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ test("choosing a local authority and clicking start changes the url", async ({
);
});

test("Uploading a valid geojson redirects to the appropriate authority scheme page", async ({
test("Importing a valid geojson redirects to the appropriate authority scheme page", async ({
page,
}) => {
await page.goto("/");
await page
.getByLabel("Or upload a GeoJSON file")
.getByLabel("Or import a ATIP GeoJSON file")
.setInputFiles("tests/data/LAD_Adur.geojson");

await expect(page).toHaveURL(
Expand Down Expand Up @@ -48,7 +48,7 @@ test("a v1 file with a pipeline hint redirects to pipeline mode", async ({
}) => {
await page.goto("/index.html?schema=pipeline");
await page
.getByLabel("Or upload an ATIP GeoJSON file")
.getByLabel("Or import a ATIP GeoJSON file")
.setInputFiles("tests/data/LAD_Adur.geojson");
await expect(page).toHaveURL(
/.*scheme.html\?authority=LAD_Adur&schema=pipeline/,
Expand Down
36 changes: 20 additions & 16 deletions tests/modes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { expect, test, type Page } from "@playwright/test";
import { resetSketch, clickMap } from "./shared.js";

let page: Page;

test.beforeEach(async ({ browser }) => {
page = await resetSketch(browser);
test.beforeEach(async ({ page }) => {
await resetSketch(page);
});

test("creating a new point opens a form", async () => {
test("creating a new point opens a form", async ({ page }) => {
await page.getByRole("button", { name: "New point" }).click();
await clickMap(page, 500, 500);
await page.getByLabel("Name").fill("Point name");
Expand All @@ -17,7 +15,7 @@ test("creating a new point opens a form", async () => {
await page.getByRole("link", { name: "Point name" }).click();
});

test("creating a new freehand area opens a form", async () => {
test("creating a new freehand area opens a form", async ({ page }) => {
await page.getByRole("button", { name: "New area (freehand)" }).click();
await page.getByLabel("Name").fill("Area name");
await page.getByLabel("Description").click();
Expand All @@ -30,7 +28,9 @@ test("creating a new freehand area opens a form", async () => {
await page.getByRole("link", { name: "Area name" }).click();
});

test("creating a new freehand area and canceling doesn't save anything", async () => {
test("creating a new freehand area and canceling doesn't save anything", async ({
page,
}) => {
await page.getByRole("button", { name: "New area (freehand)" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
Expand All @@ -44,7 +44,7 @@ test("creating a new freehand area and canceling doesn't save anything", async (

// TODO Repeat canceling for other draw tools

test("creating a new snapped area opens a form", async () => {
test("creating a new snapped area opens a form", async ({ page }) => {
await page.getByRole("button", { name: "New area (snapped)" }).click();
await page.getByLabel("Name").fill("Area name");
await page.getByLabel("Description").click();
Expand All @@ -57,7 +57,9 @@ test("creating a new snapped area opens a form", async () => {
await page.getByRole("link", { name: "Area name" }).click();
});

test("creating a new route opens a form, and auto-fill sets its name", async () => {
test("creating a new route opens a form, and auto-fill sets its name", async ({
page,
}) => {
await page.getByRole("button", { name: "New route" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
Expand All @@ -81,7 +83,7 @@ test("creating a new route opens a form, and auto-fill sets its name", async ()
).toBeVisible();
});

test("editing geometry of a area works", async () => {
test("editing geometry of a area works", async ({ page }) => {
// Create an area
await page.getByRole("button", { name: "New area (snapped)" }).click();
await clickMap(page, 241, 509);
Expand All @@ -97,7 +99,9 @@ test("editing geometry of a area works", async () => {
});

// TODO Flaky only on GH Actions
test.skip("adding interventions, then deleting one, then adding another", async () => {
test("adding interventions, then deleting one, then adding another", async ({
page,
}) => {
await page.getByRole("button", { name: "New route" }).click();
await clickMap(page, 522, 468);
await clickMap(page, 192, 513);
Expand All @@ -122,12 +126,12 @@ test.skip("adding interventions, then deleting one, then adding another", async
).toBeVisible();
});

test("escape key works from every mode", async () => {
test("escape key works from every mode", async ({ page }) => {
// We start in list mode
await expectListMode();
await expectListMode(page);
// Pressing escape from there shouldn't do anything
await page.keyboard.down("Escape");
await expectListMode();
await expectListMode(page);

// From each tool, make sure escape goes back to list mode
for (let mode of [
Expand All @@ -140,11 +144,11 @@ test("escape key works from every mode", async () => {
]) {
await page.getByRole("button", { name: mode }).click();
await page.keyboard.down("Escape");
await expectListMode();
await expectListMode(page);
}
});

// Assert the page is in the main list mode.
async function expectListMode() {
async function expectListMode(page: Page) {
await expect(page.getByRole("button", { name: "New point" })).toBeEnabled();
}
57 changes: 29 additions & 28 deletions tests/pipeline.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { expect, test, type Page } from "@playwright/test";
import {
checkPageLoaded,
clearExistingInterventions,
getLocalStorage,
} from "./shared.js";

let page: Page;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
await page.goto("/scheme.html?authority=LAD_Adur&schema=pipeline");
await checkPageLoaded(page);
});
import { expect, test } from "@playwright/test";
import { resetSketch, getLocalStorage } from "./shared.js";

test.beforeEach(async () => {
await clearExistingInterventions(page);
});
test("scheme validations are updated", async ({ page }) => {
let filename = await resetSketch(page, "pipeline");

test("scheme validations are updated", async () => {
await page.getByRole("button", { name: "Edit" }).click();
// Blank schemes aren't valid
await expect(page.getByText("Missing some required data")).toBeVisible();
Expand Down Expand Up @@ -51,7 +37,7 @@ test("scheme validations are updated", async () => {
await page.getByRole("button", { name: "Save changes" }).click();

// Check the data in local storage
let json = await getLocalStorage(page, "LAD_Adur_pipeline");
let json = await getLocalStorage(page, `sketch/LAD_Adur/${filename}`);
let scheme = Object.values(json.schemes)[0] as any;
expect(scheme.scheme_name).toEqual("Corridor 1");
expect(scheme.pipeline).toEqual(
Expand All @@ -70,12 +56,14 @@ test("scheme validations are updated", async () => {

// Refresh and make sure there are no warnings
await page.reload();
await checkPageLoaded(page);
await expect(page.getByRole("button", { name: "New route" })).toBeEnabled();
await page.getByRole("button", { name: "Edit" }).click();
await expect(page.getByText("Missing some required data")).not.toBeVisible();
});

test("file started with v1 can be edited by adding", async () => {
test("file started with v1 can be edited by adding", async ({ page }) => {
await resetSketch(page, "pipeline");

// Load a file with no pipeline data, using the v1 schema
await page
.getByLabel("Add scheme from file")
Expand All @@ -89,22 +77,30 @@ test("file started with v1 can be edited by adding", async () => {
.click();
});

test("file started with v1 can be edited by loading", async () => {
// TODO need to rethink this one
/*test("file started with v1 can be edited by loading", async () => {
await page.getByText("Manage files").click();
await page
.getByLabel("Load GeoJSON file")
.setInputFiles("tests/data/LAD_Adur.geojson");
await page.getByRole("button", { name: "Edit" }).click();
await page.getByText("Shared-use route").click();
});
});*/

// Check compatibility of old files with new per-feature fields introduced 14 February 2024
test("file without new budget/timing forms can be edited by loading", async () => {
await page.getByText("Manage files").click();
test("file without new budget/timing forms can be edited by loading", async ({
page,
}) => {
await page.goto("/");
await page
.getByLabel("Load GeoJSON file")
.getByLabel("Or import a ATIP GeoJSON file")
.setInputFiles("tests/data/pipeline_before_feb_fields.geojson");

await expect(page).toHaveURL(
/.*scheme.html\?authority=LAD_Adur&filename=pipeline_before_feb_fields/,
);
await expect(page.getByRole("button", { name: "New route" })).toBeEnabled();

await page.getByRole("link", { name: "POI" }).click();
await page.getByLabel("Cost (GBP)").fill("1.2");
await page.getByRole("button", { name: "multiply by 1 million" }).click();
Expand All @@ -113,7 +109,10 @@ test("file without new budget/timing forms can be edited by loading", async () =
await page.getByRole("button", { name: "Finish" }).click();

// Check the data in local storage
let json = await getLocalStorage(page, "LAD_Adur_pipeline");
let json = await getLocalStorage(
page,
"sketch/LAD_Adur/pipeline_before_feb_fields",
);
let feature = json.features[0] as any;
expect(feature.properties.name).toEqual("POI");
expect(feature.properties.pipeline).toEqual(
Expand All @@ -127,7 +126,9 @@ test("file without new budget/timing forms can be edited by loading", async () =
);
});

test("file from another tool can be edited", async () => {
test("file from another tool can be edited", async ({ page }) => {
await resetSketch(page, "pipeline");

// Load a file produced with another tool
await page
.getByLabel("Add scheme from file")
Expand Down
2 changes: 1 addition & 1 deletion tests/savefiles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ test("the previous file from local storage is loaded by default", async () => {
test("loading a file from the homepage goes to the correct page", async () => {
await page.goto("/");
await page
.getByLabel("Or upload an ATIP GeoJSON file")
.getByLabel("Or import a ATIP GeoJSON file")
.setInputFiles("tests/data/LAD_Adur.geojson");

await expect(page).toHaveURL(/scheme.html\?authority=LAD_Adur/);
Expand Down
Loading

0 comments on commit 6a78503

Please sign in to comment.