Start Add value in the empty custom-policy wizard so Finalize can save a selected chip named from the title.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -256,25 +256,12 @@ describe("CoreValuesSelectScreen", () => {
|
||||
expect(labels[1]).toMatch(/What does this value mean to your group/);
|
||||
});
|
||||
|
||||
// The "Add value" → custom-chip → modal flow uses a `customPending`
|
||||
// session: dismissing the modal must drop the brand-new chip entirely
|
||||
// (not just unselect it), because the user never confirmed it via
|
||||
// the modal's Add Value button. Clicking Add Value keeps the chip
|
||||
// as a selected entry. These two tests pin both halves of the
|
||||
// contract so the screens stay in sync with the create-flow draft.
|
||||
describe("custom chip — confirmed vs dismissed", () => {
|
||||
// Use a label guaranteed to NOT collide with any preset value
|
||||
// (we'd otherwise get two matching chips and false positives).
|
||||
// The "Add value" control opens an empty custom-policy wizard. Dismissing
|
||||
// without Finalize leaves the chip list unchanged. Finalize writes a
|
||||
// selected chip named from the wizard title.
|
||||
describe("Add value wizard", () => {
|
||||
const CUSTOM_LABEL = "ZZTopBespokeValue";
|
||||
|
||||
async function addCustomChipNamed(label: string) {
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add value" }));
|
||||
const input = await screen.findByPlaceholderText("Type to add");
|
||||
fireEvent.change(input, { target: { value: label } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Confirm" }));
|
||||
return screen.findByRole("dialog");
|
||||
}
|
||||
|
||||
/**
|
||||
* The label can also appear in the modal header while the modal
|
||||
* is open, and as the chip's "Remove" button aria-label. Scope to
|
||||
@@ -290,33 +277,50 @@ describe("CoreValuesSelectScreen", () => {
|
||||
).length;
|
||||
}
|
||||
|
||||
it("removes the custom chip when its modal is dismissed without Add Value", async () => {
|
||||
renderWithProviders(<CoreValuesSelectScreen />);
|
||||
await addCustomChipNamed(CUSTOM_LABEL);
|
||||
expect(countCustomChips(CUSTOM_LABEL)).toBe(1);
|
||||
async function completeAddValueWizard(label: string) {
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add value" }));
|
||||
const nameInput = await screen.findByPlaceholderText("Policy name");
|
||||
fireEvent.change(nameInput, { target: { value: label } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Next" }));
|
||||
const descriptionInput =
|
||||
await screen.findByPlaceholderText("Policy description");
|
||||
fireEvent.change(descriptionInput, {
|
||||
target: { value: "A community-authored value." },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Next" }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Finalize" }));
|
||||
}
|
||||
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
// Chip must be gone — not just unselected. If it were merely
|
||||
// unselected the chip button would still render. Wrap in waitFor
|
||||
// because the chip removal flushes through `updateState` →
|
||||
// `useEffect` → `setCoreValueOptions` and isn't synchronous with
|
||||
// the dialog close.
|
||||
await waitFor(() => {
|
||||
expect(countCustomChips(CUSTOM_LABEL)).toBe(0);
|
||||
});
|
||||
it("opens the empty custom-policy wizard from Add value", async () => {
|
||||
renderWithProviders(<CoreValuesSelectScreen />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add value" }));
|
||||
expect(
|
||||
await screen.findByPlaceholderText("Policy name"),
|
||||
).toHaveValue("");
|
||||
expect(screen.queryByPlaceholderText("Type to add")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the custom chip selected when Add Value is clicked", async () => {
|
||||
it("leaves no chip when the Add value wizard is dismissed", async () => {
|
||||
renderWithProviders(<CoreValuesSelectScreen />);
|
||||
const dialog = await addCustomChipNamed(CUSTOM_LABEL);
|
||||
fireEvent.click(
|
||||
within(dialog).getByRole("button", { name: "Add Value" }),
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add value" }));
|
||||
await screen.findByPlaceholderText("Policy name");
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByPlaceholderText("Policy name"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
expect(countCustomChips(CUSTOM_LABEL)).toBe(0);
|
||||
expect(screen.queryByPlaceholderText("Type to add")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("adds a selected chip named from the wizard title after Finalize", async () => {
|
||||
renderWithProviders(<CoreValuesSelectScreen />);
|
||||
await completeAddValueWizard(CUSTOM_LABEL);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.queryByPlaceholderText("Policy name"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
expect(countCustomChips(CUSTOM_LABEL)).toBe(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user