@cainiaofe/cn-ui-m
Version:
22 lines (21 loc) • 1.04 kB
JavaScript
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { CnRating } from '../index';
describe('CnRating', function () {
it('should render the component correctly', function () {
var container = render(React.createElement(CnRating, null)).container;
expect(container).toBeInTheDocument();
});
it('should set the initial value correctly', function () {
var container = render(React.createElement(CnRating, { defaultValue: 3 })).container;
var stars = container.querySelectorAll('.cn-ui-m-rating-star-active');
expect(stars.length).toBe(3);
});
it('should not update the value on click when readOnly is true', function () {
var handleChange = jest.fn();
var container = render(React.createElement(CnRating, { onChange: handleChange, readOnly: true })).container;
var star = container.querySelector('.cn-ui-m-rating-star');
fireEvent.click(star);
expect(handleChange).not.toHaveBeenCalled();
});
});