Skip to content

Commit

Permalink
fix jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Aug 11, 2020
1 parent 58af035 commit 631f21d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,47 @@ import { DocViewTable } from './table';
import { indexPatterns, IndexPattern } from '../../../../../data/public';

const indexPattern = {
fields: [
{
name: '_index',
type: 'string',
scripted: false,
filterable: true,
},
{
name: 'message',
type: 'string',
scripted: false,
filterable: false,
},
{
name: 'extension',
type: 'string',
scripted: false,
filterable: true,
},
{
name: 'bytes',
type: 'number',
scripted: false,
filterable: true,
},
{
name: 'scripted',
type: 'number',
scripted: true,
filterable: false,
},
],
fields: {
getAll: () => [
{
name: '_index',
type: 'string',
scripted: false,
filterable: true,
},
{
name: 'message',
type: 'string',
scripted: false,
filterable: false,
},
{
name: 'extension',
type: 'string',
scripted: false,
filterable: true,
},
{
name: 'bytes',
type: 'number',
scripted: false,
filterable: true,
},
{
name: 'scripted',
type: 'number',
scripted: true,
filterable: false,
},
],
},
metaFields: ['_index', '_score'],
flattenHit: undefined,
formatHit: jest.fn((hit) => hit._source),
} as IndexPattern;

indexPattern.fields.getByName = (name: string) => {
return indexPattern.fields.find((field) => field.name === name);
return indexPattern.fields.getAll().find((field) => field.name === name);
};

indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
* under the License.
*/

import {
IndexPattern,
IndexPatternField,
IIndexPatternFieldList,
FieldFormatInstanceType,
} from 'src/plugins/data/public';
import { IndexPattern, IndexPatternField, FieldFormatInstanceType } from 'src/plugins/data/public';

jest.mock('brace/mode/groovy', () => ({}));

Expand Down Expand Up @@ -71,15 +66,19 @@ jest.mock('./components/field_format_editor', () => ({
FieldFormatEditor: 'field-format-editor',
}));

const fields: IndexPatternField[] = [
const fieldList = [
{
name: 'foobar',
} as IndexPatternField,
];

const fields = {
getAll: () => fieldList,
};

// @ts-ignore
fields.getByName = (name: string) => {
return fields.find((field) => field.name === name);
return fields.getAll().find((field) => field.name === name);
};

class Format {
Expand Down Expand Up @@ -112,7 +111,7 @@ describe('FieldEditor', () => {

beforeEach(() => {
indexPattern = ({
fields: fields as IIndexPatternFieldList,
fields,
getFormatterForField: () => ({ params: () => ({}) }),
} as unknown) as IndexPattern;
});
Expand All @@ -139,7 +138,7 @@ describe('FieldEditor', () => {
name: 'test',
script: 'doc.test.value',
};
indexPattern.fields.push(testField as IndexPatternField);
fieldList.push(testField as IndexPatternField);
indexPattern.fields.getByName = (name) => {
const flds = {
[testField.name]: testField,
Expand Down Expand Up @@ -169,7 +168,7 @@ describe('FieldEditor', () => {
script: 'doc.test.value',
lang: 'testlang',
};
indexPattern.fields.push((testField as unknown) as IndexPatternField);
fieldList.push((testField as unknown) as IndexPatternField);
indexPattern.fields.getByName = (name) => {
const flds = {
[testField.name]: testField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fields.push({ name: 'myField' } as any);
fields.getByName = (name: any) => {
return fields.find(({ name: n }: { name: string }) => n === name);
};
fields.getAll = () => [...fields];

export const getDepsMock = ({
searchSource = {
Expand Down

0 comments on commit 631f21d

Please sign in to comment.