@cainiaofe/cn-ui-m
Version:
43 lines (42 loc) • 2.58 kB
JavaScript
import React from 'react';
import { render } from '@testing-library/react';
import { CnResult } from '../index';
describe('CnResult', function () {
it('renders without errors', function () {
var container = render(React.createElement(CnResult, { type: "success" })).container;
expect(container).toBeInTheDocument();
});
it('renders the correct icon based on the provided type and icon props', function () {
var container = render(React.createElement(CnResult, { type: "messageEmpty" })).container;
expect(container.firstChild).toHaveClass(' cn-result-type-messageEmpty');
});
it('renders the correct title and subtitle based on the provided type prop', function () {
var getByText = render(React.createElement(CnResult, { title: "\u6807\u9898", subTitle: React.createElement("div", null, "\u95EE\u95EE\u7B97\u7B97\u7B97"), type: "error" })).getByText;
expect(getByText('标题')).toBeInTheDocument();
expect(getByText('问问算算算')).toBeInTheDocument();
});
it('renders the extra content if provided', function () {
var getByText = render(React.createElement(CnResult, { extra: React.createElement("button", null, "Retry") })).getByText;
expect(getByText('Retry')).toBeInTheDocument();
});
it('renders the children content if provided', function () {
var getByText = render(React.createElement(CnResult, null, "Custom content")).getByText;
expect(getByText('Custom content')).toBeInTheDocument();
});
it('applies the provided className prop', function () {
var container = render(React.createElement(CnResult, { className: "custom-class" })).container;
expect(container.firstChild).toHaveClass('custom-class');
});
it('applies the correct type and mode class names based on the provided props', function () {
var container = render(React.createElement(CnResult, { type: "warning", mode: "inline" })).container;
expect(container.firstChild).toHaveClass('cn-result-type-warning');
expect(container.firstChild).toHaveClass('cn-result-mode-inline');
});
it('passes down any additional props to the root element', function () {
var getByTestId = render(React.createElement(CnResult, { "data-testid": "test" })).getByTestId;
expect(getByTestId('test')).toBeInTheDocument();
});
it('throws an error if an invalid type prop is provided', function () {
expect(function () { return render(React.createElement(CnResult, { type: "invalid" })); }).toThrow();
});
});