forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mappings editor] Fix regressions in scaled_float and date_range types (
- Loading branch information
Showing
7 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...onents/mappings_editor/__jest__/client_integration/datatypes/date_range_datatype.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { componentHelpers, MappingsEditorTestBed } from '../helpers'; | ||
|
||
const { setup, getMappingsEditorDataFactory } = componentHelpers.mappingsEditor; | ||
|
||
// Parameters automatically added to the date range datatype when saved (with the default values) | ||
export const defaultDateRangeParameters = { | ||
type: 'date_range', | ||
coerce: true, | ||
index: true, | ||
store: false, | ||
}; | ||
|
||
describe('Mappings editor: date range datatype', () => { | ||
/** | ||
* Variable to store the mappings data forwarded to the consumer component | ||
*/ | ||
let data: any; | ||
let onChangeHandler: jest.Mock = jest.fn(); | ||
let getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler); | ||
let testBed: MappingsEditorTestBed; | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
beforeEach(() => { | ||
onChangeHandler = jest.fn(); | ||
getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler); | ||
}); | ||
|
||
test('should require a scaling factor to be provided', async () => { | ||
const defaultMappings = { | ||
properties: { | ||
myField: { | ||
type: 'double_range', | ||
}, | ||
}, | ||
}; | ||
|
||
const updatedMappings = { ...defaultMappings }; | ||
|
||
await act(async () => { | ||
testBed = setup({ value: defaultMappings, onChange: onChangeHandler }); | ||
}); | ||
testBed.component.update(); | ||
|
||
const { | ||
component, | ||
find, | ||
exists, | ||
actions: { startEditField, updateFieldAndCloseFlyout, toggleFormRow }, | ||
} = testBed; | ||
|
||
// Open the flyout to edit the field | ||
await startEditField('myField'); | ||
|
||
expect(exists('formatParameter')).toBe(false); | ||
|
||
// Change the type to "date_range" | ||
await act(async () => { | ||
find('mappingsEditorFieldEdit.fieldSubType').simulate('change', [ | ||
{ | ||
label: 'Date range', | ||
value: 'date_range', | ||
}, | ||
]); | ||
}); | ||
component.update(); | ||
|
||
expect(exists('formatParameter')).toBe(true); | ||
expect(exists('formatParameter.formatInput')).toBe(false); | ||
toggleFormRow('formatParameter'); | ||
expect(exists('formatParameter.formatInput')).toBe(true); | ||
|
||
await act(async () => { | ||
find('formatParameter.formatInput').simulate('change', [{ label: 'customDateFormat' }]); | ||
}); | ||
component.update(); | ||
|
||
await updateFieldAndCloseFlyout(); | ||
|
||
// It should have the default parameters values added, plus the scaling factor | ||
updatedMappings.properties.myField = { | ||
...defaultDateRangeParameters, | ||
format: 'customDateFormat', | ||
} as any; | ||
|
||
({ data } = await getMappingsEditorData(component)); | ||
expect(data).toEqual(updatedMappings); | ||
}); | ||
}); |
102 changes: 102 additions & 0 deletions
102
...ents/mappings_editor/__jest__/client_integration/datatypes/scaled_float_datatype.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { componentHelpers, MappingsEditorTestBed } from '../helpers'; | ||
|
||
const { setup, getMappingsEditorDataFactory } = componentHelpers.mappingsEditor; | ||
|
||
// Parameters automatically added to the scaled float datatype when saved (with the default values) | ||
export const defaultScaledFloatParameters = { | ||
type: 'scaled_float', | ||
coerce: true, | ||
doc_values: true, | ||
ignore_malformed: false, | ||
index: true, | ||
store: false, | ||
}; | ||
|
||
describe('Mappings editor: scaled float datatype', () => { | ||
/** | ||
* Variable to store the mappings data forwarded to the consumer component | ||
*/ | ||
let data: any; | ||
let onChangeHandler: jest.Mock = jest.fn(); | ||
let getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler); | ||
let testBed: MappingsEditorTestBed; | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
beforeEach(() => { | ||
onChangeHandler = jest.fn(); | ||
getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler); | ||
}); | ||
|
||
test('should require a scaling factor to be provided', async () => { | ||
const defaultMappings = { | ||
properties: { | ||
myField: { | ||
type: 'byte', | ||
}, | ||
}, | ||
}; | ||
|
||
const updatedMappings = { ...defaultMappings }; | ||
|
||
await act(async () => { | ||
testBed = setup({ value: defaultMappings, onChange: onChangeHandler }); | ||
}); | ||
testBed.component.update(); | ||
|
||
const { | ||
component, | ||
find, | ||
exists, | ||
form, | ||
actions: { startEditField, updateFieldAndCloseFlyout }, | ||
} = testBed; | ||
|
||
// Open the flyout to edit the field | ||
await startEditField('myField'); | ||
|
||
// Change the type to "scaled_float" | ||
await act(async () => { | ||
find('mappingsEditorFieldEdit.fieldSubType').simulate('change', [ | ||
{ | ||
label: 'Scaled float', | ||
value: 'scaled_float', | ||
}, | ||
]); | ||
}); | ||
component.update(); | ||
|
||
// It should **not** allow to save as the "scaling factor" parameter has not been set | ||
await updateFieldAndCloseFlyout(); | ||
expect(exists('mappingsEditorFieldEdit')).toBe(true); | ||
expect(form.getErrorsMessages()).toEqual(['A scaling factor is required.']); | ||
|
||
await act(async () => { | ||
form.setInputValue('scalingFactor.input', '123'); | ||
}); | ||
await updateFieldAndCloseFlyout(); | ||
expect(exists('mappingsEditorFieldEdit')).toBe(false); | ||
|
||
// It should have the default parameters values added, plus the scaling factor | ||
updatedMappings.properties.myField = { | ||
...defaultScaledFloatParameters, | ||
scaling_factor: 123, | ||
} as any; | ||
|
||
({ data } = await getMappingsEditorData(component)); | ||
expect(data).toEqual(updatedMappings); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters