diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/configuration_form.test.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/configuration_form.test.tsx index 9c317fd2486c..39c04d2e9da3 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/configuration_form.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/configuration_form.test.tsx @@ -7,7 +7,6 @@ import { AppDependencies } from '../../../..'; import { registerTestBed, TestBed } from '@kbn/test-jest-helpers'; -import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; import { ConfigurationForm } from '../../components/configuration_form'; import { WithAppDependencies } from './helpers/setup_environment'; import { TestSubjects } from './helpers/mappings_editor.helpers'; @@ -29,21 +28,32 @@ const setup = (props: any = { onUpdate() {} }, appDependencies?: any) => { return testBed; }; +const getContext = (sourceFieldEnabled: boolean = true, hasEnterpriseLicense: boolean = true) => + ({ + config: { + enableMappingsSourceFieldSection: sourceFieldEnabled, + }, + plugins: { + licensing: { + license$: { + subscribe: jest.fn((callback: any) => { + callback({ + isActive: true, + hasAtLeast: jest.fn((type: any) => hasEnterpriseLicense), + }); + return { unsubscribe: jest.fn() }; + }), + }, + }, + }, + } as unknown as AppDependencies); + describe('Mappings editor: configuration form', () => { let testBed: TestBed; it('renders the form', async () => { - const ctx = { - config: { - enableMappingsSourceFieldSection: true, - }, - plugins: { - licensing: licensingMock.createStart(), - }, - } as unknown as AppDependencies; - await act(async () => { - testBed = setup({ esNodesPlugins: [] }, ctx); + testBed = setup({ esNodesPlugins: [] }, getContext()); }); testBed.component.update(); const { exists } = testBed; @@ -52,42 +62,87 @@ describe('Mappings editor: configuration form', () => { }); describe('_source field', () => { - it('renders the _source field when it is enabled', async () => { - const ctx = { - config: { - enableMappingsSourceFieldSection: true, - }, - plugins: { - licensing: licensingMock.createStart(), - }, - } as unknown as AppDependencies; + describe('renders depending on enableMappingsSourceFieldSection config', () => { + it('renders when config set to true', async () => { + await act(async () => { + testBed = setup({ esNodesPlugins: [] }, getContext(true)); + }); + testBed.component.update(); + const { exists } = testBed; - await act(async () => { - testBed = setup({ esNodesPlugins: [] }, ctx); + expect(exists('sourceField')).toBe(true); }); - testBed.component.update(); - const { exists } = testBed; - expect(exists('sourceField')).toBe(true); + it("doesn't render when config set to false", async () => { + await act(async () => { + testBed = setup({ esNodesPlugins: [] }, getContext(false)); + }); + testBed.component.update(); + const { exists } = testBed; + + expect(exists('sourceField')).toBe(false); + }); }); - it("doesn't render the _source field when it is disabled", async () => { - const ctx = { - config: { - enableMappingsSourceFieldSection: false, - }, - plugins: { - licensing: licensingMock.createStart(), - }, - } as unknown as AppDependencies; + describe('has synthetic option depending on license', () => { + it('has synthetic option on enterprise license', async () => { + await act(async () => { + testBed = setup({ esNodesPlugins: [] }, getContext(true, true)); + }); + testBed.component.update(); + const { exists, find } = testBed; - await act(async () => { - testBed = setup({ esNodesPlugins: [] }, ctx); + // Clicking on the field to open the options dropdown + find('sourceValueField').simulate('click'); + expect(exists('syntheticSourceFieldOption')).toBe(true); }); - testBed.component.update(); - const { exists } = testBed; - expect(exists('sourceField')).toBe(false); + it("doesn't have synthetic option on lower than enterprise license", async () => { + await act(async () => { + testBed = setup({ esNodesPlugins: [] }, getContext(true, false)); + }); + testBed.component.update(); + const { exists, find } = testBed; + + // Clicking on the field to open the options dropdown + find('sourceValueField').simulate('click'); + expect(exists('syntheticSourceFieldOption')).toBe(false); + }); + }); + + describe('has correct default value', () => { + it("defaults to 'stored' if index mode prop is 'standard'", async () => { + await act(async () => { + testBed = setup({ esNodesPlugins: [], indexMode: 'standard' }, getContext()); + }); + testBed.component.update(); + const { find } = testBed; + + // Check that the stored option is selected + expect(find('sourceValueField').text()).toBe('Stored _source'); + }); + + it("defaults to 'synthetic' if index mode prop is 'logsdb'", async () => { + await act(async () => { + testBed = setup({ esNodesPlugins: [], indexMode: 'logsdb' }, getContext()); + }); + testBed.component.update(); + const { find } = testBed; + + // Check that the synthetic option is selected + expect(find('sourceValueField').text()).toBe('Synthetic _source'); + }); + + it("defaults to 'synthetic' if index mode prop is 'time_series'", async () => { + await act(async () => { + testBed = setup({ esNodesPlugins: [], indexMode: 'time_series' }, getContext()); + }); + testBed.component.update(); + const { find } = testBed; + + // Check that the synthetic option is selected + expect(find('sourceValueField').text()).toBe('Synthetic _source'); + }); }); }); }); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/configuration_form/source_field_section/source_field_section.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/configuration_form/source_field_section/source_field_section.tsx index 3b5d62a5aeb6..45df40caa3a0 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/configuration_form/source_field_section/source_field_section.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/configuration_form/source_field_section/source_field_section.tsx @@ -47,6 +47,7 @@ export const SourceFieldSection = () => { value: STORED_SOURCE_OPTION, inputDisplay: sourceOptionLabels[STORED_SOURCE_OPTION], dropdownDisplay: renderOptionDropdownDisplay(STORED_SOURCE_OPTION), + 'data-test-subj': 'storedSourceFieldOption', }, ]; @@ -55,12 +56,14 @@ export const SourceFieldSection = () => { value: SYNTHETIC_SOURCE_OPTION, inputDisplay: sourceOptionLabels[SYNTHETIC_SOURCE_OPTION], dropdownDisplay: renderOptionDropdownDisplay(SYNTHETIC_SOURCE_OPTION), + 'data-test-subj': 'syntheticSourceFieldOption', }); } sourceValueOptions.push({ value: DISABLED_SOURCE_OPTION, inputDisplay: sourceOptionLabels[DISABLED_SOURCE_OPTION], dropdownDisplay: renderOptionDropdownDisplay(DISABLED_SOURCE_OPTION), + 'data-test-subj': 'disabledSourceFieldOption', }); const renderDisableWarning = () => (