[Mappings editor] Fix bug when switching between mapping tabs (#78707)
This commit is contained in:
parent
97ac553d03
commit
cba458e456
2 changed files with 31 additions and 5 deletions
|
@ -223,6 +223,33 @@ describe('Mappings editor: core', () => {
|
|||
isNumericDetectionVisible = exists('advancedConfiguration.numericDetection');
|
||||
expect(isNumericDetectionVisible).toBe(false);
|
||||
});
|
||||
|
||||
test('should keep default dynamic templates value when switching tabs', async () => {
|
||||
await act(async () => {
|
||||
testBed = setup({
|
||||
value: { ...defaultMappings, dynamic_templates: [] }, // by default, the UI will provide an empty array for dynamic templates
|
||||
onChange: onChangeHandler,
|
||||
});
|
||||
});
|
||||
testBed.component.update();
|
||||
|
||||
const {
|
||||
actions: { selectTab, getJsonEditorValue },
|
||||
} = testBed;
|
||||
|
||||
// Navigate to dynamic templates tab and verify empty array
|
||||
await selectTab('templates');
|
||||
let templatesValue = getJsonEditorValue('dynamicTemplatesEditor');
|
||||
expect(templatesValue).toEqual([]);
|
||||
|
||||
// Navigate to advanced tab
|
||||
await selectTab('advanced');
|
||||
|
||||
// Navigate back to dynamic templates tab and verify empty array persists
|
||||
await selectTab('templates');
|
||||
templatesValue = getJsonEditorValue('dynamicTemplatesEditor');
|
||||
expect(templatesValue).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('component props', () => {
|
||||
|
|
|
@ -36,11 +36,10 @@ const formSerializer: SerializerFunc<MappingsTemplates | undefined> = (formData)
|
|||
// Silently swallow errors
|
||||
}
|
||||
|
||||
return Array.isArray(parsedTemplates) && parsedTemplates.length > 0
|
||||
? {
|
||||
dynamic_templates: parsedTemplates,
|
||||
}
|
||||
: undefined;
|
||||
return {
|
||||
dynamic_templates:
|
||||
Array.isArray(parsedTemplates) && parsedTemplates.length > 0 ? parsedTemplates : [],
|
||||
};
|
||||
};
|
||||
|
||||
const formDeserializer = (formData: { [key: string]: any }) => {
|
||||
|
|
Loading…
Reference in a new issue