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
sebelga
merged 25 commits into
elastic:master
from
sebelga:test/rollup_job_create_integration
Mar 14, 2019
Merged
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 6790f77
test(create rollup job): Logistics -> Validate rollup index name & cron
sebelga 8cdd23c
test(create rollup job): Logistics -> Validate page size
sebelga 9f292da
test(create rollup job): Logistics -> Validate navigation to step 2
sebelga aaadeb2
test(create rollup job): validate step 2 date histogram
sebelga e26f23b
Small refactor
sebelga f170bcd
test(create rollup job): step 3 terms
sebelga f7c4522
test(create rollup job): link to the docs
sebelga eee97d7
test(create rollup job): step 3 histogram
sebelga 1d3f79b
test(create rollup job): step 5 metrics
sebelga cf25359
test(create rollup job): step 6 review
sebelga 3d807f4
Merge remote-tracking branch 'upstream/master' into test/rollup_job_c…
sebelga 64ef85d
Split job create test steps into files
sebelga 2a6eb2e
Fix tipo
sebelga 8147bcf
Fix absolute import
sebelga 33d5a38
Fix absolute webpack import
sebelga 80562b9
Merge remote-tracking branch 'upstream/master' into test/rollup_job_c…
sebelga 5acdff5
[Rollup] Api integration test (Indices, index validity, crud)
sebelga 2a5d66b
Revert "[Rollup] Api integration test (Indices, index validity, crud)"
sebelga 432ce8f
Fix failing test
sebelga 98ae910
Fix enzyme_helpers import path
sebelga bdbbe91
Rename test folder to "client_integration"
sebelga 9a409a2
Merge remote-tracking branch 'upstream/master' into test/rollup_job_c…
sebelga 0193443
Fix failing test
sebelga 6a1908d
Fix absolute import from webpack alias
sebelga File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
1,298 changes: 0 additions & 1,298 deletions
1,298
x-pack/plugins/rollup/__jest__/integration_tests/job_create.test.js
This file was deleted.
Oops, something went wrong.
147 changes: 147 additions & 0 deletions
147
x-pack/plugins/rollup/__jest__/integration_tests/job_create.test_helpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}; | ||
|
||
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 }; | ||
}; | ||
|
137 changes: 137 additions & 0 deletions
137
x-pack/plugins/rollup/__jest__/integration_tests/job_create_date_histogram.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.`); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😊