mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 19:22:06 +00:00
test(vendors): update the deactivation e2e to the confirmation flow (SH-254)
The browser smoke encoded the behaviour this ticket changes: it asserted the Deactivate button was disabled when work orders were linked. It now asserts the opposite — the work orders are listed as links, "Deactivate anyway" is enabled, and confirming sends confirmOpenWorkOrders=true. Also fixes the mock's DELETE route, whose anchored pattern stopped matching once the request carried a query string. The raced-409 case is unchanged and still preserves the vendor.
This commit is contained in:
parent
22b03b8ac0
commit
670d03d572
1 changed files with 23 additions and 11 deletions
34
e2e/vendors/vendors.spec.ts
vendored
34
e2e/vendors/vendors.spec.ts
vendored
|
|
@ -66,6 +66,7 @@ interface MockState {
|
||||||
createdBody?: Record<string, unknown>;
|
createdBody?: Record<string, unknown>;
|
||||||
updatedBody?: Record<string, unknown>;
|
updatedBody?: Record<string, unknown>;
|
||||||
deletedId?: string;
|
deletedId?: string;
|
||||||
|
deleteConfirmedOpenWorkOrders?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fulfillJson(route: Route, body: unknown, status = 200) {
|
async function fulfillJson(route: Route, body: unknown, status = 200) {
|
||||||
|
|
@ -259,8 +260,9 @@ async function mockVendorApi(
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
await page.route(/\/api\/vendors\/\d+$/, async (route) => {
|
await page.route(/\/api\/vendors\/\d+(\?.*)?$/, async (route) => {
|
||||||
const id = route.request().url().split("/").pop() ?? "";
|
const requestUrl = new URL(route.request().url());
|
||||||
|
const id = requestUrl.pathname.split("/").pop() ?? "";
|
||||||
if (route.request().method() === "PUT") {
|
if (route.request().method() === "PUT") {
|
||||||
state.updatedBody = route.request().postDataJSON();
|
state.updatedBody = route.request().postDataJSON();
|
||||||
const vendor = vendorRecords.find((item) => String(item.Id) === id);
|
const vendor = vendorRecords.find((item) => String(item.Id) === id);
|
||||||
|
|
@ -273,6 +275,8 @@ async function mockVendorApi(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (route.request().method() === "DELETE") {
|
if (route.request().method() === "DELETE") {
|
||||||
|
state.deleteConfirmedOpenWorkOrders =
|
||||||
|
requestUrl.searchParams.get("confirmOpenWorkOrders") === "true";
|
||||||
if (options.deleteConflict) {
|
if (options.deleteConflict) {
|
||||||
await fulfillJson(
|
await fulfillJson(
|
||||||
route,
|
route,
|
||||||
|
|
@ -517,20 +521,28 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
await expect(page.getByRole("button", { name: "Close drawer" })).toHaveCount(0);
|
await expect(page.getByRole("button", { name: "Close drawer" })).toHaveCount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("blocks deactivation for linked work orders and preserves the vendor on a raced 409", async ({
|
test("confirms deactivation past linked work orders and preserves the vendor on a raced 409", async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
const blockedState = await mockVendorApi(page, { deactivationBlocked: true });
|
const confirmState = await mockVendorApi(page, { deactivationBlocked: true });
|
||||||
await page.goto("/vendors");
|
await page.goto("/vendors");
|
||||||
|
|
||||||
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
||||||
await page.getByRole("switch", { name: "Active status" }).click();
|
await page.getByRole("switch", { name: "Active status" }).click();
|
||||||
const blockedDialog = page.getByRole("dialog", { name: "Deactivate Vendor" });
|
const dialog = page.getByRole("dialog", { name: "Deactivate this vendor?" });
|
||||||
await expect(blockedDialog).toContainText("WO-501 — Emergency boiler repair");
|
await expect(dialog).toContainText("It still has 1 open work order");
|
||||||
await expect(blockedDialog.getByRole("button", { name: /^Deactivate$/ })).toBeDisabled();
|
await expect(
|
||||||
expect(blockedState.deletedId).toBeUndefined();
|
dialog.getByRole("link", { name: /WO-501 — Emergency boiler repair/ }),
|
||||||
|
).toHaveAttribute("href", "/workorders/501");
|
||||||
|
|
||||||
|
// SH-254: the open work orders inform the decision, they no longer block it.
|
||||||
|
const confirm = dialog.getByRole("button", { name: "Deactivate anyway" });
|
||||||
|
await expect(confirm).toBeEnabled();
|
||||||
|
await confirm.click();
|
||||||
|
|
||||||
|
await expect.poll(() => confirmState.deletedId).toBe("1");
|
||||||
|
expect(confirmState.deleteConfirmedOpenWorkOrders).toBe(true);
|
||||||
|
|
||||||
await blockedDialog.getByRole("button", { name: "Cancel" }).click();
|
|
||||||
await page.unrouteAll({ behavior: "wait" });
|
await page.unrouteAll({ behavior: "wait" });
|
||||||
|
|
||||||
const racedState = await mockVendorApi(page, { deleteConflict: true });
|
const racedState = await mockVendorApi(page, { deleteConflict: true });
|
||||||
|
|
@ -538,13 +550,13 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
||||||
await page.getByRole("switch", { name: "Active status" }).click();
|
await page.getByRole("switch", { name: "Active status" }).click();
|
||||||
await page
|
await page
|
||||||
.getByRole("dialog", { name: "Deactivate Vendor" })
|
.getByRole("dialog", { name: "Deactivate this vendor?" })
|
||||||
.getByRole("button", {
|
.getByRole("button", {
|
||||||
name: /^Deactivate$/,
|
name: /^Deactivate$/,
|
||||||
})
|
})
|
||||||
.click();
|
.click();
|
||||||
|
|
||||||
await expect(page.getByRole("dialog", { name: "Deactivate Vendor" })).toContainText(
|
await expect(page.getByRole("dialog", { name: "Deactivate this vendor?" })).toContainText(
|
||||||
/open work orders|conflict/i,
|
/open work orders|conflict/i,
|
||||||
);
|
);
|
||||||
expect(racedState.deletedId).toBeUndefined();
|
expect(racedState.deletedId).toBeUndefined();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue