From 3ecb6158cbf35321acc5b161288c6c9ba8d05801 Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 16 Feb 2021 17:11:35 +0200 Subject: [PATCH] fix jest --- .../autocomplete/providers/value_suggestion_provider.test.ts | 2 +- .../autocomplete/providers/value_suggestion_provider.ts | 2 +- .../__snapshots__/suggestions_component.test.tsx.snap | 4 ++++ .../data/public/ui/typeahead/suggestions_component.test.tsx | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts index 23fc9f5405aea..a7b1bd2c7839d 100644 --- a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts +++ b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts @@ -18,7 +18,7 @@ describe('FieldSuggestions', () => { beforeEach(() => { const uiSettings = { get: (key: string) => shouldSuggestValues } as IUiSettingsClient; - http = { fetch: jest.fn() }; + http = { fetch: jest.fn().mockResolvedValue([]) }; getValueSuggestions = setupValueSuggestionProvider({ http, uiSettings } as CoreSetup, { timefilter: ({ diff --git a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts index 032861070c708..b8af6ad3a99e5 100644 --- a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts +++ b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts @@ -48,7 +48,6 @@ export const setupValueSuggestionProvider = ( }: { timefilter: TimefilterSetup; usageCollector?: AutocompleteUsageCollector } ): ValueSuggestionsGetFn => { function resolver(title: string, field: IFieldType, query: string, filters: any[]) { - usageCollector?.trackCall(); // Only cache results for a minute const ttl = Math.floor(Date.now() / 1000 / 60); return [ttl, query, title, field.name, JSON.stringify(filters)].join('|'); @@ -98,6 +97,7 @@ export const setupValueSuggestionProvider = ( const filterQuery = timeFilter ? buildQueryFromFilters([timeFilter], indexPattern).filter : []; const filters = [...(boolFilter ? boolFilter : []), ...filterQuery]; try { + usageCollector?.trackCall(); return await requestSuggestions(title, field, query, filters, signal); } catch (e) { if (!signal?.aborted) { diff --git a/src/plugins/data/public/ui/typeahead/__snapshots__/suggestions_component.test.tsx.snap b/src/plugins/data/public/ui/typeahead/__snapshots__/suggestions_component.test.tsx.snap index 2fa7834872f6b..9185e6a77d102 100644 --- a/src/plugins/data/public/ui/typeahead/__snapshots__/suggestions_component.test.tsx.snap +++ b/src/plugins/data/public/ui/typeahead/__snapshots__/suggestions_component.test.tsx.snap @@ -22,6 +22,7 @@ exports[`SuggestionsComponent Passing the index should control which suggestion > { component.find(SuggestionComponent).at(1).simulate('click'); expect(mockCallback).toHaveBeenCalledTimes(1); - expect(mockCallback).toHaveBeenCalledWith(mockSuggestions[1]); + expect(mockCallback).toHaveBeenCalledWith(mockSuggestions[1], 1); }); it('Should call onMouseEnter with the index of the suggestion that was entered', () => {