UNPKG

@cainiaofe/cn-ui-m

Version:
59 lines (58 loc) 2.77 kB
import React from 'react'; import { render } from '@testing-library/react'; import { CnSearch } from '../index'; describe('CnSearch', function () { test('renders without error', function () { var container = render(React.createElement(CnSearch, null)).container; expect(container).toBeInTheDocument(); }); // test('calls onSearch callback with input value when search button is clicked', () => { // const onSearch = jest.fn(); // const { getByText, getByPlaceholderText } = render( // <CnSearch onSearch={onSearch} showSearchButton />, // ); // const input = getByPlaceholderText('Please enter the search content'); // const searchButton = getByText('搜索'); // fireEvent.change(input, { target: { value: 'example' } }); // fireEvent.click(searchButton); // // expect(onSearch).toHaveBeenCalledWith('example'); // expect(onSearch).toHaveBeenCalledTimes(1); // }); // test('calls onCancel callback when cancel button is clicked', () => { // const onCancel = jest.fn(); // const { getByText, getByPlaceholderText } = render( // <CnSearch showCancelMode="always" onCancel={onCancel} />, // ); // const input = getByPlaceholderText('Please enter the search content'); // const cancelButton = getByText('Cancel'); // fireEvent.change(input, { target: { value: 'example' } }); // fireEvent.click(cancelButton); // expect(onCancel).toHaveBeenCalledTimes(1); // }); // test('clears input value when clear button is clicked', () => { // const { getByPlaceholderText, container } = render( // <CnSearch hasClear defaultValue="12121" />, // ); // const input = getByPlaceholderText('Please enter the search content'); // const clearButton = container.querySelector('.cn-ui-m-input--icon-clear'); // expect(clearButton).toBeInTheDocument(); // fireEvent.click(clearButton); // waitFor(() => { // expect(input.value).toBe(''); // }); // }); // test('calls onFocus callback when input is focused', () => { // const onFocus = jest.fn(); // const { getByPlaceholderText } = render(<CnSearch onFocus={onFocus} />); // const input = getByPlaceholderText('Please enter the search content'); // fireEvent.focus(input); // expect(onFocus).toHaveBeenCalled(); // }); // test('calls onBlur callback when input is blurred', () => { // const onBlur = jest.fn(); // const { getByPlaceholderText } = render(<CnSearch onBlur={onBlur} />); // const input = getByPlaceholderText('Please enter the search content'); // fireEvent.blur(input); // expect(onBlur).toHaveBeenCalled(); // }); });