From ba1f243f3a2943dbb93a016937a44308b3f2624b Mon Sep 17 00:00:00 2001 From: "Hugo P.Brito" Date: Thu, 19 Mar 2026 16:10:20 +0000 Subject: [PATCH] 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 --- .../query-execution-error.test.tsx | 5 +- .../query-parameters-form.test.tsx | 72 ++++++++++--------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-execution-error.test.tsx b/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-execution-error.test.tsx index 560aa2d434..80863bd6bd 100644 --- a/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-execution-error.test.tsx +++ b/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-execution-error.test.tsx @@ -13,9 +13,8 @@ describe("QueryExecutionError", () => { render(); // 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(); diff --git a/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-parameters-form.test.tsx b/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-parameters-form.test.tsx index dff2b087bc..ad704f3d8f 100644 --- a/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-parameters-form.test.tsx +++ b/ui/app/(prowler)/attack-paths/(workflow)/query-builder/_components/query-parameters-form.test.tsx @@ -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 ( + + + + ); +} + 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( - - - , - ); + render(); // When const input = screen.getByRole("textbox", { name: /opencypher query/i });