@@ -235,6 +235,70 @@ describe('generic selector queries', () => {
235235 }
236236 )
237237
238+ it . each ( [ true , false , undefined ] ) (
239+ 'preserves flat selector truncation %s and clears it after a complete refetch' ,
240+ async ( truncated ) => {
241+ const items = [ { id : 'label-1' , label : 'First label' } ]
242+ mockExecuteSelectorRequest . mockResolvedValue ( {
243+ kind : 'list' ,
244+ items,
245+ ...( truncated !== undefined ? { truncated } : { } ) ,
246+ } )
247+ const hook = renderHookWithClient ( ( ) =>
248+ useSelectorOptions ( 'gmail.labels' , {
249+ context : { workspaceId : 'workspace-1' , oauthCredential : 'credential-1' } ,
250+ surfaceId : 'connector:gmail:label' ,
251+ } )
252+ )
253+
254+ await waitFor ( ( ) => expect ( hook . getResult ( ) . isSuccess ) . toBe ( true ) )
255+ expect ( hook . getResult ( ) ) . toMatchObject ( {
256+ data : items ,
257+ hasMore : false ,
258+ truncated : truncated === true ,
259+ } )
260+
261+ const refreshedItems = [ { id : 'label-2' , label : 'Complete results' } ]
262+ mockExecuteSelectorRequest . mockResolvedValue ( { kind : 'list' , items : refreshedItems } )
263+ act ( ( ) => hook . getResult ( ) . refetch ( ) )
264+
265+ await waitFor ( ( ) => expect ( hook . getResult ( ) . data ) . toEqual ( refreshedItems ) )
266+ expect ( hook . getResult ( ) ) . toMatchObject ( { hasMore : false , truncated : false } )
267+ }
268+ )
269+
270+ it ( 'retains server truncation from earlier pages after loading the final page' , async ( ) => {
271+ mockExecuteSelectorRequest . mockImplementation (
272+ async ( { request } : { request : { cursor ?: string } } ) =>
273+ request . cursor
274+ ? { kind : 'list' , items : [ { id : 'workspace-2' , label : 'Second' } ] , truncated : false }
275+ : {
276+ kind : 'list' ,
277+ items : [ { id : 'workspace-1' , label : 'First' } ] ,
278+ nextCursor : 'next-page' ,
279+ truncated : true ,
280+ }
281+ )
282+ const hook = renderHookWithClient ( ( ) =>
283+ useSelectorOptions ( 'bitbucket.workspaces' , {
284+ context : { workspaceId : 'workspace-1' , oauthCredential : 'credential-1' } ,
285+ surfaceId : 'canvas:block-1:workspace' ,
286+ } )
287+ )
288+
289+ await waitFor ( ( ) => expect ( hook . getResult ( ) . hasMore ) . toBe ( true ) )
290+ expect ( hook . getResult ( ) . truncated ) . toBe ( true )
291+
292+ act ( ( ) => hook . getResult ( ) . loadMore ( ) )
293+ await waitFor ( ( ) =>
294+ expect ( hook . getResult ( ) . data ) . toEqual ( [
295+ { id : 'workspace-1' , label : 'First' } ,
296+ { id : 'workspace-2' , label : 'Second' } ,
297+ ] )
298+ )
299+ expect ( hook . getResult ( ) ) . toMatchObject ( { hasMore : false , truncated : true } )
300+ } )
301+
238302 it ( 'loads paginated selectors on demand without putting cursors in the base key' , async ( ) => {
239303 mockExecuteSelectorRequest . mockImplementation (
240304 async ( { request } : { request : { cursor ?: string } } ) =>
0 commit comments