@@ -5,6 +5,7 @@ import { render, waitFor } from '@testing-library/react';
55import {
66 type CreateResult ,
77 DataProviderContext ,
8+ type MutationMode ,
89 type RaRecord ,
910 type UpdateResult ,
1011 testDataProvider ,
@@ -142,9 +143,15 @@ test.each([
142143 } ) ;
143144} ) ;
144145
145- test . each ( [ { name : 'Required' } , null ] ) (
146- 'notification handling on validation errors (%s)' ,
147- async ( submissionErrors ) => {
146+ test . each `
147+ submissionErrors | mutationMode | shouldNotify
148+ ${ { name : 'Required' } } | ${ 'pessimistic' } | ${ false }
149+ ${ { name : 'Required' } } | ${ 'optimistic' } | ${ true }
150+ ${ { name : 'Required' } } | ${ 'undoable' } | ${ true }
151+ ${ null } | ${ 'pessimistic' } | ${ true }
152+ ` (
153+ 'notification handling on validation errors ($submissionErrors, $mutationMode)' ,
154+ async ( { submissionErrors, mutationMode, shouldNotify } ) => {
148155 const { default : useOnSubmit } = await import ( './useOnSubmit.js' ) ;
149156 notify . mockClear ( ) ;
150157 dataProvider . create = jest . fn ( ( ) =>
@@ -155,6 +162,7 @@ test.each([{ name: 'Required' }, null])(
155162 const Dummy = ( ) => {
156163 const onSubmit = useOnSubmit ( {
157164 ...onSubmitProps ,
165+ mutationMode : mutationMode as MutationMode ,
158166 schemaAnalyzer : {
159167 ...onSubmitProps . schemaAnalyzer ,
160168 getSubmissionErrors : ( ) => submissionErrors ,
@@ -182,7 +190,7 @@ test.each([{ name: 'Required' }, null])(
182190 await waitFor ( ( ) => {
183191 expect ( dataProvider . create ) . toHaveBeenCalled ( ) ;
184192 } ) ;
185- ( submissionErrors ? expect ( notify ) . not : expect ( notify ) ) . toHaveBeenCalled ( ) ;
193+ ( shouldNotify ? expect ( notify ) : expect ( notify ) . not ) . toHaveBeenCalled ( ) ;
186194 expect ( errors ) . toEqual ( submissionErrors ?? { } ) ;
187195 } ,
188196) ;
0 commit comments