test(ui): fix attack paths query builder tests

- Assert the query error title as rendered by the alert component
- Move custom query form setup into a React test wrapper
This commit is contained in:
Hugo P.Brito
2026-03-19 16:10:20 +00:00
parent a1e48e6b84
commit ba1f243f3a
2 changed files with 40 additions and 37 deletions

View File

@@ -13,9 +13,8 @@ describe("QueryExecutionError", () => {
render(<QueryExecutionError error={error} />);
// Then
expect(
screen.getByRole("heading", { name: /query execution failed/i }),
).toBeInTheDocument();
expect(screen.getByRole("alert")).toBeInTheDocument();
expect(screen.getByText(/query execution failed/i)).toBeInTheDocument();
expect(
screen.getByText(/the attack paths query could not be executed/i),
).toBeInTheDocument();

View File

@@ -42,6 +42,43 @@ function TestForm() {
);
}
function TestCustomQueryForm() {
const customQuery: AttackPathQuery = {
type: "attack-paths-scans",
id: "custom-query",
attributes: {
name: "Custom openCypher query",
short_description: "Write your own openCypher query",
description: "Run a custom query against the graph.",
provider: "aws",
attribution: null,
parameters: [
{
name: "query",
label: "openCypher query",
data_type: "string",
input_type: "textarea",
placeholder: "MATCH (n) RETURN n LIMIT 25",
description: "",
required: true,
},
],
},
};
const form = useForm({
defaultValues: {
query: "",
},
});
return (
<FormProvider {...form}>
<QueryParametersForm selectedQuery={customQuery} />
</FormProvider>
);
}
describe("QueryParametersForm", () => {
it("uses the field description as the placeholder instead of rendering helper text below", () => {
// Given
@@ -73,40 +110,7 @@ describe("QueryParametersForm", () => {
it("renders a textarea when the parameter input type is textarea", () => {
// Given
const customQuery: AttackPathQuery = {
type: "attack-paths-scans",
id: "custom-query",
attributes: {
name: "Custom openCypher query",
short_description: "Write your own openCypher query",
description: "Run a custom query against the graph.",
provider: "aws",
attribution: null,
parameters: [
{
name: "query",
label: "openCypher query",
data_type: "string",
input_type: "textarea",
placeholder: "MATCH (n) RETURN n LIMIT 25",
description: "",
required: true,
},
],
},
};
const form = useForm({
defaultValues: {
query: "",
},
});
render(
<FormProvider {...form}>
<QueryParametersForm selectedQuery={customQuery} />
</FormProvider>,
);
render(<TestCustomQueryForm />);
// When
const input = screen.getByRole("textbox", { name: /opencypher query/i });