@etsoo/toolpad
Version:
Dashboard framework extention based on Toolpad Core
53 lines (52 loc) • 3.65 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const vitest_1 = require("vitest");
const react_1 = require("@testing-library/react");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
const AccountPreview_1 = require("./AccountPreview");
const AppProviderComponent_1 = require("../AppProvider/AppProviderComponent");
(0, vitest_1.describe)("AccountPreview", () => {
const auth = { signIn: vitest_1.vi.fn(), signOut: vitest_1.vi.fn() };
const session = {
user: {
name: "John Doe",
email: "john@example.com",
image: "https://example.com/avatar.jpg"
}
};
(0, vitest_1.test)("renders nothing when no session is provided", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(AppProviderComponent_1.AppProvider, { authentication: auth, children: (0, jsx_runtime_1.jsx)(AccountPreview_1.AccountPreview, {}) }));
(0, vitest_1.expect)(react_1.screen.queryByRole("button")).not.toBeInTheDocument();
});
(0, vitest_1.test)("displays condensed variant by default", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(AppProviderComponent_1.AppProvider, { authentication: auth, session: session, children: (0, jsx_runtime_1.jsx)(AccountPreview_1.AccountPreview, {}) }));
const avatar = react_1.screen.getByRole("img", { name: "John Doe" });
(0, vitest_1.expect)(avatar).toBeInTheDocument();
(0, vitest_1.expect)(react_1.screen.queryByText("John Doe")).not.toBeInTheDocument();
(0, vitest_1.expect)(avatar).toHaveAttribute("src", "https://example.com/avatar.jpg");
});
(0, vitest_1.test)("displays user name, email, and avatar in expanded variant", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(AppProviderComponent_1.AppProvider, { authentication: auth, session: session, children: (0, jsx_runtime_1.jsx)(AccountPreview_1.AccountPreview, { variant: "expanded" }) }));
(0, vitest_1.expect)(react_1.screen.getByText("John Doe")).toBeInTheDocument();
(0, vitest_1.expect)(react_1.screen.getByText("john@example.com")).toBeInTheDocument();
(0, vitest_1.expect)(react_1.screen.getByRole("img", { name: "John Doe" })).toBeInTheDocument();
});
(0, vitest_1.test)("calls handleClick when more icon button is clicked in expanded variant", async () => {
const handleClick = vitest_1.vi.fn();
(0, react_1.render)((0, jsx_runtime_1.jsx)(AppProviderComponent_1.AppProvider, { authentication: auth, session: session, children: (0, jsx_runtime_1.jsx)(AccountPreview_1.AccountPreview, { variant: "expanded", handleClick: handleClick }) }));
const moreButton = react_1.screen.getByRole("button");
await user_event_1.default.click(moreButton);
(0, vitest_1.expect)(handleClick).toHaveBeenCalled();
});
(0, vitest_1.test)("calls handleClick when avatar is clicked in condensed variant", async () => {
const handleClick = vitest_1.vi.fn();
(0, react_1.render)((0, jsx_runtime_1.jsx)(AppProviderComponent_1.AppProvider, { authentication: auth, session: session, children: (0, jsx_runtime_1.jsx)(AccountPreview_1.AccountPreview, { handleClick: handleClick }) }));
const avatarButton = react_1.screen.getByRole("button", { name: "Current User" });
await user_event_1.default.click(avatarButton);
(0, vitest_1.expect)(handleClick).toHaveBeenCalled();
});
});