Skip to content

Commit

Permalink
[Mappings editor] Re-enable scaled float test (elastic#162834)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Aug 23, 2023
1 parent a14f76d commit 58b4104
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { act } from 'react-dom/test-utils';

import { componentHelpers, MappingsEditorTestBed, kibanaVersion } from '../helpers';
import { componentHelpers, MappingsEditorTestBed } from '../helpers';

const { setup, getMappingsEditorDataFactory } = componentHelpers.mappingsEditor;

Expand All @@ -21,8 +21,7 @@ export const defaultScaledFloatParameters = {
store: false,
};

// FLAKY: https://github.com/elastic/kibana/issues/145102
describe.skip('Mappings editor: scaled float datatype', () => {
describe('Mappings editor: scaled float datatype', () => {
/**
* Variable to store the mappings data forwarded to the consumer component
*/
Expand All @@ -32,7 +31,7 @@ describe.skip('Mappings editor: scaled float datatype', () => {
let testBed: MappingsEditorTestBed;

beforeAll(() => {
jest.useFakeTimers({ legacyFakeTimers: true });
jest.useFakeTimers();
});

afterAll(() => {
Expand Down Expand Up @@ -90,15 +89,12 @@ describe.skip('Mappings editor: scaled float datatype', () => {
await act(async () => {
form.setInputValue('scalingFactor.input', '123');
});

component.update();

await updateFieldAndCloseFlyout();
expect(exists('mappingsEditorFieldEdit')).toBe(false);

if (kibanaVersion.major < 7) {
expect(exists('boostParameterToggle')).toBe(true);
} else {
// Since 8.x the boost parameter is deprecated
expect(exists('boostParameterToggle')).toBe(false);
}
expect(exists('mappingsEditorFieldEdit')).toBe(false);

// It should have the default parameters values added, plus the scaling factor
updatedMappings.properties.myField = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import SemVer from 'semver/classes/semver';

import { NormalizedField, Field as FieldType, ComboBoxOption } from '../../../../types';
import { NormalizedField, Field as FieldType } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
import { UseField, FormDataProvider, NumericField, Field } from '../../../../shared_imports';
import { UseField, useFormData, NumericField, Field } from '../../../../shared_imports';
import {
StoreParameter,
IndexParameter,
Expand Down Expand Up @@ -48,28 +48,26 @@ interface Props {
}

export const NumericType = ({ field, kibanaVersion }: Props) => {
const [formData] = useFormData({ watch: 'subType' });

return (
<>
<BasicParametersSection>
{/* scaling_factor */}
<FormDataProvider<{ subType?: ComboBoxOption[] }> pathsToWatch="subType">
{(formData) => {
return formData.subType?.[0]?.value === 'scaled_float' ? (
<EditFieldFormRow
title={PARAMETERS_DEFINITION.scaling_factor.title!}
description={PARAMETERS_DEFINITION.scaling_factor.description}
withToggle={false}
>
<UseField
path="scaling_factor"
config={getFieldConfig('scaling_factor')}
component={Field}
data-test-subj="scalingFactor"
/>
</EditFieldFormRow>
) : null;
}}
</FormDataProvider>
{formData.subType?.[0]?.value === 'scaled_float' ? (
<EditFieldFormRow
title={PARAMETERS_DEFINITION.scaling_factor.title!}
description={PARAMETERS_DEFINITION.scaling_factor.description}
withToggle={false}
>
<UseField
path="scaling_factor"
config={getFieldConfig('scaling_factor')}
component={Field}
data-test-subj="scalingFactor"
/>
</EditFieldFormRow>
) : null}

<IndexParameter hasIndexOptions={false} />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export {
useForm,
useFormContext,
UseMultiFields,
useFormData,
VALIDATION_TYPES,
} from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib';

Expand Down

0 comments on commit 58b4104

Please sign in to comment.