Cleanup pass 2

This commit is contained in:
adilallo
2026-05-22 13:30:47 -06:00
parent b7c804bac8
commit 753220f97b
76 changed files with 1338 additions and 1020 deletions
+2 -5
View File
@@ -22,7 +22,6 @@ const config: ComponentTestSuiteConfig<AskOrganizerProps> = {
subtitle: "Subtitle",
description: "Description",
buttonText: "Button",
buttonHref: "/link",
className: "custom",
variant: "centered",
},
@@ -72,11 +71,9 @@ describe("AskOrganizer (behavioral tests)", () => {
});
it("renders button with custom text", () => {
render(
<AskOrganizer title="Test" buttonText="Contact" buttonHref="/contact" />,
);
render(<AskOrganizer title="Test" buttonText="Contact" />);
expect(
screen.getByRole("link", {
screen.getByRole("button", {
name: /contact/i,
}),
).toBeInTheDocument();
@@ -1,5 +1,5 @@
import { useEffect, useLayoutEffect } from "react";
import { describe, it, expect, afterEach, vi } from "vitest";
import { describe, it, expect, afterEach } from "vitest";
import {
renderWithProviders as render,
screen,
@@ -17,6 +17,18 @@ afterEach(() => {
cleanup();
});
async function confirmDiscardCustomizeEdits() {
fireEvent.click(
await screen.findByRole("button", { name: "Discard" }),
);
}
async function declineDiscardCustomizeEdits() {
fireEvent.click(
await screen.findByRole("button", { name: "Keep editing" }),
);
}
/**
* Mounts the screen with optional starting state and exposes the latest
* `state` to the test harness so we can assert the persistence side of
@@ -152,9 +164,6 @@ describe("CommunicationMethodsScreen — Add Platform persistence", () => {
it("Cancel customize reverts edited preset without persisting (no confirm when unchanged)", async () => {
let latest: CreateFlowState = {};
const confirmSpy = vi.spyOn(window, "confirm").mockImplementation(() => {
throw new Error("confirm should not run when customize session is clean");
});
render(
<ScreenWithStateProbe
onState={(s) => {
@@ -171,20 +180,20 @@ describe("CommunicationMethodsScreen — Add Platform persistence", () => {
fireEvent.click(screen.getByRole("menuitem", { name: "Customize" }));
fireEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(
(within(screen.getByRole("dialog")).getAllByRole(
"textbox",
)[0] as HTMLTextAreaElement).disabled,
).toBe(true);
await waitFor(() => {
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(
(within(screen.getByRole("dialog")).getAllByRole(
"textbox",
)[0] as HTMLTextAreaElement).disabled,
).toBe(true);
});
expect(latest.communicationMethodDetailsById).toBeUndefined();
confirmSpy.mockRestore();
expect(screen.queryByRole("button", { name: "Discard" })).not.toBeInTheDocument();
});
it("Cancel customize with edits restores snapshot after confirm", async () => {
let latest: CreateFlowState = {};
const confirmSpy = vi.spyOn(window, "confirm").mockReturnValue(true);
render(
<ScreenWithStateProbe
onState={(s) => {
@@ -216,24 +225,23 @@ describe("CommunicationMethodsScreen — Add Platform persistence", () => {
fireEvent.change(textboxes[2], { target: { value: "Edited principle" } });
fireEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));
await confirmDiscardCustomizeEdits();
expect(confirmSpy).toHaveBeenCalled();
expect(
(
within(screen.getByRole("dialog")).getAllByRole(
"textbox",
)[0] as HTMLTextAreaElement
).value,
).toBe("Saved principle");
await waitFor(() => {
expect(
(
within(screen.getByRole("dialog")).getAllByRole(
"textbox",
)[0] as HTMLTextAreaElement
).value,
).toBe("Saved principle");
});
expect(
latest.communicationMethodDetailsById?.signal?.corePrinciple,
).toBe("Saved principle");
confirmSpy.mockRestore();
});
it("dirty Escape close stays open when user declines discard confirm", async () => {
const confirmSpy = vi.spyOn(window, "confirm").mockReturnValue(false);
render(
<ScreenWithStateProbe
onState={() => {
@@ -255,11 +263,10 @@ describe("CommunicationMethodsScreen — Add Platform persistence", () => {
fireEvent.change(textboxes[2], { target: { value: "Edited principle" } });
fireEvent.keyDown(document, { key: "Escape" });
await screen.findByRole("button", { name: "Keep editing" });
await declineDiscardCustomizeEdits();
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(confirmSpy).toHaveBeenCalled();
confirmSpy.mockRestore();
});
it("persists customized policy title for a custom UUID card on Save", async () => {
+12 -10
View File
@@ -1,5 +1,5 @@
import { useEffect, useLayoutEffect } from "react";
import { describe, it, expect, vi } from "vitest";
import { describe, it, expect } from "vitest";
import { fireEvent, within } from "@testing-library/react";
import {
renderWithProviders as render,
@@ -11,6 +11,12 @@ import { FinalReviewScreen } from "../../app/(app)/create/screens/review/FinalRe
import { useCreateFlow } from "../../app/(app)/create/context/CreateFlowContext";
import type { CreateFlowState } from "../../app/(app)/create/types";
async function confirmDiscardCustomizeEdits() {
fireEvent.click(
await screen.findByRole("button", { name: "Discard" }),
);
}
/**
* Mounts the screen with a Customize-style preset selection and exposes the
* latest `state` to the test via `onState`. Used by the edit-modal save
@@ -521,15 +527,11 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
target: { value: "Should NOT persist" },
});
const confirmSpy = vi.spyOn(window, "confirm").mockReturnValue(true);
try {
fireEvent.keyDown(document, { key: "Escape" });
await waitFor(() => {
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
} finally {
confirmSpy.mockRestore();
}
fireEvent.keyDown(document, { key: "Escape" });
await confirmDiscardCustomizeEdits();
await waitFor(() => {
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
expect(latest.communicationMethodDetailsById).toBeUndefined();
});
@@ -1,23 +0,0 @@
import { describe } from "vitest";
import {
componentTestSuite,
type ComponentTestSuiteConfig,
} from "../utils/componentTestSuite";
import LanguageSwitcher from "../../app/components/localization/LanguageSwitcher";
type Props = React.ComponentProps<typeof LanguageSwitcher>;
const config: ComponentTestSuiteConfig<Props> = {
component: LanguageSwitcher,
name: "LanguageSwitcher",
props: {} as Props,
primaryRole: "combobox",
testCases: {
renders: true,
accessibility: true,
},
};
describe("LanguageSwitcher", () => {
componentTestSuite<Props>(config);
});