Skip to content

Commit

Permalink
Test that default parameters values are added to the field when updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed Apr 22, 2020
1 parent 6c6a2a7 commit 5ea0be5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('text datatype', () => {
let testBed: MappingsEditorTestBed;

beforeEach(async () => {
testBed = await setup({ defaultValue: defaultMappings, onUpdate() {} });
testBed = await setup({ defaultValue: defaultMappings, onUpdate: onUpdateHandler });

// We edit the field (by opening the flyout)
await act(async () => {
Expand All @@ -56,9 +56,27 @@ describe('text datatype', () => {
});

test('flyout details initial view', async () => {
const updatedMappings = {
_meta: {}, // If undefined, an empty object is returned by the editor
_source: {}, // If undefined, an empty object is returned by the editor
...defaultMappings,
properties: {
user: {
type: 'object', // As no type was defined, defaults to "object" type
properties: {
address: {
type: 'object', // As no type was defined, defaults to "object" type
properties: {
street: { type: 'text' },
},
},
},
},
},
};
const {
find,
actions: { getToggleValue, showAdvancedSettings },
actions: { getToggleValue, showAdvancedSettings, updateFieldAndCloseFlyout },
} = testBed;
const fieldPath = ['user', 'address', 'street'];
const fieldName = fieldPath[fieldPath.length - 1];
Expand All @@ -76,6 +94,32 @@ describe('text datatype', () => {
// The advanced settings should be hidden initially
expect(find('mappingsEditorFieldEdit.advancedSettings').props().style.display).toEqual('none');

await showAdvancedSettings();
await act(async () => {
await showAdvancedSettings();
});

// TODO: find a way to automate the test that all expected fields are present
// and have their default value correctly set

await expectDataUpdated(updatedMappings);

await act(async () => {
await updateFieldAndCloseFlyout();
});

const streetField = {
type: 'text',
// All the default parameters values have been added
eager_global_ordinals: false,
fielddata: false,
index: true,
index_options: 'positions',
index_phrases: false,
norms: true,
store: false,
};
updatedMappings.properties.user.properties.address.properties.street = streetField;

await expectDataUpdated(updatedMappings);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ const createActions = (testBed: TestBed<TestSubjects>) => {
await waitFor('mappingsEditorFieldEdit');
};

const updateFieldAndCloseFlyout = async () => {
find('mappingsEditorFieldEdit.editFieldUpdateButton').simulate('click');

await waitForFn(
async () => exists('mappingsEditorFieldEdit') === false,
'Error waiting for the details flyout to close'
);
};

const showAdvancedSettings = async () => {
const checkIsVisible = async () =>
find('mappingsEditorFieldEdit.advancedSettings').props().style.display === 'block';
Expand Down Expand Up @@ -173,6 +182,7 @@ const createActions = (testBed: TestBed<TestSubjects>) => {
getFieldAt,
addField,
startEditField,
updateFieldAndCloseFlyout,
showAdvancedSettings,
updateJsonEditor,
getJsonEditorValue,
Expand Down Expand Up @@ -266,6 +276,7 @@ export type TestSubjects =
| 'createFieldForm.fieldType'
| 'createFieldForm.addButton'
| 'mappingsEditorFieldEdit'
| 'mappingsEditorFieldEdit.editFieldUpdateButton'
| 'mappingsEditorFieldEdit.flyoutTitle'
| 'mappingsEditorFieldEdit.documentationLink'
| 'mappingsEditorFieldEdit.fieldPath'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('<MappingsEditor />', () => {
let testBed: MappingsEditorTestBed;

beforeEach(async () => {
testBed = await setup({ defaultValue: defaultMappings, onUpdate() {} });
testBed = await setup({ defaultValue: defaultMappings, onUpdate: onUpdateHandler });
});

test('should keep the changes when switching tabs', async () => {
Expand Down

0 comments on commit 5ea0be5

Please sign in to comment.