UNPKG

@cainiaofe/cn-ui-m

Version:
39 lines (38 loc) 2.04 kB
import React from 'react'; import { render, screen } from '@testing-library/react'; import { CnSelect, CnSelectOption } from '../index'; describe('CnSelect', function () { test('renders the component', function () { var container = render(React.createElement(CnSelect, null)).container; expect(container).toBeInTheDocument(); }); // test('updates the value on selection', () => { // const { getByText } = render( // <CnSelect placeholder="右对齐" align="right"> // <CnSelectOption value={1}>选项 1</CnSelectOption> // <CnSelectOption value={2}>选项 2</CnSelectOption> // <CnSelectOption value={3}>选项 3</CnSelectOption> // </CnSelect>, // ); // const selectInput = getByText('右对齐'); // // Simulate selection // fireEvent.click(selectInput); // expect(screen.getByText('选项 1')).toBeInTheDocument(); // // Simulate selection // fireEvent.click(screen.getByText('选项 2')); // expect(screen.getByText('选项 2')).toBeInTheDocument(); // }); test('renders the preview element in read-only mode', function () { render(React.createElement(CnSelect, { placeholder: "\u8BF7\u9009\u62E9", value: 2, readOnly: true }, React.createElement(CnSelectOption, { value: 1 }, "\u9009\u9879 1"), React.createElement(CnSelectOption, { value: 2 }, "\u9009\u9879 2(\u6B63\u5E38)"), React.createElement(CnSelectOption, { value: 3 }, "\u9009\u9879 3"))); // Assert that the preview element is rendered expect(screen.getByText('选项 2(正常)')).toBeInTheDocument(); }); test('renders the custom preview element', function () { render(React.createElement(CnSelect, { isPreview: true, renderPreview: function () { return React.createElement("span", null, "Custom Preview"); } })); // Assert that the custom preview element is rendered expect(screen.getByText('Custom Preview')).toBeInTheDocument(); }); });