Skip to content

Commit 631f21d

Browse files
committed
fix jest tests
1 parent 58af035 commit 631f21d

4 files changed

Lines changed: 66 additions & 125 deletions

File tree

src/plugins/discover/public/application/components/table/table.test.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,47 @@ import { DocViewTable } from './table';
2424
import { indexPatterns, IndexPattern } from '../../../../../data/public';
2525

2626
const indexPattern = {
27-
fields: [
28-
{
29-
name: '_index',
30-
type: 'string',
31-
scripted: false,
32-
filterable: true,
33-
},
34-
{
35-
name: 'message',
36-
type: 'string',
37-
scripted: false,
38-
filterable: false,
39-
},
40-
{
41-
name: 'extension',
42-
type: 'string',
43-
scripted: false,
44-
filterable: true,
45-
},
46-
{
47-
name: 'bytes',
48-
type: 'number',
49-
scripted: false,
50-
filterable: true,
51-
},
52-
{
53-
name: 'scripted',
54-
type: 'number',
55-
scripted: true,
56-
filterable: false,
57-
},
58-
],
27+
fields: {
28+
getAll: () => [
29+
{
30+
name: '_index',
31+
type: 'string',
32+
scripted: false,
33+
filterable: true,
34+
},
35+
{
36+
name: 'message',
37+
type: 'string',
38+
scripted: false,
39+
filterable: false,
40+
},
41+
{
42+
name: 'extension',
43+
type: 'string',
44+
scripted: false,
45+
filterable: true,
46+
},
47+
{
48+
name: 'bytes',
49+
type: 'number',
50+
scripted: false,
51+
filterable: true,
52+
},
53+
{
54+
name: 'scripted',
55+
type: 'number',
56+
scripted: true,
57+
filterable: false,
58+
},
59+
],
60+
},
5961
metaFields: ['_index', '_score'],
6062
flattenHit: undefined,
6163
formatHit: jest.fn((hit) => hit._source),
6264
} as IndexPattern;
6365

6466
indexPattern.fields.getByName = (name: string) => {
65-
return indexPattern.fields.find((field) => field.name === name);
67+
return indexPattern.fields.getAll().find((field) => field.name === name);
6668
};
6769

6870
indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields);

src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap

Lines changed: 20 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
import {
21-
IndexPattern,
22-
IndexPatternField,
23-
IIndexPatternFieldList,
24-
FieldFormatInstanceType,
25-
} from 'src/plugins/data/public';
20+
import { IndexPattern, IndexPatternField, FieldFormatInstanceType } from 'src/plugins/data/public';
2621

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

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

74-
const fields: IndexPatternField[] = [
69+
const fieldList = [
7570
{
7671
name: 'foobar',
7772
} as IndexPatternField,
7873
];
7974

75+
const fields = {
76+
getAll: () => fieldList,
77+
};
78+
8079
// @ts-ignore
8180
fields.getByName = (name: string) => {
82-
return fields.find((field) => field.name === name);
81+
return fields.getAll().find((field) => field.name === name);
8382
};
8483

8584
class Format {
@@ -112,7 +111,7 @@ describe('FieldEditor', () => {
112111

113112
beforeEach(() => {
114113
indexPattern = ({
115-
fields: fields as IIndexPatternFieldList,
114+
fields,
116115
getFormatterForField: () => ({ params: () => ({}) }),
117116
} as unknown) as IndexPattern;
118117
});
@@ -139,7 +138,7 @@ describe('FieldEditor', () => {
139138
name: 'test',
140139
script: 'doc.test.value',
141140
};
142-
indexPattern.fields.push(testField as IndexPatternField);
141+
fieldList.push(testField as IndexPatternField);
143142
indexPattern.fields.getByName = (name) => {
144143
const flds = {
145144
[testField.name]: testField,
@@ -169,7 +168,7 @@ describe('FieldEditor', () => {
169168
script: 'doc.test.value',
170169
lang: 'testlang',
171170
};
172-
indexPattern.fields.push((testField as unknown) as IndexPatternField);
171+
fieldList.push((testField as unknown) as IndexPatternField);
173172
indexPattern.fields.getByName = (name) => {
174173
const flds = {
175174
[testField.name]: testField,

src/plugins/input_control_vis/public/test_utils/get_deps_mock.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fields.push({ name: 'myField' } as any);
2626
fields.getByName = (name: any) => {
2727
return fields.find(({ name: n }: { name: string }) => n === name);
2828
};
29+
fields.getAll = () => [...fields];
2930

3031
export const getDepsMock = ({
3132
searchSource = {

0 commit comments

Comments
 (0)