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} />);
|
render(<QueryExecutionError error={error} />);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
expect(
|
expect(screen.getByRole("alert")).toBeInTheDocument();
|
||||||
screen.getByRole("heading", { name: /query execution failed/i }),
|
expect(screen.getByText(/query execution failed/i)).toBeInTheDocument();
|
||||||
).toBeInTheDocument();
|
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(/the attack paths query could not be executed/i),
|
screen.getByText(/the attack paths query could not be executed/i),
|
||||||
).toBeInTheDocument();
|
).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", () => {
|
describe("QueryParametersForm", () => {
|
||||||
it("uses the field description as the placeholder instead of rendering helper text below", () => {
|
it("uses the field description as the placeholder instead of rendering helper text below", () => {
|
||||||
// Given
|
// Given
|
||||||
@@ -73,40 +110,7 @@ describe("QueryParametersForm", () => {
|
|||||||
|
|
||||||
it("renders a textarea when the parameter input type is textarea", () => {
|
it("renders a textarea when the parameter input type is textarea", () => {
|
||||||
// Given
|
// Given
|
||||||
const customQuery: AttackPathQuery = {
|
render(<TestCustomQueryForm />);
|
||||||
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>,
|
|
||||||
);
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
const input = screen.getByRole("textbox", { name: /opencypher query/i });
|
const input = screen.getByRole("textbox", { name: /opencypher query/i });
|
||||||
|
|||||||
Reference in New Issue
Block a user