From a57eafa030f56deafba0cd1519111ef31f53fee8 Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Thu, 10 Aug 2023 16:18:04 +0200 Subject: [PATCH] [Discover] Add a test for fetchMore --- .../layout/use_discover_histogram.test.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.test.tsx b/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.test.tsx index 2c082237fd4a0b..e4a2a674c0f772 100644 --- a/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.test.tsx +++ b/src/plugins/discover/public/application/main/components/layout/use_discover_histogram.test.tsx @@ -414,5 +414,37 @@ describe('useDiscoverHistogram', () => { }); expect(api.refetch).not.toHaveBeenCalled(); }); + + it('should skip the next refetch when fetching more', async () => { + const savedSearchFetch$ = new Subject<{ + options: { + reset: boolean; + fetchMore: boolean; + }; + searchSessionId: string; + }>(); + const stateContainer = getStateContainer(); + stateContainer.dataState.fetch$ = savedSearchFetch$; + const { hook } = await renderUseDiscoverHistogram({ stateContainer }); + const api = createMockUnifiedHistogramApi(); + act(() => { + hook.result.current.ref(api); + }); + act(() => { + savedSearchFetch$.next({ + options: { reset: false, fetchMore: true }, + searchSessionId: '1234', + }); + }); + expect(api.refetch).not.toHaveBeenCalled(); + + act(() => { + savedSearchFetch$.next({ + options: { reset: false, fetchMore: false }, + searchSessionId: '1234', + }); + }); + expect(api.refetch).toHaveBeenCalled(); + }); }); });