Files
prowler/ui/components/layout/sidebar/submenu-item.test.tsx
T

77 lines
2.1 KiB
TypeScript

import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { SubmenuItem } from "./submenu-item";
vi.mock("next/navigation", () => ({
usePathname: () => "/",
}));
const TestIcon = ({ size = 16 }: { size?: number }) => (
<svg aria-hidden="true" height={size} width={size} />
);
describe("SubmenuItem", () => {
it("should show the cloud-only tooltip for disabled cloud menu items", async () => {
// Given
const user = userEvent.setup();
render(
<SubmenuItem
href="/alerts"
label="Alerts"
icon={TestIcon}
disabled
highlight
cloudOnly
/>,
);
// When
const button = screen.getByRole("button", { name: /alerts/i });
expect(button).toHaveAttribute("aria-disabled", "true");
expect(button).toHaveClass(
"cursor-not-allowed",
"text-text-neutral-tertiary",
);
await user.hover(button.parentElement as HTMLElement);
// Then
expect(screen.getByText("New")).toHaveClass("h-5", "text-[10px]");
expect(screen.queryByText("Cloud")).not.toBeInTheDocument();
expect(
await screen.findAllByText("Available in Prowler Cloud"),
).not.toHaveLength(0);
});
it("should render disabled Scan config menu items like disabled Alerts", async () => {
// Given
const user = userEvent.setup();
render(
<SubmenuItem
href="/scans/config"
label="Scan"
icon={TestIcon}
disabled
highlight
cloudOnly
/>,
);
// When
const button = screen.getByRole("button", { name: /scan/i });
await user.hover(button.parentElement as HTMLElement);
// Then
expect(button).toHaveAttribute("aria-disabled", "true");
expect(button).toHaveClass(
"cursor-not-allowed",
"text-text-neutral-tertiary",
);
expect(screen.getByText("New")).toHaveClass("h-5", "text-[10px]");
expect(
await screen.findAllByText("Available in Prowler Cloud"),
).not.toHaveLength(0);
});
});