UNPKG

@navinc/base-react-components

Version:
50 lines 2.93 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { jsx as _jsx } from "react/jsx-runtime"; import { describe, expect, it, vi } from 'vitest'; import { screen } from '@testing-library/react'; import { renderWithContext } from './tests/with-app-context.js'; import { CardInsight } from './card-insight.js'; import userEvent from '@testing-library/user-event'; describe('<CardInsight />', () => { it('renders Link if an actionHref and actionLabel is supplied', () => __awaiter(void 0, void 0, void 0, function* () { const user = userEvent.setup(); const { history } = renderWithContext(_jsx(CardInsight, { actionHref: "/asdf", actionLabel: "asdf" })); yield user.click(screen.getByText(/asdf/i)); expect(history.location.pathname).toBe('/asdf'); })); it('renders Button if an action and actionLabel is supplied', () => __awaiter(void 0, void 0, void 0, function* () { const mockAction = vi.fn(); const user = userEvent.setup(); renderWithContext(_jsx(CardInsight, { action: mockAction, actionLabel: "Click me" })); yield user.click(screen.getByRole('button')); expect(mockAction).toHaveBeenCalled(); })); it('renders loading dots when action, actionLabel and isActionLoading are provided', () => { const mockAction = vi.fn(); renderWithContext(_jsx(CardInsight, { action: mockAction, actionLabel: "Click me", isActionLoading: true })); expect(screen.getByTestId('button-loading-dots')); }); it('does not render action when actionLabel is not supplied', () => { const mockAction = vi.fn(); renderWithContext(_jsx(CardInsight, { actionHref: "/test", action: mockAction })); expect(screen.queryByRole('button')).not.toBeInTheDocument(); expect(screen.queryByRole('link')).not.toBeInTheDocument(); }); it('renders the copy if copy is given', () => { renderWithContext(_jsx(CardInsight, { copy: "Beets" })); expect(screen.getByText(/beets/i)).toBeInTheDocument(); }); it('renders the title if a title is given', () => { renderWithContext(_jsx(CardInsight, { title: "Bears" })); expect(screen.getByText(/bears/i)).toBeInTheDocument(); }); }); //# sourceMappingURL=card-insight.spec.js.map