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] Fix for clone job workflow #50501

Merged
merged 3 commits into from
Nov 14, 2019
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 @@ -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) {
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