Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mapping editor] Fix client integration tests #52124

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,9 @@ export const ALIASES = {
};

export const MAPPINGS = {
_source: {
enabled: false,
},
properties: {
host_name: {
type: 'keyword',
},
created_at: {
type: 'date',
format: 'EEE MMM dd HH:mm:ss Z yyyy',
},
},
dynamic: true,
date_detection: true,
numeric_detection: true,
dynamic_date_formats: [],
properties: {},
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface TemplateFormTestBed extends TestBed<TemplateFormTestSubjects> {
clickSubmitButton: () => void;
completeStepOne: ({ name, indexPatterns, order, version }: Partial<Template>) => void;
completeStepTwo: (settings: string) => void;
completeStepThree: (mappings: string) => void;
completeStepThree: () => void;
completeStepFour: (aliases: string) => void;
selectSummaryTab: (tab: 'summary' | 'request') => void;
};
Expand Down Expand Up @@ -85,17 +85,10 @@ export const formSetup = async (
component.update();
};

const completeStepThree = async (mappings: string) => {
const { find, component } = testBed;

if (mappings) {
find('mockCodeEditor').simulate('change', {
jsonString: mappings,
}); // Using mocked EuiCodeEditor
await nextTick(50);
component.update();
}
const completeStepThree = async () => {
const { component } = testBed;

await nextTick();
clickNextButton();
await nextTick(50); // hooks updates cycles are tricky, adding some latency is needed
component.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { act } from 'react-dom/test-utils';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { TemplateFormTestBed } from './helpers/template_form.helpers';
import * as fixtures from '../../test/fixtures';
import { TEMPLATE_NAME, INDEX_PATTERNS as DEFAULT_INDEX_PATTERNS } from './helpers/constants';
import {
TEMPLATE_NAME,
INDEX_PATTERNS as DEFAULT_INDEX_PATTERNS,
MAPPINGS,
} from './helpers/constants';

const { setup } = pageHelpers.templateClone;

Expand Down Expand Up @@ -50,6 +54,7 @@ describe('<TemplateClone />', () => {
const templateToClone = fixtures.getTemplate({
name: TEMPLATE_NAME,
indexPatterns: ['indexPattern1'],
mappings: MAPPINGS,
});

beforeEach(async () => {
Expand Down Expand Up @@ -87,6 +92,7 @@ describe('<TemplateClone />', () => {
component.update();

// Bypass step 3 (mappings)
await nextTick();
actions.clickNextButton();
await nextTick();
component.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ describe('<TemplateCreate />', () => {
expect(exists('stepMappings')).toBe(true);
expect(find('stepTitle').text()).toEqual('Mappings (optional)');
});

it('should not allow invalid json', async () => {
const { actions, form } = testBed;

await act(async () => {
// Complete step 3 (mappings) with invalid json
await actions.completeStepThree('{ invalidJsonString ');
});

expect(form.getErrorsMessages()).toContain('Invalid JSON format.');
});
});

describe('aliases (step 4)', () => {
Expand All @@ -155,7 +144,7 @@ describe('<TemplateCreate />', () => {
await actions.completeStepTwo('{}');

// Complete step 3 (mappings)
await actions.completeStepThree('{}');
await actions.completeStepThree();
});
});

Expand Down Expand Up @@ -196,7 +185,7 @@ describe('<TemplateCreate />', () => {
await actions.completeStepTwo(JSON.stringify(SETTINGS));

// Complete step 3 (mappings)
await actions.completeStepThree(JSON.stringify(MAPPINGS));
await actions.completeStepThree();

// Complete step 4 (aliases)
await actions.completeStepFour(JSON.stringify(ALIASES));
Expand Down Expand Up @@ -250,7 +239,7 @@ describe('<TemplateCreate />', () => {
await actions.completeStepTwo(JSON.stringify({}));

// Complete step 3 (mappings)
await actions.completeStepThree(JSON.stringify({}));
await actions.completeStepThree();

// Complete step 4 (aliases)
await actions.completeStepFour(JSON.stringify({}));
Expand Down Expand Up @@ -280,7 +269,7 @@ describe('<TemplateCreate />', () => {
await actions.completeStepTwo(JSON.stringify(SETTINGS));

// Complete step 3 (mappings)
await actions.completeStepThree(JSON.stringify(MAPPINGS));
await actions.completeStepThree();

// Complete step 4 (aliases)
await actions.completeStepFour(JSON.stringify(ALIASES));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('<TemplateEdit />', () => {
await actions.completeStepTwo(JSON.stringify(SETTINGS));

// Step 3 (mappings)
await actions.completeStepThree(JSON.stringify(MAPPINGS));
await actions.completeStepThree();

// Step 4 (aliases)
await actions.completeStepFour(JSON.stringify(ALIASES));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export const MappingsState = React.memo(({ children, onUpdate, defaultValue }: P
const [state, dispatch] = useReducer(reducer, initialState);

useEffect(() => {
// console.log('State update', state);
// If we are creating a new field, but haven't entered any name
// it is valid and we can byPass its form validation (that requires a "name" to be defined)
const isFieldFormVisible = state.fieldForm !== undefined;
Expand Down