Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Oct 13, 2021
1 parent b113732 commit e523622
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ReactWrapper } from 'enzyme';
import { findTestSubject } from '@elastic/eui/lib/test';
import { Doc, DocProps } from './doc';
import { SEARCH_FIELDS_FROM_SOURCE as mockSearchFieldsFromSource } from '../../../../../common';
import { indexPatternMock } from '../../../../__mocks__/index_pattern';

const mockSearchApi = jest.fn();

Expand Down Expand Up @@ -74,21 +75,11 @@ const waitForPromises = async () =>
* this works but logs ugly error messages until we're using React 16.9
* should be adapted when we upgrade
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function mountDoc(update = false, indexPatternGetter: any = null) {
const indexPattern = {
getComputedFields: () => [],
};
const indexPatternService = {
get: indexPatternGetter ? indexPatternGetter : jest.fn(() => Promise.resolve(indexPattern)),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;

async function mountDoc(update = false) {
const props = {
id: '1',
index: 'index1',
indexPatternId: 'xyz',
indexPatternService,
indexPattern: indexPatternMock,
} as DocProps;
let comp!: ReactWrapper;
await act(async () => {
Expand All @@ -108,12 +99,6 @@ describe('Test of <Doc /> of Discover', () => {
expect(findTestSubject(comp, 'doc-msg-loading').length).toBe(1);
});

test('renders IndexPattern notFound msg', async () => {
const indexPatternGetter = jest.fn(() => Promise.reject({ savedObjectId: '007' }));
const comp = await mountDoc(true, indexPatternGetter);
expect(findTestSubject(comp, 'doc-msg-notFoundIndexPattern').length).toBe(1);
});

test('renders notFound msg', async () => {
mockSearchApi.mockImplementation(() => throwError({ status: 404 }));
const comp = await mountDoc(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import { DocViewerTab } from './doc_viewer_tab';
import { ElasticSearchHit } from '../../doc_views/doc_views_types';
import { indexPatternMock } from '../../../__mocks__/index_pattern';

describe('DocViewerTab', () => {
test('changing columns triggers an update', () => {
Expand All @@ -21,6 +22,7 @@ describe('DocViewerTab', () => {
renderProps: {
hit: {} as ElasticSearchHit,
columns: ['test'],
indexPattern: indexPatternMock,
},
};

Expand All @@ -31,6 +33,7 @@ describe('DocViewerTab', () => {
renderProps: {
hit: {} as ElasticSearchHit,
columns: ['test2'],
indexPattern: indexPatternMock,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DocViewerTableProps {
columns?: string[];
filter?: DocViewFilterFn;
hit: ElasticSearchHit;
indexPattern?: IndexPattern;
indexPattern: IndexPattern;
onAddColumn?: (columnName: string) => void;
onRemoveColumn?: (columnName: string) => void;
}
Expand Down

0 comments on commit e523622

Please sign in to comment.