Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import ImpersonationBanner from "./components/impersonation-banner";
|
||||
|
||||
vi.mock("react-router", () => ({
|
||||
Form: ({ children, ...props }: React.ComponentProps<"form">) => <form {...props}>{children}</form>,
|
||||
}));
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
i18n: { language: "en" },
|
||||
t: (key: string) =>
|
||||
({
|
||||
"impersonation.active": "Impersonation active",
|
||||
"impersonation.actingAs": "Acting as {to} from {from}",
|
||||
"impersonation.exit": "Exit impersonation",
|
||||
"impersonation.ariaLabel": "Active impersonation session",
|
||||
})[key] ?? key,
|
||||
}),
|
||||
}));
|
||||
|
||||
type RootImpersonationBannerProps = {
|
||||
impersonatingSession: {
|
||||
fromUser: { email: string };
|
||||
toUser: { email: string };
|
||||
} | null;
|
||||
};
|
||||
|
||||
function RootImpersonationBanner({ impersonatingSession }: RootImpersonationBannerProps) {
|
||||
if (!impersonatingSession) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <ImpersonationBanner fromEmail={impersonatingSession.fromUser.email} toEmail={impersonatingSession.toUser.email} csrf="csrf-token" />;
|
||||
}
|
||||
|
||||
describe("root impersonation banner", () => {
|
||||
it("renders actor and target emails with a single exit action", () => {
|
||||
render(
|
||||
<RootImpersonationBanner
|
||||
impersonatingSession={{
|
||||
fromUser: { email: "admin@example.com" },
|
||||
toUser: { email: "member@example.com" },
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("impersonation-banner")).toHaveAttribute("role", "status");
|
||||
expect(screen.getByTestId("impersonation-banner")).toHaveTextContent("admin@example.com");
|
||||
expect(screen.getByTestId("impersonation-banner")).toHaveTextContent("member@example.com");
|
||||
expect(screen.getByRole("button", { name: "Exit impersonation" })).toHaveAttribute("type", "submit");
|
||||
expect(screen.getByRole("button", { name: "Exit impersonation" }).closest("form")).toHaveAttribute("action", "/logout");
|
||||
expect(screen.getByDisplayValue("csrf-token")).toHaveAttribute("name", "csrf");
|
||||
});
|
||||
|
||||
it("renders no banner marker when impersonation data is null", () => {
|
||||
render(<RootImpersonationBanner impersonatingSession={null} />);
|
||||
|
||||
expect(screen.queryByTestId("impersonation-banner")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user