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 35f4377af1a65..4c73fd1037dda 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 @@ -28,19 +28,18 @@ const setup = (props: any = { onUpdate() {} }, appDependencies?: any) => { return testBed; }; -const getContext = (sourceFieldEnabled: boolean = true) => - ({ - config: { - enableMappingsSourceFieldSection: sourceFieldEnabled, - }, - } as unknown as AppDependencies); - describe('Mappings editor: configuration form', () => { let testBed: TestBed; it('renders the form', async () => { + const ctx = { + config: { + enableMappingsSourceFieldSection: true, + }, + } as unknown as AppDependencies; + await act(async () => { - testBed = setup({ esNodesPlugins: [] }, getContext()); + testBed = setup({ esNodesPlugins: [] }, ctx); }); testBed.component.update(); const { exists } = testBed; @@ -49,64 +48,36 @@ describe('Mappings editor: configuration form', () => { }); describe('_source field', () => { - 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; - - expect(exists('sourceField')).toBe(true); + it('renders the _source field when it is enabled', async () => { + const ctx = { + config: { + enableMappingsSourceFieldSection: true, + }, + } as unknown as AppDependencies; + + await act(async () => { + testBed = setup({ esNodesPlugins: [] }, ctx); }); + testBed.component.update(); + const { exists } = testBed; - 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); - }); + expect(exists('sourceField')).toBe(true); }); - describe('has synthetic option depending on license', () => { - it('has synthetic option on enterprise license', async () => { - jest.mock('../../mappings_state_context', () => ({ - useMappingsState: jest.fn().mockReturnValue({ - hasEnterpriseLicense: true, - }), - })); - - await act(async () => { - testBed = setup({ esNodesPlugins: [] }, getContext(true)); - }); - testBed.component.update(); - const { exists, find } = testBed; + it("doesn't render the _source field when it is disabled", async () => { + const ctx = { + config: { + enableMappingsSourceFieldSection: false, + }, + } as unknown as AppDependencies; - // Clicking on the field to open the options dropdown - find('sourceValueField').simulate('click'); - expect(exists('syntheticSourceFieldOption')).toBe(true); + await act(async () => { + testBed = setup({ esNodesPlugins: [] }, ctx); }); + testBed.component.update(); + const { exists } = testBed; - it("doesn't have synthetic option on lower than enterprise license", async () => { - jest.mock('../../mappings_state_context', () => ({ - useMappingsState: jest.fn().mockReturnValue({ - hasEnterpriseLicense: false, - }), - })); - - await act(async () => { - testBed = setup({ esNodesPlugins: [] }, getContext(true)); - }); - 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); - }); + expect(exists('sourceField')).toBe(false); }); }); }); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx index 094fd40ab1e32..349a724043169 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx @@ -459,6 +459,7 @@ export type TestSubjects = | 'advancedConfiguration.dynamicMappingsToggle.input' | 'advancedConfiguration.metaField' | 'advancedConfiguration.routingRequiredToggle.input' + | 'sourceValueField' | 'sourceField.includesField' | 'sourceField.excludesField' | 'dynamicTemplatesEditor' diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx index d41510d3a43e5..ee3b3e72e7c19 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx @@ -28,6 +28,8 @@ describe('Mappings editor: core', () => { let onChangeHandler: jest.Mock = jest.fn(); let getMappingsEditorData = getMappingsEditorDataFactory(onChangeHandler); let testBed: MappingsEditorTestBed; + let hasEnterpriseLicense = true; + const mockLicenseCheck = jest.fn((type: any) => hasEnterpriseLicense); const appDependencies = { plugins: { ml: { mlApi: {} }, @@ -36,7 +38,7 @@ describe('Mappings editor: core', () => { subscribe: jest.fn((callback: any) => { callback({ isActive: true, - hasAtLeast: jest.fn((type: any) => true), + hasAtLeast: mockLicenseCheck, }); return { unsubscribe: jest.fn() }; }), @@ -485,7 +487,7 @@ describe('Mappings editor: core', () => { }); describe('props.indexMode sets the correct default value of _source field', () => { - it("defaults to 'stored' if index mode prop is 'standard'", async () => { + it("defaults to 'stored' with 'standard' index mode prop", async () => { await act(async () => { testBed = setup( { @@ -509,52 +511,56 @@ describe('Mappings editor: core', () => { expect(find('sourceValueField').prop('value')).toBe('stored'); }); - it("defaults to 'synthetic' if index mode prop is 'logsdb'", async () => { - await act(async () => { - testBed = setup( - { - value: { ...defaultMappings, _source: undefined }, - onChange: onChangeHandler, - indexMode: 'logsdb', - }, - ctx - ); - }); - testBed.component.update(); - - const { - actions: { selectTab }, - find, - } = testBed; + ['logsdb', 'time_series'].forEach((indexMode) => { + it(`defaults to 'synthetic' with ${indexMode} index mode prop on enterprise license`, async () => { + hasEnterpriseLicense = true; + await act(async () => { + testBed = setup( + { + value: { ...defaultMappings, _source: undefined }, + onChange: onChangeHandler, + indexMode, + }, + ctx + ); + }); + testBed.component.update(); - await selectTab('advanced'); + const { + actions: { selectTab }, + find, + } = testBed; - // Check that the synthetic option is selected - expect(find('sourceValueField').prop('value')).toBe('synthetic'); - }); + await selectTab('advanced'); - it("defaults to 'synthetic' if index mode prop is 'time_series'", async () => { - await act(async () => { - testBed = setup( - { - value: { ...defaultMappings, _source: undefined }, - onChange: onChangeHandler, - indexMode: 'time_series', - }, - ctx - ); + // Check that the synthetic option is selected + expect(find('sourceValueField').prop('value')).toBe('synthetic'); }); - testBed.component.update(); - const { - actions: { selectTab }, - find, - } = testBed; + it(`defaults to 'standard' with ${indexMode} index mode prop on basic license`, async () => { + hasEnterpriseLicense = false; + await act(async () => { + testBed = setup( + { + value: { ...defaultMappings, _source: undefined }, + onChange: onChangeHandler, + indexMode, + }, + ctx + ); + }); + testBed.component.update(); - await selectTab('advanced'); + const { + actions: { selectTab }, + find, + } = testBed; - // Check that the synthetic option is selected - expect(find('sourceValueField').prop('value')).toBe('synthetic'); + await selectTab('advanced'); + + // Check that the stored option is selected + expect(find('sourceValueField').prop('value')).toBe('stored'); + }); }); }); });