feat(web): UserMenu (email/role + sign out) + HeaderSearch components (#54)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { server } from "../test/server";
|
||||
import { renderApp } from "../test/render";
|
||||
import { UserMenu } from "./user-menu";
|
||||
|
||||
test("shows the signed-in email on the trigger", async () => {
|
||||
renderApp(<UserMenu />);
|
||||
expect(await screen.findByText("editor@example.com")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("opens the menu showing email + role and signs out", async () => {
|
||||
let loggedOut = false;
|
||||
server.use(
|
||||
http.post("/api/admin/logout", () => {
|
||||
loggedOut = true;
|
||||
return new HttpResponse(null, { status: 204 });
|
||||
}),
|
||||
);
|
||||
|
||||
renderApp(<UserMenu />);
|
||||
|
||||
const trigger = await screen.findByRole("button", { name: /editor@example.com/ });
|
||||
await userEvent.click(trigger);
|
||||
|
||||
// Menu content renders in a portal on document.body.
|
||||
const menu = within(document.body);
|
||||
expect(await menu.findByText("editor")).toBeInTheDocument();
|
||||
const signOut = await menu.findByText("Sign out");
|
||||
|
||||
await userEvent.click(signOut);
|
||||
await waitFor(() => expect(loggedOut).toBe(true));
|
||||
});
|
||||
Reference in New Issue
Block a user