|
| 1 | +import React from 'react'; |
| 2 | +import { render } from '@testing-library/react'; |
| 3 | +import { Circle, type ProgressProps } from '../src'; |
| 4 | + |
| 5 | +describe('Semantic', () => { |
| 6 | + describe('Circle', () => { |
| 7 | + function test( |
| 8 | + name: string, |
| 9 | + props: Partial<ProgressProps> = {}, |
| 10 | + postCallback?: (cotainer: HTMLElement) => void, |
| 11 | + ) { |
| 12 | + it(name, () => { |
| 13 | + const classNames: ProgressProps['classNames'] = { |
| 14 | + root: 'my-root', |
| 15 | + rail: 'my-rail', |
| 16 | + track: 'my-track', |
| 17 | + }; |
| 18 | + const styles = { |
| 19 | + root: { background: 'red' }, |
| 20 | + rail: { background: 'blue' }, |
| 21 | + track: { background: 'green' }, |
| 22 | + }; |
| 23 | + |
| 24 | + const { container } = render( |
| 25 | + <Circle percent={50} classNames={classNames} styles={styles} {...props} />, |
| 26 | + ); |
| 27 | + |
| 28 | + expect(container.querySelector('.rc-progress-circle')).toHaveClass(classNames.root); |
| 29 | + expect(container.querySelector('.rc-progress-circle-trail')).toHaveClass(classNames.rail); |
| 30 | + expect(container.querySelector('.rc-progress-circle-path')).toHaveClass(classNames.track); |
| 31 | + |
| 32 | + expect(container.querySelector('.my-root')).toHaveStyle(styles.root); |
| 33 | + expect(container.querySelector('.my-rail')).toHaveStyle(styles.rail); |
| 34 | + expect(container.querySelector('.my-track')).toHaveStyle(styles.track); |
| 35 | + |
| 36 | + postCallback?.(container); |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + test('basic'); |
| 41 | + |
| 42 | + test( |
| 43 | + 'gradient', |
| 44 | + { |
| 45 | + strokeColor: { |
| 46 | + '0%': '#f00', |
| 47 | + '100%': '#0f0', |
| 48 | + }, |
| 49 | + }, |
| 50 | + (container) => { |
| 51 | + expect(container.querySelector('foreignObject')).toBeTruthy(); |
| 52 | + }, |
| 53 | + ); |
| 54 | + }); |
| 55 | +}); |
0 commit comments