Skip to content

Commit

Permalink
[Behavioral Analytics] Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yansavitski committed Apr 24, 2023
1 parent 5b808c5 commit f7f29ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ describe('FetchAnalyticsCollectionsApiLogic', () => {
http.get.mockReturnValue(promise);
const result = fetchAnalyticsCollections({});
await nextTick();
expect(http.get).toHaveBeenCalledWith('/internal/enterprise_search/analytics/collections');
expect(http.get).toHaveBeenCalledWith('/internal/enterprise_search/analytics/collections', {
query: { query: '' },
});
await expect(result).resolves.toEqual([{ name: 'result' }]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import { LogicMounter } from '../../../__mocks__/kea_logic';

import { nextTick } from '@kbn/test-jest-helpers';

import { KibanaLogic } from '../../../shared/kibana/kibana_logic';

import {
Expand Down Expand Up @@ -38,13 +40,18 @@ describe('AnalyticsCollectionExplorerTablesLogic', () => {
});

const defaultProps = {
dataView: null,
isLoading: false,
items: [],
pageIndex: 0,
pageSize: 10,
search: '',
selectedTable: null,
sorting: null,
timeRange: {
from: 'now-7d',
to: 'now',
},
totalItemsCount: 0,
};

Expand Down Expand Up @@ -79,6 +86,10 @@ describe('AnalyticsCollectionExplorerTablesLogic', () => {
});

describe('isLoading', () => {
beforeEach(() => {
mount({ selectedTable: ExploreTables.TopReferrers });
});

it('should handle onTableChange', () => {
AnalyticsCollectionExploreTableLogic.actions.onTableChange({
page: { index: 2, size: 10 },
Expand Down Expand Up @@ -241,11 +252,15 @@ describe('AnalyticsCollectionExplorerTablesLogic', () => {
});
});

it('should fetch items when search changes', () => {
it('should fetch items when search changes', async () => {
jest.useFakeTimers({ legacyFakeTimers: true });
AnalyticsCollectionExploreTableLogic.actions.setSelectedTable(ExploreTables.WorsePerformers);
(KibanaLogic.values.data.search.search as jest.Mock).mockClear();

AnalyticsCollectionExploreTableLogic.actions.setSearch('test');
jest.advanceTimersByTime(200);
await nextTick();

expect(KibanaLogic.values.data.search.search).toHaveBeenCalledWith(expect.any(Object), {
indexPattern: undefined,
sessionId: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ export const AnalyticsCollectionExploreTableLogic = kea<
listeners: ({ actions, values }) => {
const fetchItems = () => {
if (values.selectedTable === null || !(values.selectedTable in tablesParams)) {
actions.setItems([]);
actions.setTotalItemsCount(0);

return;
}

Expand Down

0 comments on commit f7f29ae

Please sign in to comment.