@@ -5,6 +5,7 @@ import React, { useState } from 'react';
5
5
import {
6
6
useInfiniteOffsetPaginationQuery ,
7
7
fetchOffsetPaginationHasMoreFallbackData ,
8
+ useInsertMutation ,
8
9
} from '../../src' ;
9
10
import type { Database } from '../database.types' ;
10
11
import { renderWithConfig } from '../utils' ;
@@ -221,4 +222,57 @@ describe('useInfiniteOffsetPaginationQuery', () => {
221
222
renderWithConfig ( < Page /> , { provider : ( ) => provider } ) ;
222
223
await screen . findByText ( contacts [ 0 ] . username ! , { } , { timeout : 10000 } ) ;
223
224
} ) ;
225
+
226
+ it ( 'revalidation should work' , async ( ) => {
227
+ function Page ( ) {
228
+ const [ success , setSuccess ] = useState ( false ) ;
229
+ const { currentPage, isLoading, setPage } =
230
+ useInfiniteOffsetPaginationQuery (
231
+ client
232
+ . from ( 'contact' )
233
+ . select ( 'id,username' )
234
+ . ilike ( 'username' , `${ testRunPrefix } %` )
235
+ . order ( 'username' , { ascending : true } ) ,
236
+ { pageSize : 1 , revalidateOnReconnect : true } ,
237
+ ) ;
238
+
239
+ const { trigger : insert } = useInsertMutation (
240
+ client . from ( 'contact_note' ) ,
241
+ [ 'id' ] ,
242
+ null ,
243
+ {
244
+ revalidateTables : [ { schema : 'public' , table : 'contact' } ] ,
245
+ onSuccess : ( ) => setSuccess ( true ) ,
246
+ onError : ( error ) => console . error ( error ) ,
247
+ } ,
248
+ ) ;
249
+
250
+ const contact = currentPage ?. [ 0 ] ;
251
+
252
+ return (
253
+ < div >
254
+ < div
255
+ data-testid = "revalidate"
256
+ onClick = { ( ) => insert ( [ { contact_id : contact ! . id , text : 'Test' } ] ) }
257
+ />
258
+ < div data-testid = "pages" >
259
+ { ( currentPage ?? [ ] ) [ 0 ] ?. username ?? 'undefined' }
260
+ </ div >
261
+ < div > { `isLoading: ${ isLoading } ` } </ div >
262
+ < div > { `success: ${ success } ` } </ div >
263
+ </ div >
264
+ ) ;
265
+ }
266
+
267
+ renderWithConfig ( < Page /> , { provider : ( ) => provider } ) ;
268
+ await screen . findByText ( 'isLoading: false' , { } , { timeout : 10000 } ) ;
269
+ await screen . findByText ( contacts [ 0 ] . username ! , { } , { timeout : 10000 } ) ;
270
+ fireEvent . click ( screen . getByTestId ( 'revalidate' ) ) ;
271
+ await screen . findByText ( 'success: true' , { } , { timeout : 10000 } ) ;
272
+ await screen . findByText (
273
+ `${ testRunPrefix } -username-1` ,
274
+ { } ,
275
+ { timeout : 10000 } ,
276
+ ) ;
277
+ } ) ;
224
278
} ) ;
0 commit comments