The interface is now fully English regardless of the chat language (session titles stay in whatever language the user typed). Changed the right-rail subtitle to 'Datamart Builder with Human In The Loop'. Translated all chrome: new-question/settings dialogs, workflow phase strip (F1-F8), session rail, steer input, widgets (select/multiselect/freetext/fallback/reserved controls) and viewers (SQL, results, schema linking). Test matchers updated in lockstep. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import { render, screen, waitFor } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { SchemaLinkingViewer } from "./SchemaLinkingViewer";
|
|
|
|
vi.mock("./mermaid", () => ({
|
|
renderMermaid: vi.fn().mockResolvedValue('<svg data-testid="mm"></svg>'),
|
|
}));
|
|
|
|
const smallLinking = {
|
|
question: "quante ordini?",
|
|
candidates: [
|
|
{ kind: "table" as const, name: "orders", decision: "promoted" as const },
|
|
{ kind: "column" as const, name: "orders.id", decision: "promoted" as const },
|
|
{ kind: "table" as const, name: "users", decision: "excluded" as const },
|
|
],
|
|
joins: [{ from: "orders", to: "orders.id" }],
|
|
excluded: [{ kind: "table" as const, name: "users" }],
|
|
open_questions: [],
|
|
};
|
|
|
|
const bigLinking = {
|
|
question: "grossa query",
|
|
candidates: Array.from({ length: 46 }, (_, i) => ({
|
|
kind: "table" as const,
|
|
name: `table_${i}`,
|
|
decision: "promoted" as const,
|
|
})),
|
|
joins: [],
|
|
excluded: [],
|
|
open_questions: [],
|
|
};
|
|
|
|
test("(a) default renders the mermaid container (mocked svg appears)", async () => {
|
|
render(<SchemaLinkingViewer linking={smallLinking} />);
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId("mm")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
test("(b) clicking toggle switches to table listing a promoted table name", async () => {
|
|
render(<SchemaLinkingViewer linking={smallLinking} />);
|
|
// wait for mermaid to load
|
|
await waitFor(() => expect(screen.getByTestId("mm")).toBeInTheDocument());
|
|
|
|
const toggle = screen.getByRole("button", { name: /table/i });
|
|
await userEvent.click(toggle);
|
|
|
|
expect(screen.getByText("orders")).toBeInTheDocument();
|
|
expect(screen.queryByTestId("mm")).not.toBeInTheDocument();
|
|
});
|
|
|
|
test("(c) oversized linking (>45) shows cap notice", () => {
|
|
render(<SchemaLinkingViewer linking={bigLinking} />);
|
|
expect(
|
|
screen.getByText(/too many elements for the graph/i)
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
test("(d) ~10 promoted + ~50 excluded does NOT cap; graph is available", async () => {
|
|
const mixedLinking = {
|
|
question: "caso misto",
|
|
candidates: [
|
|
...Array.from({ length: 10 }, (_, i) => ({
|
|
kind: "table" as const,
|
|
name: `kept_${i}`,
|
|
decision: "promoted" as const,
|
|
})),
|
|
...Array.from({ length: 50 }, (_, i) => ({
|
|
kind: "table" as const,
|
|
name: `dropped_${i}`,
|
|
decision: "excluded" as const,
|
|
})),
|
|
],
|
|
joins: [],
|
|
excluded: [],
|
|
open_questions: [],
|
|
};
|
|
render(<SchemaLinkingViewer linking={mixedLinking} />);
|
|
expect(
|
|
screen.queryByText(/troppi elementi per il grafico/i)
|
|
).not.toBeInTheDocument();
|
|
// Grafico (mermaid) view is the default and renders the mocked svg.
|
|
await waitFor(() => expect(screen.getByTestId("mm")).toBeInTheDocument());
|
|
});
|