Skip to content

Commit

Permalink
Slight revision to logic and added test for wizard with rollup job af…
Browse files Browse the repository at this point in the history
…ter index pattern changed
  • Loading branch information
jloleysens committed Nov 13, 2019
1 parent 1a1f687 commit 8ac8af1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { JobCreate } from '../../../public/crud_app/sections';
import { JOB_TO_CLONE } from './constants';
import { deserializeJob } from '../../../public/crud_app/services';

const initTestBed = registerTestBed(JobCreate, {
store: createRollupJobsStore({
cloneJob: { job: deserializeJob(JOB_TO_CLONE.jobs[0]) },
}),
});

export const setup = props => {
const initTestBed = registerTestBed(JobCreate, {
store: createRollupJobsStore({
cloneJob: { job: deserializeJob(JOB_TO_CLONE.jobs[0]) },
}),
});
const testBed = initTestBed(props);
const { component } = testBed;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { setupEnvironment, pageHelpers } from './helpers';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants';

jest.mock('ui/new_platform');
Expand Down Expand Up @@ -134,4 +134,64 @@ describe('Cloning a rollup job through create job wizard', () => {
expect(checkedCountActual).toBe(checkedCountExpected);
});
});

it('should correctly reset defaults after index pattern changes', async () => {
// 1. Logistics

// Sanity check for rollup job name, i.e., we are in clone mode.
expect(find('rollupJobName').props().value).toBe(jobConfig.id + '-copy');

// Changing the index pattern value after cloning a rollup job should update a number of values.
// On each view of the set up wizard we check for the expected state after this change.
form.setInputValue('rollupIndexPattern', 'test');
// Fires off a network request.
await nextTick();

const {
groups: {
date_histogram: dateHistogram
},
} = jobConfig;

await actions.clickNextStep();

// 2. Date Histogram

expect(exists('rollupJobCreateDateHistogramTitle')).toBe(true);
expect(find('rollupJobCreateDateFieldSelect').props().value).toBe(dateHistogram.field);

await actions.clickNextStep();

// 3. Terms

expect(exists('rollupJobCreateTermsTitle')).toBe(true);
const { tableCellsValues: tableCellValuesTerms } = table.getMetaData('rollupJobTermsFieldList');
expect(tableCellValuesTerms[0][0]).toBe('No terms fields added');

await actions.clickNextStep();

// 4. Histogram

expect(exists('rollupJobCreateHistogramTitle')).toBe(true);
const { tableCellsValues: tableCellValuesHisto } = table.getMetaData(
'rollupJobHistogramFieldList'
);

expect(tableCellValuesHisto[0][0]).toBe('No histogram fields added');

await actions.clickNextStep();

// 5. Metrics

expect(exists('rollupJobCreateMetricsTitle')).toBe(true);
const { rows: metricsRows } = table.getMetaData('rollupJobMetricsFieldList');
// Empty placeholder value
expect(metricsRows.length).toBe(1);

// 6. Review

await actions.clickNextStep();

expect(exists('rollupJobCreateReviewTitle')).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export class JobCreateUi extends Component {
const indexPattern = this.getIndexPattern();
if (indexPattern !== this.getIndexPattern(prevState)) {


// If the user hasn't entered anything, then skip validation.
if (!indexPattern || !indexPattern.trim()) {
this.setState({
Expand Down Expand Up @@ -268,7 +267,6 @@ export class JobCreateUi extends Component {
indexPatternDateFields.sort();

if (resetDefaults) {
const { indexPatternDateFields } = this.state;
// Whenever the index pattern changes we default to the first date field if there is one.
this.onFieldsChange(
{
Expand Down

0 comments on commit 8ac8af1

Please sign in to comment.