UNPKG

@octopusdeploy/design-system-components

Version:
54 lines (53 loc) 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const testing_library_1 = require("@octopusdeploy/testing-library"); const react_1 = require("@testing-library/react"); const vitest_1 = require("vitest"); const InlineSnackbar_1 = require("../InlineSnackbar"); (0, vitest_1.describe)("InlineSnackbar", () => { (0, vitest_1.it)("display string content", () => { const interactions = renderInlineSnackbar({ content: "text content" }); interactions.shouldHaveText("text content"); }); (0, vitest_1.it)("displays ReactNode content", () => { const interactions = renderInlineSnackbar({ content: (0, jsx_runtime_1.jsx)("h2", { children: "heading content" }) }); interactions.shouldHaveHeading("heading content"); }); (0, vitest_1.it)("calls onClose", () => { vitest_1.vi.useFakeTimers(); const interactions = renderInlineSnackbar({ autoHideDuration: 1000 }); interactions.shouldNotHaveCalledOnClose(); vitest_1.vi.runAllTimers(); interactions.shouldHaveCalledOnClose(); vitest_1.vi.useRealTimers(); }); (0, vitest_1.it)("does not call onClose without autoHideDuration", () => { vitest_1.vi.useFakeTimers(); const interactions = renderInlineSnackbar({}); vitest_1.vi.runAllTimers(); interactions.shouldNotHaveCalledOnClose(); vitest_1.vi.useRealTimers(); }); }); function renderInlineSnackbar({ autoHideDuration, content }) { const onClose = vitest_1.vi.fn(); (0, react_1.render)((0, jsx_runtime_1.jsx)(InlineSnackbar_1.InlineSnackbar, { show: true, autoHideDuration: autoHideDuration, content: content ?? "default message", onClose: onClose, variant: "neutral" })); return getInteractions(onClose); } function getInteractions(onClose) { return { shouldHaveCalledOnClose: () => { (0, vitest_1.expect)(onClose).toHaveBeenCalledTimes(1); }, shouldNotHaveCalledOnClose: () => { (0, vitest_1.expect)(onClose).not.toHaveBeenCalled(); }, shouldHaveText: (text) => { (0, vitest_1.expect)(react_1.screen.getByText(text)).toBeInTheDocument(); }, shouldHaveHeading: (text) => { testing_library_1.domQueries.getHeading(text).assertIsInTheDocument(); }, }; }