Skip to content

Commit

Permalink
[Rollup] Fix for clone job workflow (#50501)
Browse files Browse the repository at this point in the history
* First iteration of fix for clone job workflow

* Second iteration of fix, previous had race condition :gasp:

* Slight revision to logic and added test for wizard with rollup job after index pattern changed
  • Loading branch information
jloleysens committed Nov 14, 2019
1 parent 34f3fee commit 54bb4c8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 18 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 @@ -125,13 +125,14 @@ export class JobCreateUi extends Component {
const { clearCloneJob, jobToClone } = this.props;
if (jobToClone) {
clearCloneJob();
this.requestIndexPatternValidation();
this.requestIndexPatternValidation(false);
}
}

componentDidUpdate(prevProps, prevState) { // eslint-disable-line no-unused-vars
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 @@ -159,7 +160,7 @@ export class JobCreateUi extends Component {
this.props.clearCreateJobErrors();
}

requestIndexPatternValidation = debounce(() => {
requestIndexPatternValidation = debounce((resetDefaults = true) => {
const indexPattern = this.getIndexPattern();

const lastIndexPatternValidationTime = this.lastIndexPatternValidationTime = Date.now();
Expand Down Expand Up @@ -265,6 +266,16 @@ export class JobCreateUi extends Component {

indexPatternDateFields.sort();

if (resetDefaults) {
// Whenever the index pattern changes we default to the first date field if there is one.
this.onFieldsChange(
{
dateHistogramField: indexPatternDateFields.length ? indexPatternDateFields[0] : undefined,
},
STEP_DATE_HISTOGRAM
);
}

this.setState({
indexPatternAsyncErrors,
indexPatternDateFields,
Expand All @@ -273,16 +284,6 @@ export class JobCreateUi extends Component {
indexPatternMetricsFields,
isValidatingIndexPattern: false,
});

if (!jobToClone) {
// Select first time field by default.
this.onFieldsChange(
{
dateHistogramField: indexPatternDateFields.length ? indexPatternDateFields[0] : null,
},
STEP_DATE_HISTOGRAM
);
}
}).catch(error => {
// We don't need to do anything if this component has been unmounted.
if (!this._isMounted) {
Expand Down

0 comments on commit 54bb4c8

Please sign in to comment.