11import React from 'react' ;
22import { fireEvent , render } from '@testing-library/react' ;
3+ import { alert } from 'ant-design-testing' ;
34import '@testing-library/jest-dom/extend-expect' ;
45
56import SlidePane from '../index' ;
67
78describe ( 'test SlidePane ' , ( ) => {
89 test ( 'snapshot match' , ( ) => {
9- const wrapper = render ( < SlidePane visible > Hello World</ SlidePane > ) ;
10+ const wrapper = render ( < SlidePane open > Hello World</ SlidePane > ) ;
1011 expect ( wrapper ) . toMatchSnapshot ( ) ;
1112 } ) ;
12- test ( 'should be invisible ' , ( ) => {
13- const { container } = render ( < SlidePane visible = { false } > Hello World</ SlidePane > ) ;
13+ test ( 'should be not open ' , ( ) => {
14+ const { container } = render ( < SlidePane open = { false } > Hello World</ SlidePane > ) ;
1415 expect ( container ) . not . toHaveClass ( ) ;
1516 } ) ;
1617 test ( 'should render loading correct ' , ( ) => {
17- const { unmount } = render ( < SlidePane visible > Hello World</ SlidePane > ) ;
18+ const { unmount } = render ( < SlidePane open > Hello World</ SlidePane > ) ;
1819 const dom = document . querySelector ( '.ant-spin-spinning' ) ;
1920 expect ( dom ) . toBe ( null ) ;
2021 unmount ( ) ;
2122 render (
22- < SlidePane visible loading >
23+ < SlidePane open loading >
2324 Hello World
2425 </ SlidePane >
2526 ) ;
2627 const domLoading = document . querySelector ( '.ant-spin-spinning' ) ;
2728 expect ( domLoading ) . not . toBe ( null ) ;
2829 } ) ;
2930 test ( 'should render mask correct ' , ( ) => {
30- const { unmount } = render ( < SlidePane visible > Hello World</ SlidePane > ) ;
31+ const { unmount } = render ( < SlidePane open > Hello World</ SlidePane > ) ;
3132 const dom = document . querySelector ( '.dtc-slide-pane-mask' ) ;
3233 expect ( dom ) . toBe ( null ) ;
3334 unmount ( ) ;
3435 render (
35- < SlidePane visible mask >
36+ < SlidePane open mask >
3637 Hello World
3738 </ SlidePane >
3839 ) ;
@@ -41,18 +42,28 @@ describe('test SlidePane ', () => {
4142 } ) ;
4243 test ( 'should render width correct' , ( ) => {
4344 render (
44- < SlidePane visible width = { 640 } >
45+ < SlidePane open width = { 640 } >
4546 Hello World
4647 </ SlidePane >
4748 ) ;
4849 expect ( document . querySelector ( '.dtc-slide-pane-content-wrapper' ) ) . toHaveStyle ( {
4950 width : '640px' ,
5051 } ) ;
5152 } ) ;
53+ test ( 'should render size width correct' , ( ) => {
54+ render (
55+ < SlidePane open size = "large" >
56+ Hello World
57+ </ SlidePane >
58+ ) ;
59+ expect ( document . querySelector ( '.dtc-slide-pane-content-wrapper' ) ) . toHaveStyle ( {
60+ width : '1256px' ,
61+ } ) ;
62+ } ) ;
5263 test ( 'should render className/style correct' , ( ) => {
5364 const { unmount } = render (
5465 < SlidePane
55- visible
66+ open
5667 rootClassName = "root-className"
5768 bodyClassName = "body-className"
5869 rootStyle = { { color : 'red' } }
@@ -72,7 +83,7 @@ describe('test SlidePane ', () => {
7283 test ( 'should render tab correct' , ( ) => {
7384 const { getByText, unmount } = render (
7485 < SlidePane
75- visible
86+ open
7687 width = { 640 }
7788 tabs = { [
7889 { key : '1' , title : 'tab1' } ,
@@ -98,7 +109,7 @@ describe('test SlidePane ', () => {
98109
99110 const { getByText : getByText1 } = render (
100111 < SlidePane
101- visible
112+ open
102113 width = { 640 }
103114 tabs = { [
104115 { key : '1' , title : 'tab1' } ,
@@ -121,10 +132,38 @@ describe('test SlidePane ', () => {
121132 expect ( getByText1 ( '变更记录' ) ) . toBeTruthy ( ) ;
122133 expect ( getByText1 ( 'tab2' ) . parentNode ) . toHaveClass ( 'ant-tabs-tab-active' ) ;
123134 } ) ;
135+ test ( 'Should support string banner' , async ( ) => {
136+ const { getByText } = render (
137+ < SlidePane open banner = "banner" >
138+ Hello World
139+ </ SlidePane >
140+ ) ;
141+
142+ expect ( getByText ( 'banner' ) ) . toBeInTheDocument ( ) ;
143+ } ) ;
144+ test ( 'Should support ReactNode' , async ( ) => {
145+ const { getByTestId } = render (
146+ < SlidePane open banner = { < div data-testid = "banner" > xxxx</ div > } >
147+ test
148+ </ SlidePane >
149+ ) ;
150+
151+ expect ( getByTestId ( 'banner' ) ) . toBeInTheDocument ( ) ;
152+ } ) ;
153+ it ( 'Should support AlertProps' , async ( ) => {
154+ const { getByText } = render (
155+ < SlidePane open banner = { { message : 'banner' , type : 'error' } } >
156+ test
157+ </ SlidePane >
158+ ) ;
159+
160+ expect ( getByText ( 'banner' ) ) . toBeInTheDocument ( ) ;
161+ expect ( alert . query ( document ) ?. classList . contains ( 'ant-alert-error' ) ) . toBeTruthy ( ) ;
162+ } ) ;
124163 test ( 'should callback to be called' , ( ) => {
125164 const fn = jest . fn ( ) ;
126165 const { getByRole } = render (
127- < SlidePane visible onClose = { fn } >
166+ < SlidePane open onClose = { fn } >
128167 Hello World
129168 </ SlidePane >
130169 ) ;
0 commit comments