@@ -13,11 +13,64 @@ test('should render different height and color when use color height props', asy
1313 < Progress percent = { 50 } color = "blue" strokeWidth = "20" />
1414 )
1515 const inner = container . querySelector ( '.nut-progress-inner' )
16- expect ( inner ?. getAttribute ( 'style' ) ) . toBe ( 'width: 50%; background: blue;' )
16+ expect ( inner ?. getAttribute ( 'style' ) ) . toBe (
17+ 'width: 50%; background: blue; transition: width 300ms ease-in-out;'
18+ )
1719} )
1820
1921test ( 'should show percent when use showText props' , ( ) => {
2022 const { container } = render ( < Progress percent = { 30 } showText /> )
2123 const text = container . querySelector ( '.nut-progress-text' )
2224 expect ( text ) . toBeTruthy ( )
2325} )
26+ test ( 'should render with custom style props' , ( ) => {
27+ const { container } = render (
28+ < Progress percent = { 50 } borderRadius = "8px" fontSize = "16px" showText />
29+ )
30+ const inner = container . querySelector ( '.nut-progress-text' )
31+ expect ( inner ) . toHaveStyle ( {
32+ fontSize : '16px' ,
33+ } )
34+ const outerDiv = container . querySelector ( '.nut-progress-outer' )
35+ expect ( outerDiv ) . toHaveStyle ( {
36+ borderRadius : '8px' ,
37+ } )
38+ } )
39+
40+ test ( 'should handle animation mode and duration' , ( ) => {
41+ const onActiveEndMock = vi . fn ( )
42+ const { container, rerender } = render (
43+ < Progress
44+ percent = { 30 }
45+ activeMode = "backwards"
46+ duration = { 500 }
47+ onActiveEnd = { onActiveEndMock }
48+ />
49+ )
50+
51+ const inner = container . querySelector ( '.nut-progress-inner' )
52+ expect ( inner ?. getAttribute ( 'style' ) ) . toContain (
53+ 'transition: width 500ms ease-in-out'
54+ )
55+
56+ // 测试动画完成回调
57+ rerender (
58+ < Progress
59+ percent = { 100 }
60+ activeMode = "backwards"
61+ duration = { 500 }
62+ onActiveEnd = { onActiveEndMock }
63+ />
64+ )
65+ setTimeout ( ( ) => {
66+ expect ( onActiveEndMock ) . toHaveBeenCalled ( )
67+ } , 600 )
68+ } )
69+
70+ test ( 'should render with aria-label' , ( ) => {
71+ const { container } = render (
72+ < Progress percent = { 50 } ariaLabel = "当前进度50%" />
73+ )
74+ const progressDiv = container . querySelector ( '.nut-progress' )
75+ expect ( progressDiv ?. getAttribute ( 'aria-label' ) ) . toBe ( '当前进度50%' )
76+ } )
0 commit comments