diff --git a/src/plugins/discover/public/application/components/table/table.test.tsx b/src/plugins/discover/public/application/components/table/table.test.tsx index 0793072fd0cf46..29659b39693656 100644 --- a/src/plugins/discover/public/application/components/table/table.test.tsx +++ b/src/plugins/discover/public/application/components/table/table.test.tsx @@ -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); diff --git a/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap b/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap index c22160bc4036d8..3f4190eed91707 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap +++ b/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap @@ -25,11 +25,10 @@ exports[`FieldEditor should render create new scripted field correctly 1`] = ` executeScript={[Function]} indexPattern={ Object { - "fields": Array [ - Object { - "name": "foobar", - }, - ], + "fields": Object { + "getAll": [Function], + "getByName": [Function], + }, "getFormatterForField": [Function], } } @@ -261,19 +260,10 @@ exports[`FieldEditor should render edit scripted field correctly 1`] = ` executeScript={[Function]} indexPattern={ Object { - "fields": Array [ - Object { - "name": "foobar", - }, - Object { - "format": Format {}, - "lang": "painless", - "name": "test", - "script": "doc.test.value", - "scripted": true, - "type": "number", - }, - ], + "fields": Object { + "getAll": [Function], + "getByName": [Function], + }, "getFormatterForField": [Function], } } @@ -504,27 +494,10 @@ exports[`FieldEditor should show conflict field warning 1`] = ` executeScript={[Function]} indexPattern={ Object { - "fields": Array [ - Object { - "name": "foobar", - }, - Object { - "format": Format {}, - "lang": "painless", - "name": "test", - "script": "doc.test.value", - "scripted": true, - "type": "number", - }, - Object { - "format": Format {}, - "lang": "testlang", - "name": "test", - "script": "doc.test.value", - "scripted": true, - "type": "number", - }, - ], + "fields": Object { + "getAll": [Function], + "getByName": [Function], + }, "getFormatterForField": [Function], } } @@ -784,27 +757,10 @@ exports[`FieldEditor should show deprecated lang warning 1`] = ` executeScript={[Function]} indexPattern={ Object { - "fields": Array [ - Object { - "name": "foobar", - }, - Object { - "format": Format {}, - "lang": "painless", - "name": "test", - "script": "doc.test.value", - "scripted": true, - "type": "number", - }, - Object { - "format": Format {}, - "lang": "testlang", - "name": "test", - "script": "doc.test.value", - "scripted": true, - "type": "number", - }, - ], + "fields": Object { + "getAll": [Function], + "getByName": [Function], + }, "getFormatterForField": [Function], } } @@ -1116,27 +1072,10 @@ exports[`FieldEditor should show multiple type field warning with a table contai executeScript={[Function]} indexPattern={ Object { - "fields": Array [ - Object { - "name": "foobar", - }, - Object { - "format": Format {}, - "lang": "painless", - "name": "test", - "script": "doc.test.value", - "scripted": true, - "type": "number", - }, - Object { - "format": Format {}, - "lang": "testlang", - "name": "test", - "script": "doc.test.value", - "scripted": true, - "type": "number", - }, - ], + "fields": Object { + "getAll": [Function], + "getByName": [Function], + }, "getFormatterForField": [Function], } } diff --git a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx index ba1f2ff4b665d9..96d3fc549ece01 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx +++ b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx @@ -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', () => ({})); @@ -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 { @@ -112,7 +111,7 @@ describe('FieldEditor', () => { beforeEach(() => { indexPattern = ({ - fields: fields as IIndexPatternFieldList, + fields, getFormatterForField: () => ({ params: () => ({}) }), } as unknown) as IndexPattern; }); @@ -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, @@ -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, diff --git a/src/plugins/input_control_vis/public/test_utils/get_deps_mock.tsx b/src/plugins/input_control_vis/public/test_utils/get_deps_mock.tsx index feedcab1850eb7..f72bc96f9e7c18 100644 --- a/src/plugins/input_control_vis/public/test_utils/get_deps_mock.tsx +++ b/src/plugins/input_control_vis/public/test_utils/get_deps_mock.tsx @@ -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 = {