@@ -108,7 +108,37 @@ describe('<TabbedForm />', () => {
108
108
expect ( tabs [ 1 ] . classList . contains ( 'error' ) ) . toEqual ( true ) ;
109
109
} ) ;
110
110
111
- it ( 'should not set the style of an active Tab button with errors' , ( ) => {
111
+ it ( 'should set the style of an active Tab button with errors' , ( ) => {
112
+ const { getAllByRole, getByLabelText } = renderWithRedux (
113
+ < MemoryRouter initialEntries = { [ '/posts/1' ] } initialIndex = { 0 } >
114
+ < SaveContextProvider value = { saveContextValue } >
115
+ < TabbedForm
116
+ classes = { { errorTabButton : 'error' } }
117
+ resource = "posts"
118
+ >
119
+ < FormTab label = "tab1" >
120
+ < TextInput source = "title" validate = { required ( ) } />
121
+ </ FormTab >
122
+ < FormTab label = "tab2" >
123
+ < TextInput
124
+ source = "description"
125
+ validate = { required ( ) }
126
+ />
127
+ </ FormTab >
128
+ </ TabbedForm >
129
+ </ SaveContextProvider >
130
+ </ MemoryRouter >
131
+ ) ;
132
+
133
+ const tabs = getAllByRole ( 'tab' ) ;
134
+ fireEvent . click ( tabs [ 1 ] ) ;
135
+ const input = getByLabelText ( 'resources.posts.fields.description *' ) ;
136
+ fireEvent . blur ( input ) ;
137
+ expect ( tabs [ 0 ] . classList . contains ( 'error' ) ) . toEqual ( false ) ;
138
+ expect ( tabs [ 1 ] . classList . contains ( 'error' ) ) . toEqual ( true ) ;
139
+ } ) ;
140
+
141
+ it ( 'should set the style of any Tab button with errors on submit' , ( ) => {
112
142
const { getAllByRole, getByLabelText } = renderWithRedux (
113
143
< MemoryRouter initialEntries = { [ '/posts/1' ] } initialIndex = { 0 } >
114
144
< SaveContextProvider value = { saveContextValue } >
@@ -133,9 +163,10 @@ describe('<TabbedForm />', () => {
133
163
const tabs = getAllByRole ( 'tab' ) ;
134
164
fireEvent . click ( tabs [ 1 ] ) ;
135
165
const input = getByLabelText ( 'resources.posts.fields.description' ) ;
136
- fireEvent . change ( input , { target : { value : 'foo' } } ) ;
137
166
fireEvent . blur ( input ) ;
138
- expect ( tabs [ 0 ] . classList . contains ( 'error' ) ) . toEqual ( false ) ;
167
+ fireEvent . change ( input , { target : { value : 'fooooooooo' } } ) ;
168
+ fireEvent . click ( getByLabelText ( 'ra.action.save' ) ) ;
169
+ expect ( tabs [ 0 ] . classList . contains ( 'error' ) ) . toEqual ( true ) ;
139
170
expect ( tabs [ 1 ] . classList . contains ( 'error' ) ) . toEqual ( false ) ;
140
171
} ) ;
141
172
0 commit comments