@@ -5,9 +5,12 @@ import Descriptions from '../index';
55describe ( '<Descriptions />' , ( ) => {
66 it ( 'should match the snapshot' , ( ) => {
77 const { asFragment } = render (
8- < Descriptions >
8+ < Descriptions title = "Profile" footer = "Footer" >
99 < Descriptions . Item label = "Name" > John</ Descriptions . Item >
1010 < Descriptions . Item label = "Age" > 30</ Descriptions . Item >
11+ < Descriptions . Item label = "Address" span = "fill" >
12+ Sydney
13+ </ Descriptions . Item >
1114 </ Descriptions >
1215 ) ;
1316 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
@@ -20,15 +23,18 @@ describe('<Descriptions />', () => {
2023 </ Descriptions >
2124 ) ;
2225 expect ( container . firstChild ) . toHaveClass ( 'ty-descriptions' ) ;
26+ expect ( container . querySelector ( 'dl' ) ) . toBeInTheDocument ( ) ;
2327 } ) ;
2428
25- it ( 'should render title ' , ( ) => {
29+ it ( 'should render header and footer ' , ( ) => {
2630 const { getByText } = render (
27- < Descriptions title = "User Info" >
31+ < Descriptions title = "User Info" extra = { < button > Action </ button > } footer = "Summary footer" >
2832 < Descriptions . Item label = "Name" > John</ Descriptions . Item >
2933 </ Descriptions >
3034 ) ;
3135 expect ( getByText ( 'User Info' ) ) . toBeInTheDocument ( ) ;
36+ expect ( getByText ( 'Action' ) ) . toBeInTheDocument ( ) ;
37+ expect ( getByText ( 'Summary footer' ) ) . toBeInTheDocument ( ) ;
3238 } ) ;
3339
3440 it ( 'should render items' , ( ) => {
@@ -40,4 +46,34 @@ describe('<Descriptions />', () => {
4046 expect ( getByText ( 'Name' ) ) . toBeInTheDocument ( ) ;
4147 expect ( getByText ( 'John' ) ) . toBeInTheDocument ( ) ;
4248 } ) ;
49+
50+ it ( 'should render items from items prop' , ( ) => {
51+ const { getByText } = render (
52+ < Descriptions
53+ items = { [
54+ { key : 'name' , label : 'Name' , content : 'John' } ,
55+ { key : 'role' , label : 'Role' , content : 'Maintainer' } ,
56+ ] }
57+ />
58+ ) ;
59+
60+ expect ( getByText ( 'Name' ) ) . toBeInTheDocument ( ) ;
61+ expect ( getByText ( 'Maintainer' ) ) . toBeInTheDocument ( ) ;
62+ } ) ;
63+
64+ it ( 'should use table semantic when bordered' , ( ) => {
65+ const { container } = render (
66+ < Descriptions bordered items = { [ { key : 'name' , label : 'Name' , content : 'John' } ] } />
67+ ) ;
68+
69+ expect ( container . querySelector ( 'table' ) ) . toBeInTheDocument ( ) ;
70+ } ) ;
71+
72+ it ( 'should render empty placeholder for nullish content' , ( ) => {
73+ const { getByText } = render (
74+ < Descriptions items = { [ { key : 'name' , label : 'Name' , content : null } ] } empty = "Pending" />
75+ ) ;
76+
77+ expect ( getByText ( 'Pending' ) ) . toBeInTheDocument ( ) ;
78+ } ) ;
4379} ) ;
0 commit comments