@@ -10,7 +10,13 @@ describe('SchemaDescriptionField', () => {
1010 const { getByText, getByRole, queryByText } = render (
1111 < MockedProvider mocks = { mocks } addTypename = { false } >
1212 < TestPageContainer >
13- < SchemaDescriptionField description = "test description updated" isEdited onUpdate = { async ( ) => { } } />
13+ < SchemaDescriptionField
14+ expanded
15+ onExpanded = { ( ) => { } }
16+ description = "test description updated"
17+ isEdited
18+ onUpdate = { async ( ) => { } }
19+ /> { ' ' }
1420 </ TestPageContainer >
1521 </ MockedProvider > ,
1622 ) ;
@@ -24,6 +30,8 @@ describe('SchemaDescriptionField', () => {
2430 < MockedProvider mocks = { mocks } addTypename = { false } >
2531 < TestPageContainer >
2632 < SchemaDescriptionField
33+ expanded
34+ onExpanded = { ( ) => { } }
2735 description = "test description"
2836 original = "test description"
2937 isEdited
@@ -44,42 +52,51 @@ describe('SchemaDescriptionField', () => {
4452
4553 it ( 'renders short messages without show more / show less' , ( ) => {
4654 const { getByText, queryByText } = render (
47- < SchemaDescriptionField description = "short description" onUpdate = { ( ) => Promise . resolve ( ) } /> ,
55+ < SchemaDescriptionField
56+ expanded
57+ onExpanded = { ( ) => { } }
58+ description = "short description"
59+ onUpdate = { ( ) => Promise . resolve ( ) }
60+ /> ,
4861 ) ;
4962 expect ( getByText ( 'short description' ) ) . toBeInTheDocument ( ) ;
5063 expect ( queryByText ( 'Read Less' ) ) . not . toBeInTheDocument ( ) ;
5164 expect ( queryByText ( 'Read More' ) ) . not . toBeInTheDocument ( ) ;
5265 } ) ;
5366
54- it ( 'renders longer messages with show more / show less' , ( ) => {
67+ describe ( 'renders longer messages with show more / show less' , ( ) => {
5568 const longDescription =
5669 'really long description over 80 characters, really long description over 80 characters, really long description over 80 characters, really long description over 80 characters, really long description over 80 characters' ;
57- const { getByText, queryByText } = render (
58- < SchemaDescriptionField description = { longDescription } onUpdate = { ( ) => Promise . resolve ( ) } /> ,
59- ) ;
60- expect ( getByText ( 'Read More' ) ) . toBeInTheDocument ( ) ;
61- expect ( queryByText ( longDescription ) ) . not . toBeInTheDocument ( ) ;
62-
63- fireEvent (
64- getByText ( 'Read More' ) ,
65- new MouseEvent ( 'click' , {
66- bubbles : true ,
67- cancelable : true ,
68- } ) ,
69- ) ;
70-
71- expect ( getByText ( longDescription ) ) . toBeInTheDocument ( ) ;
72- expect ( getByText ( 'Read Less' ) ) . toBeInTheDocument ( ) ;
73-
74- fireEvent (
75- getByText ( 'Read Less' ) ,
76- new MouseEvent ( 'click' , {
77- bubbles : true ,
78- cancelable : true ,
79- } ) ,
80- ) ;
70+ it ( 'renders longer messages with show more when not expanded' , ( ) => {
71+ const onClick = jest . fn ( ) ;
72+ const { getByText, queryByText } = render (
73+ < SchemaDescriptionField
74+ expanded = { false }
75+ onExpanded = { onClick }
76+ description = { longDescription }
77+ onUpdate = { ( ) => Promise . resolve ( ) }
78+ /> ,
79+ ) ;
80+ expect ( getByText ( 'Read More' ) ) . toBeInTheDocument ( ) ;
81+ expect ( queryByText ( longDescription ) ) . not . toBeInTheDocument ( ) ;
82+ fireEvent . click ( getByText ( 'Read More' ) ) ;
83+ expect ( onClick ) . toHaveBeenCalled ( ) ;
84+ } ) ;
8185
82- expect ( getByText ( 'Read More' ) ) . toBeInTheDocument ( ) ;
83- expect ( queryByText ( longDescription ) ) . not . toBeInTheDocument ( ) ;
86+ it ( 'renders longer messages with show less when expanded' , ( ) => {
87+ const onClick = jest . fn ( ) ;
88+ const { getByText } = render (
89+ < SchemaDescriptionField
90+ expanded
91+ onExpanded = { onClick }
92+ description = { longDescription }
93+ onUpdate = { ( ) => Promise . resolve ( ) }
94+ /> ,
95+ ) ;
96+ expect ( getByText ( longDescription ) ) . toBeInTheDocument ( ) ;
97+ expect ( getByText ( 'Read Less' ) ) . toBeInTheDocument ( ) ;
98+ fireEvent . click ( getByText ( 'Read Less' ) ) ;
99+ expect ( onClick ) . toHaveBeenCalled ( ) ;
100+ } ) ;
84101 } ) ;
85102} ) ;
0 commit comments