Skip to content

Commit 83a088c

Browse files
authored
[Mappings editor] Add component integration tests (#63853)
1 parent 8a8647a commit 83a088c

File tree

31 files changed

+1513
-117
lines changed

31 files changed

+1513
-117
lines changed

x-pack/plugins/index_management/__jest__/components/index_table.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import React from 'react';
88
import axios from 'axios';
99
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
1010
import { MemoryRouter } from 'react-router-dom';
11+
12+
/**
13+
* The below import is required to avoid a console error warn from brace package
14+
* console.warn ../node_modules/brace/index.js:3999
15+
Could not load worker ReferenceError: Worker is not defined
16+
at createWorker (/<path-to-repo>/node_modules/brace/index.js:17992:5)
17+
*/
18+
import * as stubWebWorker from '../../../../test_utils/stub_web_worker'; // eslint-disable-line no-unused-vars
19+
1120
import { AppWithoutRouter } from '../../public/application/app';
1221
import { AppContextProvider } from '../../public/application/app_context';
1322
import { Provider } from 'react-redux';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { defaultShapeParameters } from './shape_datatype.test';
8+
export { defaultTextParameters } from './text_datatype.test';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { act } from 'react-dom/test-utils';
8+
9+
import { componentHelpers, MappingsEditorTestBed } from '../helpers';
10+
11+
const { setup, getMappingsEditorDataFactory } = componentHelpers.mappingsEditor;
12+
const onChangeHandler = jest.fn();
13+
const getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler);
14+
15+
// Parameters automatically added to the shape datatype when saved (with the default values)
16+
export const defaultShapeParameters = {
17+
type: 'shape',
18+
coerce: false,
19+
ignore_malformed: false,
20+
ignore_z_value: true,
21+
};
22+
23+
describe('Mappings editor: shape datatype', () => {
24+
let testBed: MappingsEditorTestBed;
25+
26+
/**
27+
* Variable to store the mappings data forwarded to the consumer component
28+
*/
29+
let data: any;
30+
31+
test('initial view and default parameters values', async () => {
32+
const defaultMappings = {
33+
_meta: {},
34+
_source: {},
35+
properties: {
36+
myField: {
37+
type: 'shape',
38+
},
39+
},
40+
};
41+
42+
const updatedMappings = { ...defaultMappings };
43+
44+
await act(async () => {
45+
testBed = await setup({ value: defaultMappings, onChange: onChangeHandler });
46+
});
47+
48+
const {
49+
exists,
50+
waitFor,
51+
waitForFn,
52+
actions: { startEditField, updateFieldAndCloseFlyout },
53+
} = testBed;
54+
55+
// Open the flyout to edit the field
56+
await act(async () => {
57+
startEditField('myField');
58+
});
59+
60+
await waitFor('mappingsEditorFieldEdit');
61+
62+
// Save the field and close the flyout
63+
await act(async () => {
64+
await updateFieldAndCloseFlyout();
65+
});
66+
67+
await waitForFn(
68+
async () => exists('mappingsEditorFieldEdit') === false,
69+
'Error waiting for the details flyout to close'
70+
);
71+
72+
// It should have the default parameters values added
73+
updatedMappings.properties.myField = {
74+
type: 'shape',
75+
...defaultShapeParameters,
76+
};
77+
78+
({ data } = await getMappingsEditorData());
79+
expect(data).toEqual(updatedMappings);
80+
});
81+
});

0 commit comments

Comments
 (0)