81 lines
2.9 KiB
TypeScript
81 lines
2.9 KiB
TypeScript
import { expect } from "@playwright/test";
|
|
import { test } from "../fixtures";
|
|
import { registerAndLogin, createList, addItem } from "../helpers";
|
|
|
|
test("a user can create a list", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
|
|
await createList(page, "Weekly shop");
|
|
|
|
await expect(page.locator("h1")).toContainText("Weekly shop");
|
|
await expect(page.locator(".empty-items")).toBeVisible();
|
|
});
|
|
|
|
test("a user can add an item with a quantity", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await createList(page, "Weekly shop");
|
|
|
|
await addItem(page, "Apple", "2");
|
|
|
|
// Quantity renders in parens to the left of the name.
|
|
const row = page.locator(".item-row").filter({ hasText: "Apple" });
|
|
await expect(row.locator(".item-qty")).toHaveText("(2)");
|
|
await expect(row.locator("strong")).toHaveText("Apple");
|
|
});
|
|
|
|
test("a user can check off an item", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await createList(page, "Weekly shop");
|
|
await addItem(page, "Apple");
|
|
|
|
const row = page.locator(".item-row").filter({ hasText: "Apple" });
|
|
await row.locator(".check-button").click();
|
|
|
|
await expect(row).toHaveClass(/is-checked/);
|
|
});
|
|
|
|
test("a user can edit an item via the actions modal", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await createList(page, "Weekly shop");
|
|
await addItem(page, "Apple", "2");
|
|
|
|
const row = page.locator(".item-row").filter({ hasText: "Apple" });
|
|
await row.locator(".item-actions-button").click();
|
|
|
|
const dialog = row.locator("dialog.item-modal");
|
|
await expect(dialog).toBeVisible();
|
|
await dialog.locator('[id^="item-edit-name"]').fill("Banana");
|
|
await dialog.locator('[id^="item-edit-quantity"]').fill("6");
|
|
await dialog.locator('[id^="item-edit-save"]').click();
|
|
|
|
const updated = page.locator(".item-row").filter({ hasText: "Banana" });
|
|
await expect(updated).toBeVisible();
|
|
await expect(updated.locator(".item-qty")).toHaveText("(6)");
|
|
});
|
|
|
|
test("a user can delete an item via the actions modal", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await createList(page, "Weekly shop");
|
|
await addItem(page, "Apple");
|
|
|
|
const row = page.locator(".item-row").filter({ hasText: "Apple" });
|
|
await row.locator(".item-actions-button").click();
|
|
|
|
const dialog = row.locator("dialog.item-modal");
|
|
await expect(dialog).toBeVisible();
|
|
await dialog.locator('[id^="item-edit-delete"]').click();
|
|
|
|
await expect(page.locator(".item-row").filter({ hasText: "Apple" })).toHaveCount(0);
|
|
await expect(page.locator(".empty-items")).toBeVisible();
|
|
});
|
|
|
|
test("a user can add a category", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await createList(page, "Weekly shop");
|
|
|
|
await page.fill("#category-name", "Bakery");
|
|
await page.click("#add-category-button");
|
|
|
|
await expect(page.locator(".category-chip").filter({ hasText: "Bakery" })).toBeVisible();
|
|
});
|