UNPKG

@cainiaofe/cn-ui-m

Version:
28 lines (27 loc) 1.57 kB
import React from 'react'; import { render, screen, fireEvent } from '@testing-library/react'; import { CnNotice } from '../index'; describe('CnNotice', function () { test('renders the notice with correct content', function () { render(React.createElement(CnNotice, { content: "This is a notice" })); expect(screen.getByText('This is a notice')).toBeInTheDocument(); }); test('renders the notice with close button', function () { render(React.createElement(CnNotice, { content: "This is a notice", closeable: true })); expect(screen.getByTestId('cn-notice-close-button')).toBeInTheDocument(); }); test('calls onClose when close button is clicked', function () { var handleClose = jest.fn(); render(React.createElement(CnNotice, { content: "This is a notice", closeable: true, onClose: handleClose })); fireEvent.click(screen.getByTestId('cn-notice-close-button')); expect(handleClose).toHaveBeenCalled(); }); test('renders the notice with correct icon', function () { var container = render(React.createElement(CnNotice, { content: "This is a notice", type: "notice" })).container; expect(container.querySelector('.cn-ui-m-notice')).toBeInTheDocument(); }); test('renders the notice with hidden overflow style', function () { var container = render(React.createElement(CnNotice, { content: "This is a notice", overflowStyle: "hidden" })).container; expect(container.querySelector('.cn-ui-m-notice-hidden')).toBeInTheDocument(); }); });