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

[Rollup] Redux integration test job creation #32223

Merged
merged 25 commits into from Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1b58dbc
test(create rollup job): Logistics -> Validate index pattern
sebelga Feb 26, 2019
6790f77
test(create rollup job): Logistics -> Validate rollup index name & cron
sebelga Feb 27, 2019
8cdd23c
test(create rollup job): Logistics -> Validate page size
sebelga Feb 27, 2019
9f292da
test(create rollup job): Logistics -> Validate navigation to step 2
sebelga Feb 27, 2019
aaadeb2
test(create rollup job): validate step 2 date histogram
sebelga Feb 27, 2019
e26f23b
Small refactor
sebelga Feb 27, 2019
f170bcd
test(create rollup job): step 3 terms
sebelga Feb 28, 2019
f7c4522
test(create rollup job): link to the docs
sebelga Feb 28, 2019
eee97d7
test(create rollup job): step 3 histogram
sebelga Feb 28, 2019
1d3f79b
test(create rollup job): step 5 metrics
sebelga Feb 28, 2019
cf25359
test(create rollup job): step 6 review
sebelga Feb 28, 2019
3d807f4
Merge remote-tracking branch 'upstream/master' into test/rollup_job_c…
sebelga Mar 5, 2019
64ef85d
Split job create test steps into files
sebelga Mar 5, 2019
2a6eb2e
Fix tipo
sebelga Mar 5, 2019
8147bcf
Fix absolute import
sebelga Mar 5, 2019
33d5a38
Fix absolute webpack import
sebelga Mar 6, 2019
80562b9
Merge remote-tracking branch 'upstream/master' into test/rollup_job_c…
sebelga Mar 7, 2019
5acdff5
[Rollup] Api integration test (Indices, index validity, crud)
sebelga Mar 7, 2019
2a5d66b
Revert "[Rollup] Api integration test (Indices, index validity, crud)"
sebelga Mar 7, 2019
432ce8f
Fix failing test
sebelga Mar 7, 2019
98ae910
Fix enzyme_helpers import path
sebelga Mar 8, 2019
bdbbe91
Rename test folder to "client_integration"
sebelga Mar 13, 2019
9a409a2
Merge remote-tracking branch 'upstream/master' into test/rollup_job_c…
sebelga Mar 13, 2019
0193443
Fix failing test
sebelga Mar 13, 2019
6a1908d
Fix absolute import from webpack alias
sebelga Mar 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1,298 changes: 0 additions & 1,298 deletions x-pack/plugins/rollup/__jest__/integration_tests/job_create.test.js

This file was deleted.

@@ -0,0 +1,147 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import axios from 'axios';

import { registerTestBed } from '../utils';
import { rollupJobsStore } from '../../public/crud_app/store';
import {
setHttp,
} from '../../public/crud_app/services';

import { JobCreate } from '../../public/crud_app/sections';

// axios has a $http like interface so using it to simulate $http
setHttp(axios.create());

// This is the Rollup job we will be creating in our tests
const JOB_TO_CREATE = {
id: 'test-job',
indexPattern: 'test-pattern-*',
rollupIndex: 'rollup-index',
interval: '24h'
};

const initUserActions = (component, findTestSubject) => {
const clickNextStep = () => {
const button = findTestSubject('rollupJobNextButton');
button.simulate('click');
component.update();
};

const clickPreviousStep = () => {
const button = findTestSubject('rollupJobBackButton');
button.simulate('click');
component.update();
};

const clickSave = () => {
const button = findTestSubject('rollupJobSaveButton');
button.simulate('click');
component.update();
};

return {
clickNextStep,
clickPreviousStep,
clickSave,
};
};

const initFillFormFields = form => async (step) => {
switch (step) {
case 'logistics':
form.setInputValue('rollupJobName', JOB_TO_CREATE.id);
await form.setInputValue('rollupIndexPattern', JOB_TO_CREATE.indexPattern, true);
form.setInputValue('rollupIndexName', JOB_TO_CREATE.rollupIndex);
break;
case 'date-histogram':
form.setInputValue('rollupJobInterval', JOB_TO_CREATE.interval);
break;
default:
return;
}
};

const initGoToStep = (fillFormFields, clickNextStep) => async (step) => {
if (!step || step === 1) {
return;
}

await fillFormFields('logistics');
clickNextStep();

if (step > 2) {
await fillFormFields('date-histogram');
clickNextStep();
}

if (step > 3) {
clickNextStep();
}

if (step > 4) {
clickNextStep();
}

if (step > 5) {
clickNextStep();
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the loop idea not work out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to update that part. Just did it 😊


export const initTestBed = () => {
const testBed = registerTestBed(JobCreate, {}, rollupJobsStore)();
const userActions = initUserActions(testBed.component, testBed.findTestSubject);
const fillFormFields = initFillFormFields(testBed.form);
const goToStep = initGoToStep(fillFormFields, userActions.clickNextStep);
const getEuiStepsHorizontalActive = () => testBed.component.find('.euiStepHorizontal-isSelected').text();

return {
...testBed,
userActions: {
...userActions
},
form: {
...testBed.form,
fillFormFields,
},
goToStep,
getEuiStepsHorizontalActive,
};
};

export const nextTick = async () => new Promise((resolve) => setTimeout(resolve));

export const mockServerResponses = server => {
const mockIndexPatternValidityResponse = (response) => {
const defaultResponse = {
doesMatchIndices: true,
doesMatchRollupIndices: false,
dateFields: ['foo', 'bar'],
numericFields: [],
keywordFields: [],
};
server.respondWith(/\/api\/rollup\/index_pattern_validity\/.*/, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({ ...defaultResponse, ...response }),
]);
};

const mockCreateJob = () => {
server.respondWith(/\/api\/rollup\/create/, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({}),
]);
};

mockIndexPatternValidityResponse();
mockCreateJob();

return { mockIndexPatternValidityResponse };
};

@@ -0,0 +1,137 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import sinon from 'sinon';
import moment from 'moment-timezone';

import { initTestBed, mockServerResponses } from './job_create.test_helpers';

jest.mock('ui/index_patterns', () => {
const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len
return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE };
});

jest.mock('ui/chrome', () => ({
addBasePath: () => '/api/rollup',
breadcrumbs: { set: () => {} },
}));

jest.mock('lodash/function/debounce', () => fn => fn);

describe('Create Rollup Job, step 2: Date histogram', () => {
let server;
let findTestSubject;
let testSubjectExists;
let userActions;
let getFormErrorsMessages;
let form;
let mockIndexPatternValidityResponse;
let getEuiStepsHorizontalActive;
let goToStep;

beforeEach(() => {
server = sinon.fakeServer.create();
server.respondImmediately = true;
({ mockIndexPatternValidityResponse } = mockServerResponses(server));
({
findTestSubject,
testSubjectExists,
userActions,
getFormErrorsMessages,
form,
getEuiStepsHorizontalActive,
goToStep,
} = initTestBed());
});

afterEach(() => {
server.restore();
});

describe('layout', () => {
beforeEach(async () => {
await goToStep(2);
});

it('should have the horizontal step active on "Date histogram"', () => {
expect(getEuiStepsHorizontalActive()).toContain('Date histogram');
});

it('should have the title set to "Date histogram"', () => {
expect(testSubjectExists('rollupJobCreateDateHistogramTitle')).toBe(true);
});

it('should have a link to the documentation', () => {
expect(testSubjectExists('rollupJobCreateDateHistogramDocsButton')).toBe(true);
});

it('should have the "next" and "back" button visible', () => {
expect(testSubjectExists('rollupJobBackButton')).toBe(true);
expect(testSubjectExists('rollupJobNextButton')).toBe(true);
expect(testSubjectExists('rollupJobSaveButton')).toBe(false);
});

it('should go to the "Logistics" step when clicking the back button', async () => {
userActions.clickPreviousStep();
expect(getEuiStepsHorizontalActive()).toContain('Logistics');
});
});

describe('Date field select', () => {
it('should set the options value from the index pattern', async () => {
const dateFields = ['field1', 'field2', 'field3'];
mockIndexPatternValidityResponse({ dateFields });

await goToStep(2);

const dateFieldSelectOptionsValues = findTestSubject('rollupJobCreateDateFieldSelect').find('option').map(option => option.text());
expect(dateFieldSelectOptionsValues).toEqual(dateFields);
});
});

describe('time zone', () => {
it('should have a select with all the timezones', async () => {
await goToStep(2);

const timeZoneSelect = findTestSubject('rollupJobCreateTimeZoneSelect');
const options = timeZoneSelect.find('option').map(option => option.text());
expect(options).toEqual(moment.tz.names());
});
});

describe('form validation', () => {
beforeEach(async () => {
await goToStep(2);
});

it('should display errors when clicking "next" without filling the form', () => {
expect(testSubjectExists('rollupJobCreateStepError')).toBeFalsy();

userActions.clickNextStep();

expect(testSubjectExists('rollupJobCreateStepError')).toBeTruthy();
expect(getFormErrorsMessages()).toEqual(['Interval is required.']);
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
});

describe('interval', () => {
afterEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
});

it('should validate the interval format', () => {
form.setInputValue('rollupJobInterval', 'abc');
userActions.clickNextStep();
expect(getFormErrorsMessages()).toContain('Invalid interval format.');
});

it('should validate the calendar format', () => {
form.setInputValue('rollupJobInterval', '3y');
userActions.clickNextStep();
expect(getFormErrorsMessages()).toContain(`The 'y' unit only allows values of 1. Try 1y.`);
});
});
});
});