test: reduce fixture typing overhead in retry workflows
This commit is contained in:
parent
4a5cac2593
commit
cdcf0d9898
|
|
@ -1,5 +1,5 @@
|
||||||
import { type ReactNode } from "react";
|
import { type ReactNode } from "react";
|
||||||
import { render, screen } from "@testing-library/react";
|
import { fireEvent, render, screen } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { ThemeProvider } from "@mui/material/styles";
|
import { ThemeProvider } from "@mui/material/styles";
|
||||||
|
|
@ -92,11 +92,9 @@ test("an uncertain sample request retries with its original account, variant, qu
|
||||||
|
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
await user.click(screen.getByRole("button", { name: "Test login" }));
|
await user.click(screen.getByRole("button", { name: "Test login" }));
|
||||||
await user.type(await screen.findByRole("textbox", { name: /Variant ID/ }), variantId);
|
fireEvent.change(await screen.findByRole("textbox", { name: /Variant ID/ }), { target: { value: variantId } });
|
||||||
const quantity = screen.getByRole("spinbutton", { name: /Sample quantity/ });
|
fireEvent.change(screen.getByRole("spinbutton", { name: /Sample quantity/ }), { target: { value: "4" } });
|
||||||
await user.clear(quantity);
|
fireEvent.change(screen.getByRole("textbox", { name: /Sample purpose/ }), { target: { value: sample.purpose } });
|
||||||
await user.type(quantity, "4");
|
|
||||||
await user.type(screen.getByRole("textbox", { name: /Sample purpose/ }), sample.purpose);
|
|
||||||
await user.click(screen.getByRole("button", { name: "Request samples" }));
|
await user.click(screen.getByRole("button", { name: "Request samples" }));
|
||||||
await user.click(await screen.findByRole("button", { name: "Retry sample request" }));
|
await user.click(await screen.findByRole("button", { name: "Retry sample request" }));
|
||||||
await screen.findByText(sample.purpose);
|
await screen.findByText(sample.purpose);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { type ReactNode } from "react";
|
import { type ReactNode } from "react";
|
||||||
import { act, render, screen, waitFor, within } from "@testing-library/react";
|
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||||
import { Table } from "../src/components/WorkspaceTools";
|
import { Table } from "../src/components/WorkspaceTools";
|
||||||
import { ConfirmAction } from "../src/components/ConfirmAction";
|
import { ConfirmAction } from "../src/components/ConfirmAction";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
|
|
@ -722,19 +722,17 @@ test("a production batch starts, safely retries usage and completes with reconci
|
||||||
await user.click(await screen.findByRole("button", { name: "Start batch" }));
|
await user.click(await screen.findByRole("button", { name: "Start batch" }));
|
||||||
await user.click(screen.getByRole("button", { name: "Confirm" }));
|
await user.click(screen.getByRole("button", { name: "Confirm" }));
|
||||||
await user.selectOptions(await screen.findByRole("combobox", { name: /Usage type/ }), "WASTED");
|
await user.selectOptions(await screen.findByRole("combobox", { name: /Usage type/ }), "WASTED");
|
||||||
await user.type(screen.getByRole("textbox", { name: /Actual quantity/ }), "0.125");
|
fireEvent.change(screen.getByRole("textbox", { name: /Actual quantity/ }), { target: { value: "0.125" } });
|
||||||
await user.type(screen.getByRole("textbox", { name: /Usage reason/ }), "Spill");
|
fireEvent.change(screen.getByRole("textbox", { name: /Usage reason/ }), { target: { value: "Spill" } });
|
||||||
await user.click(screen.getByRole("button", { name: "Record material usage" }));
|
await user.click(screen.getByRole("button", { name: "Record material usage" }));
|
||||||
await user.click(await screen.findByRole("button", { name: "Retry material usage" }));
|
await user.click(await screen.findByRole("button", { name: "Retry material usage" }));
|
||||||
await screen.findByRole("cell", { name: "199.875" });
|
await screen.findByRole("cell", { name: "199.875" });
|
||||||
expect(attempts).toHaveLength(2);
|
expect(attempts).toHaveLength(2);
|
||||||
expect(attempts[0]).toEqual({ bomLineId: id, kind: "WASTED", quantity: "0.125", reason: "Spill", idempotencyKey: expect.any(String) });
|
expect(attempts[0]).toEqual({ bomLineId: id, kind: "WASTED", quantity: "0.125", reason: "Spill", idempotencyKey: expect.any(String) });
|
||||||
expect(attempts[1]).toEqual(attempts[0]);
|
expect(attempts[1]).toEqual(attempts[0]);
|
||||||
await user.type(screen.getByRole("spinbutton", { name: /Good pieces/ }), "18");
|
fireEvent.change(screen.getByRole("spinbutton", { name: /Good pieces/ }), { target: { value: "18" } });
|
||||||
const rejected = screen.getByRole("spinbutton", { name: /Rejected pieces/ });
|
fireEvent.change(screen.getByRole("spinbutton", { name: /Rejected pieces/ }), { target: { value: "2" } });
|
||||||
await user.clear(rejected);
|
fireEvent.change(screen.getByRole("textbox", { name: /Rejection reason/ }), { target: { value: "Surface defects" } });
|
||||||
await user.type(rejected, "2");
|
|
||||||
await user.type(screen.getByRole("textbox", { name: /Rejection reason/ }), "Surface defects");
|
|
||||||
await user.click(screen.getByRole("button", { name: "Complete batch" }));
|
await user.click(screen.getByRole("button", { name: "Complete batch" }));
|
||||||
await screen.findByText(/18 good · 2 rejected · Surface defects/);
|
await screen.findByText(/18 good · 2 rejected · Surface defects/);
|
||||||
expect(screen.queryByRole("button", { name: "Record material usage" })).toBeNull();
|
expect(screen.queryByRole("button", { name: "Record material usage" })).toBeNull();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue