UNPKG

@navinc/base-react-components

Version:
58 lines 3.41 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 { renderWithContext } from './tests/with-app-context.js'; import { fireEvent, screen } from '@testing-library/react'; import { Banner } from './banner.js'; describe('Banner', () => { it('renders BannerContainer', () => { renderWithContext(_jsx(Banner, { children: "My Banner" })); expect(screen.getByText(/my banner/i)).toBeInTheDocument(); }); it('renders the supplied icon', () => __awaiter(void 0, void 0, void 0, function* () { renderWithContext(_jsx(Banner, { icon: "actions/minus", children: "My Banner" })); const icon = yield screen.findByTestId('banner-icon'); expect(icon).toBeInTheDocument(); })); it('renders an actionIcon with onClick of onDismiss if there is onDismiss', () => __awaiter(void 0, void 0, void 0, function* () { const onDismiss = vi.fn(); renderWithContext(_jsx(Banner, { onDismiss: onDismiss, children: "My Banner" })); const icon = yield screen.findByTestId('banner-dismiss'); fireEvent.click(icon); expect(onDismiss).toHaveBeenCalled(); })); it('renders the supplied actionIcon', () => __awaiter(void 0, void 0, void 0, function* () { renderWithContext(_jsx(Banner, { actionIcon: "actions/close", actionHref: "/asdf", children: "My Banner" })); const icon = yield screen.findByTestId('action-icon'); expect(icon).toBeInTheDocument(); })); it('renders the title and Copy component', () => { renderWithContext(_jsx(Banner, { actionIcon: "actions/close", title: "my title", children: "My Banner" })); expect(screen.getByText(/my title/i)).toBeInTheDocument(); }); it('renders the copy and Copy component', () => { renderWithContext(_jsx(Banner, { actionIcon: "actions/close", copy: "my copy" })); expect(screen.getByText(/my copy/i)).toBeInTheDocument(); }); it('renders a Link if there is an actionLabel and action', () => { renderWithContext(_jsx(Banner, { actionLabel: "action label", action: vi.fn() })); expect(screen.getByText(/action label/i)).toBeInTheDocument(); }); it('renders a Link if there is an actionHref and action', () => { renderWithContext(_jsx(Banner, { actionHref: "/action-href" })); expect(screen.getByRole('link')).toBeInTheDocument(); }); it('passes action props to underlying links', () => { renderWithContext(_jsx(Banner, { actionTarget: "_blank", actionHref: "/home", actionLabel: "action label" })); expect(screen.getByText(/action label/i).target).toBe('_blank'); }); }); //# sourceMappingURL=banner.spec.js.map