Skip to content

Commit

Permalink
fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Dec 3, 2019
1 parent a677af6 commit 8f623ad
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 41 deletions.
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

0 comments on commit 8f623ad

Please sign in to comment.