mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-03-21 18:58:04 +00:00
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:
@@ -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();
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user