-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Rollup] Fix component integration tests #121144
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
Changes from all commits
229e29d
e4f9654
f1bdc13
3e241b5
3b04a0f
53e6c7d
948bfa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| jest.mock('lodash', () => ({ | ||
| ...jest.requireActual('lodash'), | ||
| debounce: (fn: () => unknown) => fn, | ||
| })); | ||
|
|
||
| jest.mock('../../../crud_app/services/documentation_links', () => { | ||
| const coreMocks = jest.requireActual('../../../../../../../src/core/public/mocks'); | ||
|
|
||
| return { | ||
| init: jest.fn(), | ||
| documentationLinks: coreMocks.docLinksServiceMock.createStartContract().links, | ||
| }; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| * 2.0. | ||
| */ | ||
|
|
||
| import { act } from 'react-dom/test-utils'; | ||
|
|
||
| import { registerTestBed } from '@kbn/test/jest'; | ||
| import { rollupJobsStore } from '../../../crud_app/store'; | ||
| import { JobCreate } from '../../../crud_app/sections'; | ||
|
|
@@ -22,7 +24,9 @@ export const setup = (props) => { | |
| // User actions | ||
| const clickNextStep = () => { | ||
| const button = testBed.find('rollupJobNextButton'); | ||
| button.simulate('click'); | ||
| act(() => { | ||
| button.simulate('click'); | ||
| }); | ||
| component.update(); | ||
| }; | ||
|
|
||
|
|
@@ -34,31 +38,43 @@ export const setup = (props) => { | |
|
|
||
| const clickSave = () => { | ||
| const button = testBed.find('rollupJobSaveButton'); | ||
| button.simulate('click'); | ||
| act(() => { | ||
| button.simulate('click'); | ||
| }); | ||
| component.update(); | ||
| }; | ||
|
|
||
| // Forms | ||
| const fillFormFields = 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); | ||
| act(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure what's the difference between
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we want to be as synchronous as possible and use I usually start with the sync version and if the state does not update I change to the async one. With component integration tests it is not always easy to remember all the moving parts occuring after changing a field value or clicking a button. |
||
| form.setInputValue('rollupJobName', JOB_TO_CREATE.id); | ||
| }); | ||
| act(() => { | ||
| form.setInputValue('rollupIndexPattern', JOB_TO_CREATE.indexPattern); | ||
| }); | ||
| act(() => { | ||
| form.setInputValue('rollupIndexName', JOB_TO_CREATE.rollupIndex); | ||
| }); | ||
| break; | ||
| case 'date-histogram': | ||
| form.setInputValue('rollupJobInterval', JOB_TO_CREATE.interval); | ||
| act(() => { | ||
| form.setInputValue('rollupJobInterval', JOB_TO_CREATE.interval); | ||
| }); | ||
| break; | ||
| default: | ||
| return; | ||
| } | ||
|
|
||
| component.update(); | ||
| }; | ||
|
|
||
| // Navigation | ||
| const goToStep = async (targetStep) => { | ||
| const stepHandlers = { | ||
| 1: () => fillFormFields('logistics'), | ||
| 2: () => fillFormFields('date-histogram'), | ||
| 1: async () => await fillFormFields('logistics'), | ||
| 2: async () => await fillFormFields('date-histogram'), | ||
| }; | ||
|
|
||
| let currentStep = 1; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,16 +5,13 @@ | |
| * 2.0. | ||
| */ | ||
|
|
||
| import { mockHttpRequest, pageHelpers } from './helpers'; | ||
|
|
||
| import { act } from 'react-dom/test-utils'; | ||
| import { setHttp, init as initDocumentation } from '../../crud_app/services'; | ||
| import { mockHttpRequest, pageHelpers, nextTick } from './helpers'; | ||
| import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants'; | ||
| import { coreMock, docLinksServiceMock } from '../../../../../../src/core/public/mocks'; | ||
|
|
||
| jest.mock('lodash', () => ({ | ||
| ...jest.requireActual('lodash'), | ||
| debounce: (fn) => fn, | ||
| })); | ||
|
|
||
| const { setup } = pageHelpers.jobClone; | ||
| const { | ||
| jobs: [{ config: jobConfig }], | ||
|
|
@@ -29,11 +26,16 @@ describe('Cloning a rollup job through create job wizard', () => { | |
| let startMock; | ||
|
|
||
| beforeAll(() => { | ||
| jest.useFakeTimers(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering why we would need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to have the guarantee that there aren't any timeout running in the tests. We are not using jest for isolated unit tests but for component integration tests which load all the npm dependencies which could potentially use timeouts. And we don't want them in our test. By adding this on top of our tests we are removing any risk of timing out so I would recommend to declare |
||
| startMock = coreMock.createStart(); | ||
| setHttp(startMock.http); | ||
| initDocumentation(docLinksServiceMock.createStartContract()); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| mockHttpRequest(startMock.http, { indxPatternVldtResp: JOB_CLONE_INDEX_PATTERN_CHECK }); | ||
|
|
||
|
|
@@ -149,9 +151,10 @@ describe('Cloning a rollup job through create job wizard', () => { | |
|
|
||
| // 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(); | ||
|
|
||
| await act(async () => { | ||
| form.setInputValue('rollupIndexPattern', 'test'); | ||
| }); | ||
|
|
||
| const { | ||
| groups: { date_histogram: dateHistogram }, | ||
|
|
||
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.
Not relying on the
Datefor this as we can simply use an incremental counter. Better for the tests too.