Skip to content

Commit

Permalink
tslint discover
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Sep 5, 2023
1 parent ee013d6 commit 243464b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SortDirection } from '@kbn/data-plugin/public';
import { createSearchSourceStub } from './_stubs';
import { fetchAnchor, updateSearchSource } from './anchor';
import { dataViewMock } from '@kbn/discover-utils/src/__mocks__';
import { searchResponseTimeoutWarningMock } from '@kbn/search-response-warnings/src/__mocks__/search_response_warnings';
import { searchResponseIncompleteWarningLocalCluster } from '@kbn/search-response-warnings/src/__mocks__/search_response_warnings';
import { savedSearchMock } from '../../../__mocks__/saved_search';
import { discoverServiceMock } from '../../../__mocks__/services';

Expand Down Expand Up @@ -206,7 +206,7 @@ describe('context app', function () {
).then(({ anchorRow, interceptedWarnings }) => {
expect(anchorRow).toHaveProperty('raw._id', '1');
expect(anchorRow).toHaveProperty('isAnchor', true);
expect(interceptedWarnings).toBeUndefined();
expect(interceptedWarnings).toEqual([]);
});
});

Expand All @@ -216,20 +216,10 @@ describe('context app', function () {
{ _id: '3', _index: 't' },
]);

const mockWarnings = [
{
originalWarning: searchResponseTimeoutWarningMock,
},
];

const services = discoverServiceMock;
services.data.search.showWarnings = jest.fn((adapter, callback) => {
// @ts-expect-error for empty meta
callback?.(mockWarnings[0].originalWarning, {});

// plus duplicates
// @ts-expect-error for empty meta
callback?.(mockWarnings[0].originalWarning, {});
callback?.(searchResponseIncompleteWarningLocalCluster, {});
});

return fetchAnchor(
Expand All @@ -242,7 +232,7 @@ describe('context app', function () {
).then(({ anchorRow, interceptedWarnings }) => {
expect(anchorRow).toHaveProperty('raw._id', '1');
expect(anchorRow).toHaveProperty('isAnchor', true);
expect(interceptedWarnings).toEqual(mockWarnings);
expect(interceptedWarnings.length).toBe(1);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { filter } from 'rxjs/operators';
import { dataViewMock, esHitsMockWithSort } from '@kbn/discover-utils/src/__mocks__';
import { buildDataTableRecord } from '@kbn/discover-utils';
import { searchResponseWarningsMock } from '@kbn/search-response-warnings/src/__mocks__/search_response_warnings';
import { searchResponseIncompleteWarningLocalCluster } from '@kbn/search-response-warnings/src/__mocks__/search_response_warnings';

describe('test useSavedSearch message generators', () => {
test('sendCompleteMsg', (done) => {
Expand Down Expand Up @@ -103,15 +103,15 @@ describe('test useSavedSearch message generators', () => {
if (value.fetchStatus !== FetchStatus.LOADING_MORE) {
expect(value.fetchStatus).toBe(FetchStatus.COMPLETE);
expect(value.result).toStrictEqual([...initialRecords, ...moreRecords]);
expect(value.interceptedWarnings).toHaveLength(searchResponseWarningsMock.length);
expect(value.interceptedWarnings).toHaveLength(1);
done();
}
});
sendLoadingMoreFinishedMsg(documents$, {
moreRecords,
interceptedWarnings: searchResponseWarningsMock.map((warning) => ({
originalWarning: warning,
})),
interceptedWarnings: [
{ originalWarning: searchResponseIncompleteWarningLocalCluster }
],
});
});
test('sendLoadingMoreFinishedMsg after an exception', (done) => {
Expand All @@ -121,9 +121,9 @@ describe('test useSavedSearch message generators', () => {
const documents$ = new BehaviorSubject<DataDocumentsMsg>({
fetchStatus: FetchStatus.LOADING_MORE,
result: initialRecords,
interceptedWarnings: searchResponseWarningsMock.map((warning) => ({
originalWarning: warning,
})),
interceptedWarnings: [
{ originalWarning: searchResponseIncompleteWarningLocalCluster }
],
});
documents$.subscribe((value) => {
if (value.fetchStatus !== FetchStatus.LOADING_MORE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { fetchDocuments } from './fetch_documents';
import { fetchTextBased } from './fetch_text_based';
import { buildDataTableRecord } from '@kbn/discover-utils';
import { dataViewMock, esHitsMockWithSort } from '@kbn/discover-utils/src/__mocks__';
import { searchResponseWarningsMock } from '@kbn/search-response-warnings/src/__mocks__/search_response_warnings';
import { searchResponseIncompleteWarningLocalCluster } from '@kbn/search-response-warnings/src/__mocks__/search_response_warnings';

jest.mock('./fetch_documents', () => ({
fetchDocuments: jest.fn().mockResolvedValue([]),
Expand Down Expand Up @@ -296,9 +296,9 @@ describe('test fetchAll', () => {
const initialRecords = [records[0], records[1]];
const moreRecords = [records[2], records[3]];

const interceptedWarnings = searchResponseWarningsMock.map((warning) => ({
originalWarning: warning,
}));
const interceptedWarnings = [{
originalWarning: searchResponseIncompleteWarningLocalCluster,
}];

test('should add more records', async () => {
const collectDocuments = subjectCollector(subjects.documents$);
Expand Down

0 comments on commit 243464b

Please sign in to comment.