From 91504eee86e6951563673afa1933a712485f1fe1 Mon Sep 17 00:00:00 2001 From: Elena Stoeva Date: Fri, 2 Jun 2023 12:37:36 +0100 Subject: [PATCH 1/2] Fix subtype parameter --- .../field_parameters/subtype_parameter.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/subtype_parameter.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/subtype_parameter.tsx index 404deb6356d82..21c195e1180aa 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/subtype_parameter.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/document_fields/field_parameters/subtype_parameter.tsx @@ -85,7 +85,13 @@ export const SubTypeParameter = ({ : filterTypesForNonRootFields(subTypeOptions!) } selectedOptions={subTypeField.value as ComboBoxOption[]} - onChange={subTypeField.setValue} + onChange={(value) => { + if (value.length === 0) { + // Don't allow clearing the type. One must always be selected + return; + } + subTypeField.setValue(value); + }} isClearable={false} data-test-subj="fieldSubType" /> From ea77b4b0d4e377220e7e37b0124caa4f15cd1d7e Mon Sep 17 00:00:00 2001 From: Elena Stoeva Date: Tue, 6 Jun 2023 17:58:45 +0100 Subject: [PATCH 2/2] Add functional test to catch the bug --- .../index_management/index_template_wizard.ts | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/x-pack/test/functional/apps/index_management/index_template_wizard.ts b/x-pack/test/functional/apps/index_management/index_template_wizard.ts index b19f3bf8d0d70..f04c4e90a205b 100644 --- a/x-pack/test/functional/apps/index_management/index_template_wizard.ts +++ b/x-pack/test/functional/apps/index_management/index_template_wizard.ts @@ -12,6 +12,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const testSubjects = getService('testSubjects'); const pageObjects = getPageObjects(['common', 'indexManagement', 'header']); const security = getService('security'); + const comboBox = getService('comboBox'); + const find = getService('find'); + const browser = getService('browser'); describe('Index template wizard', function () { before(async () => { @@ -98,5 +101,68 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.indexManagement.clickNextButton(); }); }); + + describe('Mappings step', async () => { + beforeEach(async () => { + await pageObjects.common.navigateToApp('indexManagement'); + // Navigate to the index templates tab + await pageObjects.indexManagement.changeTabs('templatesTab'); + await pageObjects.header.waitUntilLoadingHasFinished(); + + // Click Create Template button + await testSubjects.click('createTemplateButton'); + + // Fill out required fields + await testSubjects.setValue('nameField', 'test-index-template'); + await testSubjects.setValue('indexPatternsField', 'test-index-pattern'); + + // Go to Mappings step + await pageObjects.indexManagement.clickNextButton(); + await pageObjects.indexManagement.clickNextButton(); + await pageObjects.indexManagement.clickNextButton(); + }); + + // Test for catching the bug reported in https://github.com/elastic/kibana/issues/156202 + it("clearing up the Numeric subtype dropdown doesn't break the page", async () => { + // Add a mapping field + await testSubjects.click('addFieldButton'); + + // Select Numeric type + await testSubjects.click('fieldType'); + await comboBox.set('fieldType', 'Numeric'); + + // Clear up subtype dropdown + await testSubjects.click('fieldSubType'); + const input = await find.activeElement(); + await input.pressKeys(browser.keys.BACK_SPACE); + + // Verify that elements are still visible + expect(await testSubjects.exists('addFieldButton')).to.be(true); + expect(await testSubjects.exists('fieldType')).to.be(true); + expect(await testSubjects.exists('fieldSubType')).to.be(true); + expect(await testSubjects.exists('nextButton')).to.be(true); + }); + + // Test for catching the bug reported in https://github.com/elastic/kibana/issues/156202 + it("clearing up the Range subtype dropdown doesn't break the page", async () => { + // Add a mapping field + await testSubjects.click('addFieldButton'); + + // Select Range type + await testSubjects.click('fieldType'); + await comboBox.set('fieldType', 'Range'); + + // Clear up subtype dropdown + await testSubjects.click('fieldSubType'); + const input = await find.activeElement(); + await input.pressKeys(browser.keys.BACK_SPACE); + + // Verify that elements are still visible + expect(await testSubjects.exists('addFieldButton')).to.be(true); + expect(await testSubjects.exists('fieldType')).to.be(true); + expect(await testSubjects.exists('fieldSubType')).to.be(true); + expect(await testSubjects.exists('nextButton')).to.be(true); + }); + }); }); };