Skip to content

Commit

Permalink
Fix even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Aug 4, 2022
1 parent c60a472 commit d5de72f
Showing 1 changed file with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FieldItem } from './field_item';
import { NoFieldsCallout } from './no_fields_callout';
import { act } from 'react-dom/test-utils';
import { coreMock } from '@kbn/core/public/mocks';
import { IndexPatternPrivateState } from './types';
import { IndexPattern, IndexPatternPrivateState } from './types';
import { mountWithIntl, shallowWithIntl } from '@kbn/test-jest-helpers';
import { EuiProgress, EuiLoadingSpinner } from '@elastic/eui';
import { documentField } from './document_field';
Expand Down Expand Up @@ -243,7 +243,7 @@ const initialState: IndexPatternPrivateState = {
isFirstExistenceFetch: false,
};

const dslQuery = { bool: { must: [], filter: [], should: [], must_not: [] } };
// const dslQuery = { bool: { must: [], filter: [], should: [], must_not: [] } };

// @ts-expect-error Portal mocks are notoriously difficult to type
ReactDOM.createPortal = jest.fn((element) => element);
Expand Down Expand Up @@ -340,34 +340,41 @@ describe('IndexPattern Data Panel', () => {
afterEach(() => {
getFieldsForIndexPattern.mockClear();
});

function testProps() {
const setState = jest.fn();
const fields = [{ name: 'field_1' } as DataViewField, { name: 'field_2' } as DataViewField];
const dataViewA = {
id: 'a',
title: 'aaa',
timeFieldName: 'atime',
fields,
getFieldByName: getFieldByNameFactory([]),
hasRestrictions: false,
} as unknown as IndexPattern;
const dataViewB = {
id: 'b',
title: 'bbb',
timeFieldName: 'btime',
fields,
getFieldByName: getFieldByNameFactory([]),
hasRestrictions: false,
} as unknown as IndexPattern;
const indexPatterns = {
a: {
id: 'a',
title: 'aaa',
timeFieldName: 'atime',
fields,
getFieldByName: getFieldByNameFactory([]),
hasRestrictions: false,
},
b: {
id: 'b',
title: 'bbb',
timeFieldName: 'btime',
fields,
getFieldByName: getFieldByNameFactory([]),
hasRestrictions: false,
},
a: dataViewA,
b: dataViewB,
};
return {
...defaultProps,
dataViews: {
...defaultProps.dataViews,
getFieldsForIndexPattern,
get: (id: string) => {
return Promise.resolve(indexPatterns[id]);
if (id === 'a') {
return Promise.resolve(dataViewA);
} else {
return Promise.resolve(dataViewB);
}
},
},
changeIndexPattern: jest.fn(),
Expand All @@ -390,7 +397,7 @@ describe('IndexPattern Data Panel', () => {
columns: {},
},
},
} as IndexPatternPrivateState,
} as unknown as IndexPatternPrivateState,
};
}

Expand Down Expand Up @@ -474,7 +481,7 @@ describe('IndexPattern Data Panel', () => {
dateRange: { fromDate: '2019-02-01', toDate: '2020-01-02' },
});

expect(setState).toHaveBeenCalledTimes(1);
expect(setState).toHaveBeenCalledTimes(2);
expect(getFieldsForIndexPattern).toHaveBeenCalledTimes(2);

expect(getFieldsForIndexPattern.mock.calls[0]).toMatchInlineSnapshot(`
Expand Down

0 comments on commit d5de72f

Please sign in to comment.