Skip to content

Commit

Permalink
Add test of deleting a single local storage item
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter York committed Apr 3, 2024
1 parent e934d00 commit adc0134
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions tests/quota.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,75 @@ test("exceeding local storage quota displays an error", async () => {
await expect(page.getByText("Local Storage Quota Exceeded")).toBeVisible();
});

test("exceeding local storage quota allows user to clear local storage", async () => {

test("exceeding local storage quota allows user to clear local storage", async () => {
// Get super close to the 5MB limit
await page.evaluate(() =>
window.localStorage.setItem("small", "x"),
window.localStorage.setItem("huge", "x".repeat(4.999 * 1024 * 1024)),
);

// Draw one simple route, so that when a big item is added the quota is gone past
// Draw one simple route, causing quota to go over
await page.getByRole("button", { name: "New route" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
await page.getByRole("button", { name: "Finish" }).click();

await page.goto("/index.html?schema=pipeline");
await page.getByTestId("transport-authority").fill("LAD_Worthing");
// Surpass the 5mb limit
await page.getByText("Delete All Sketch Data From Browser").click();

// See that we're now able to set the item without surpassing the quota
await page.evaluate(() =>
window.localStorage.setItem("huge", "x".repeat(4.999 * 1024 * 1024)),
);
await expect(page.getByText("Local Storage Quota Exceeded")).not.toBeVisible();
});

test("exceeding local storage quota allows user to clear local storage, including other LAs", async () => {
// Get super close to the 5MB limit
await page.evaluate(() =>
window.localStorage.setItem("huge", "x".repeat(4.999 * 1024 * 1024)),
);

await page.goto("/index.html?schema=pipeline");
await page.getByTestId("transport-authority").fill("LAD_Worthing");

// Draw one simple route, causing quota to go over
await page.getByRole("button", { name: "New route" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
await page.getByRole("button", { name: "Finish" }).click();

await page.getByText("Delete All Sketch Data From Browser").click();

// See that we're now able to set the item without surpassing the quota
// See that we're now able to set the item without exceeding the quota
await page.evaluate(() =>
window.localStorage.setItem("huge", "x".repeat(4.999 * 1024 * 1024)),
);
await expect(page.getByText("Local Storage Quota Exceeded")).not.toBeVisible();
});

test("exceeding local storage quota allows user to clear specific local storage items, including other LAs", async () => {
// Get super close to the 5MB limit
await page.evaluate(() =>
window.localStorage.setItem("huge", "x".repeat(4.999 * 1024 * 1024)),
);

await page.goto("/index.html?schema=pipeline");
await page.getByTestId("transport-authority").fill("LAD_Worthing");

// Draw one simple route, causing quota to go over
await page.getByRole("button", { name: "New route" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
await page.getByRole("button", { name: "Finish" }).click();

await page.getByText("Remove stored item for huge").click();
await page.getByText("X").click();
await page.getByText("Save").click();

// See that we're now able to make the route without exceeding the quota
await page.getByRole("button", { name: "New route" }).click();
await clickMap(page, 500, 500);
await clickMap(page, 400, 500);
await page.getByRole("button", { name: "Finish" }).click();

await expect(page.getByText("Local Storage Quota Exceeded")).not.toBeVisible();
});

0 comments on commit adc0134

Please sign in to comment.