Implement core value modals

This commit is contained in:
adilallo
2026-04-15 23:13:28 -06:00
parent beae150f02
commit eedb70f9f3
15 changed files with 806 additions and 101 deletions
@@ -0,0 +1,42 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { screen, fireEvent, waitFor, within } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import { renderWithProviders } from "../utils/test-utils";
import { CoreValuesSelectScreen } from "../../app/create/screens/select/CoreValuesSelectScreen";
describe("CoreValuesSelectScreen", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("opens core value detail modal when a preset chip is clicked", async () => {
renderWithProviders(<CoreValuesSelectScreen />);
fireEvent.click(screen.getByText("Accessibility"));
const dialog = await screen.findByRole("dialog");
expect(
within(dialog).getByRole("button", { name: "Add Value" }),
).toBeInTheDocument();
});
it("closes modal and reverts pending selection when Escape is pressed", async () => {
renderWithProviders(<CoreValuesSelectScreen />);
fireEvent.click(screen.getByText("Accessibility"));
await screen.findByRole("dialog");
fireEvent.keyDown(document, { key: "Escape" });
await waitFor(() => {
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
});
it("saves details when Add Value is clicked", async () => {
renderWithProviders(<CoreValuesSelectScreen />);
fireEvent.click(screen.getByText("Accessibility"));
const dialog = await screen.findByRole("dialog");
fireEvent.click(
within(dialog).getByRole("button", { name: "Add Value" }),
);
await waitFor(() => {
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
});
});
+12
View File
@@ -59,6 +59,18 @@ describe("Create", () => {
}
});
it("uses login yellow backdrop when backdropVariant is loginYellow", () => {
renderWithProviders(
<Create
{...defaultProps}
backdropVariant="loginYellow"
headerContent={<div>Header</div>}
/>,
);
const overlay = document.querySelector(".backdrop-blur-md");
expect(overlay).toBeInTheDocument();
});
it("renders footer buttons when provided", () => {
const onBack = vi.fn();
const onNext = vi.fn();
+24 -1
View File
@@ -39,6 +39,7 @@ describe("buildPublishPayload", () => {
],
},
],
coreValues: [],
});
});
@@ -58,6 +59,7 @@ describe("buildPublishPayload", () => {
entries: [{ title: "Community", body: "We organize locally." }],
},
],
coreValues: [],
});
});
@@ -71,7 +73,7 @@ describe("buildPublishPayload", () => {
const r = buildPublishPayload({ title: "T", sections });
expect(r.ok).toBe(true);
if (!r.ok) return;
expect(r.document).toEqual({ sections });
expect(r.document).toEqual({ sections, coreValues: [] });
});
it("filters invalid section entries from state.sections", () => {
@@ -86,8 +88,29 @@ describe("buildPublishPayload", () => {
if (!r.ok) return;
expect(r.document).toEqual({
sections: [{ categoryName: "Values", entries: [{ title: "A", body: "B" }] }],
coreValues: [],
});
});
it("includes coreValues from selected chips and detail text", () => {
const r = buildPublishPayload({
title: "T",
selectedCoreValueIds: ["1", "2"],
coreValuesChipsSnapshot: [
{ id: "1", label: "Alpha", state: "Selected" },
{ id: "2", label: "Beta", state: "Selected" },
],
coreValueDetailsByChipId: {
"1": { meaning: "m1", signals: "s1" },
},
});
expect(r.ok).toBe(true);
if (!r.ok) return;
expect(r.document.coreValues).toEqual([
{ chipId: "1", label: "Alpha", meaning: "m1", signals: "s1" },
{ chipId: "2", label: "Beta", meaning: "", signals: "" },
]);
});
});
describe("parseDocumentSectionsForDisplay", () => {
+19
View File
@@ -101,6 +101,25 @@ describe("createFlowStateSchema", () => {
});
expect(r.success).toBe(false);
});
it("accepts coreValueDetailsByChipId", () => {
const r = createFlowStateSchema.safeParse({
coreValueDetailsByChipId: {
"1": { meaning: "We care about access.", signals: "Blocking access." },
"uuid-here": { meaning: "", signals: "" },
},
});
expect(r.success).toBe(true);
});
it("rejects core value detail strings that are too long", () => {
const r = createFlowStateSchema.safeParse({
coreValueDetailsByChipId: {
"1": { meaning: "x".repeat(8001), signals: "y" },
},
});
expect(r.success).toBe(false);
});
});
describe("putDraftBodySchema", () => {