feat(frontend): schema-linking gate widget with staged column curation
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { SchemaLinkingGateWidget } from "./SchemaLinkingGateWidget";
|
||||
import type { WidgetDescriptor } from "../api/types";
|
||||
|
||||
const descriptor: WidgetDescriptor = {
|
||||
id: "u7",
|
||||
widget: "schema-linking",
|
||||
title: "F4 — Schema linking",
|
||||
tables: [
|
||||
{
|
||||
id: "t-pat",
|
||||
name: "dim_patient",
|
||||
kind: "promote",
|
||||
recommended: true,
|
||||
description: "Anagrafica",
|
||||
rationale: "Output paziente",
|
||||
columns: [
|
||||
{ name: "cod_paz", description: "Codice", suggested: true },
|
||||
{ name: "nome", description: "Nome", suggested: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "x-sub",
|
||||
name: "fact_sostituzione",
|
||||
kind: "exclude",
|
||||
recommended: true,
|
||||
description: "Sostituzione",
|
||||
rationale: "Non impianto iniziale",
|
||||
columns: [{ name: "cod_paz" }],
|
||||
},
|
||||
],
|
||||
reserved: ["back", "exit", "other"],
|
||||
};
|
||||
|
||||
test("Confirm emits enacted tables with suggested columns (catalog order)", async () => {
|
||||
const onRespond = vi.fn();
|
||||
render(<SchemaLinkingGateWidget descriptor={descriptor} onRespond={onRespond} />);
|
||||
await userEvent.click(screen.getByRole("button", { name: /confirm/i }));
|
||||
expect(onRespond).toHaveBeenCalledWith({
|
||||
id: "u7",
|
||||
kind: "schema-linking",
|
||||
tables: [
|
||||
{ id: "t-pat", enacted: true, columns: ["cod_paz"] },
|
||||
{ id: "x-sub", enacted: true },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("selecting a column in the modal adds it to the response", async () => {
|
||||
const onRespond = vi.fn();
|
||||
render(<SchemaLinkingGateWidget descriptor={descriptor} onRespond={onRespond} />);
|
||||
// dim_patient starts with 1 suggested of 2 -> its button reads "Colonne 1/2".
|
||||
await userEvent.click(screen.getByRole("button", { name: /colonne 1\/2/i }));
|
||||
await userEvent.click(screen.getByRole("checkbox", { name: "nome" }));
|
||||
await userEvent.click(screen.getByRole("button", { name: /close/i })); // dialog X button
|
||||
await userEvent.click(screen.getByRole("button", { name: /confirm/i }));
|
||||
expect(onRespond).toHaveBeenCalledWith({
|
||||
id: "u7",
|
||||
kind: "schema-linking",
|
||||
tables: [
|
||||
{ id: "t-pat", enacted: true, columns: ["cod_paz", "nome"] },
|
||||
{ id: "x-sub", enacted: true },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("declining a table's enact checkbox drops its columns", async () => {
|
||||
const onRespond = vi.fn();
|
||||
render(<SchemaLinkingGateWidget descriptor={descriptor} onRespond={onRespond} />);
|
||||
await userEvent.click(screen.getByRole("checkbox", { name: /dim_patient/i }));
|
||||
await userEvent.click(screen.getByRole("button", { name: /confirm/i }));
|
||||
expect(onRespond).toHaveBeenCalledWith({
|
||||
id: "u7",
|
||||
kind: "schema-linking",
|
||||
tables: [
|
||||
{ id: "t-pat", enacted: false },
|
||||
{ id: "x-sub", enacted: true },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("reserved control emits control", async () => {
|
||||
const onRespond = vi.fn();
|
||||
render(<SchemaLinkingGateWidget descriptor={descriptor} onRespond={onRespond} />);
|
||||
await userEvent.click(screen.getByRole("button", { name: /go back/i }));
|
||||
expect(onRespond).toHaveBeenCalledWith({ id: "u7", control: "back" });
|
||||
});
|
||||
Reference in New Issue
Block a user