UNPKG

@navinc/base-react-components

Version:
55 lines 3.34 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, waitFor, screen } from '@testing-library/react'; import { BannerToast } from './banner-toast.js'; import userEvent from '@testing-library/user-event'; describe('<BannerToast />', () => { it('stops/starts animating when moused over/out then dismisses', () => __awaiter(void 0, void 0, void 0, function* () { const time = 500; const onDismiss = vi.fn(); renderWithContext(_jsx(BannerToast, { onDismiss: onDismiss, time: time })); const timedBar = screen.getByTestId('BannerToast:AnimationBar'); yield userEvent.hover(timedBar); expect(timedBar).toHaveStyle({ animationPlayState: 'paused' }); yield userEvent.unhover(timedBar); expect(timedBar).toHaveStyle({ animationPlayState: 'running' }); fireEvent.animationEnd(timedBar); yield waitFor(() => expect(onDismiss).toHaveBeenCalled()); })); it('does not time out when shouldNotTimeout is set', () => __awaiter(void 0, void 0, void 0, function* () { const time = 500; const onDismiss = vi.fn(); // TODO: shouldNotTimeout shouldn't need to also include shouldShowTimedBar={false} renderWithContext(_jsx(BannerToast, { onDismiss: onDismiss, time: time, shouldNotTimeout: true, shouldShowTimedBar: false })); expect(screen.queryByTestId('BannerToast:AnimationBar')).not.toBeInTheDocument(); })); it('dismisses the banner on user action when shouldNotTimeout is set', () => __awaiter(void 0, void 0, void 0, function* () { const time = 500; const onDismiss = vi.fn(); renderWithContext(_jsx(BannerToast, { onDismiss: onDismiss, time: time, shouldNotTimeout: true })); const icon = yield screen.findByTestId('banner-dismiss'); yield userEvent.click(icon); expect(onDismiss).toHaveBeenCalled(); })); it(`doesn't allow the banner to be dismissed on user action if shouldNotTimeout is not set`, () => { const time = 500; const onDismiss = vi.fn(); renderWithContext(_jsx(BannerToast, { onDismiss: onDismiss, time: time })); expect(screen.queryByTestId('banner-dismiss')).not.toBeInTheDocument(); }); it('hides the timed bar if the shouldShowTimedBar prop is false', () => { renderWithContext(_jsx(BannerToast, { shouldShowTimedBar: false })); expect(screen.queryByTestId('BannerToast:AnimationBar')).not.toBeInTheDocument(); }); }); //# sourceMappingURL=banner-toast.spec.js.map