mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-31 15:54:24 +00:00
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { useForm } from "react-hook-form";
|
|
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
|
|
import { getScheduleFormDefaults } from "@/lib/schedules";
|
|
import type { ScheduleFormValues } from "@/types/schedules";
|
|
|
|
import { ScanScheduleFields } from "./scan-schedule-fields";
|
|
|
|
beforeAll(() => {
|
|
Object.defineProperty(HTMLElement.prototype, "hasPointerCapture", {
|
|
configurable: true,
|
|
value: vi.fn(() => false),
|
|
});
|
|
Object.defineProperty(HTMLElement.prototype, "setPointerCapture", {
|
|
configurable: true,
|
|
value: vi.fn(),
|
|
});
|
|
Object.defineProperty(HTMLElement.prototype, "releasePointerCapture", {
|
|
configurable: true,
|
|
value: vi.fn(),
|
|
});
|
|
Object.defineProperty(HTMLElement.prototype, "scrollIntoView", {
|
|
configurable: true,
|
|
value: vi.fn(),
|
|
});
|
|
});
|
|
|
|
function ScheduleFieldsHarness() {
|
|
const form = useForm<ScheduleFormValues>({
|
|
defaultValues: getScheduleFormDefaults(),
|
|
});
|
|
|
|
return (
|
|
<ScanScheduleFields
|
|
form={form}
|
|
showNextScheduledCopy
|
|
canUseAdvancedSchedule
|
|
/>
|
|
);
|
|
}
|
|
|
|
function getHelperCopy(text: RegExp) {
|
|
return screen.getByText((_, element) => {
|
|
return (
|
|
element?.tagName.toLowerCase() === "p" &&
|
|
text.test(element.textContent ?? "")
|
|
);
|
|
});
|
|
}
|
|
|
|
describe("ScanScheduleFields", () => {
|
|
it("updates the helper copy when the cadence changes to interval", async () => {
|
|
// Given
|
|
const user = userEvent.setup();
|
|
render(<ScheduleFieldsHarness />);
|
|
|
|
expect(getHelperCopy(/Daily/)).toBeInTheDocument();
|
|
|
|
// When
|
|
await user.click(screen.getByRole("combobox", { name: /repeats/i }));
|
|
await user.click(screen.getByRole("option", { name: /every 48 hours/i }));
|
|
|
|
// Then
|
|
expect(getHelperCopy(/Every 48 hours/)).toBeInTheDocument();
|
|
expect(
|
|
screen.queryByText((_, element) => {
|
|
return (
|
|
element?.tagName.toLowerCase() === "p" &&
|
|
/Daily/.test(element.textContent ?? "")
|
|
);
|
|
}),
|
|
).not.toBeInTheDocument();
|
|
});
|
|
});
|