Skip to content

Commit

Permalink
[Watcher] Use fixed_interval instead of interval (#113527)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga authored Oct 9, 2021
1 parent cbc4f52 commit 961fe75
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ export const useField = <T, FormType = FormData, I = T>(
if (resetValue) {
hasBeenReset.current = true;
const newValue = deserializeValue(updatedDefaultValue ?? defaultValue);
// updateStateIfMounted('value', newValue);
setValue(newValue);
return newValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { of } from 'rxjs';
import { ComponentType } from 'enzyme';
import { LocationDescriptorObject } from 'history';

import {
docLinksServiceMock,
uiSettingsServiceMock,
Expand All @@ -17,6 +18,7 @@ import {
scopedHistoryMock,
} from '../../../../../../src/core/public/mocks';
import { AppContextProvider } from '../../../public/application/app_context';
import { AppDeps } from '../../../public/application/app';
import { LicenseStatus } from '../../../common/types/license_status';

class MockTimeBuckets {
Expand All @@ -35,7 +37,7 @@ history.createHref.mockImplementation((location: LocationDescriptorObject) => {
return `${location.pathname}${location.search ? '?' + location.search : ''}`;
});

export const mockContextValue = {
export const mockContextValue: AppDeps = {
licenseStatus$: of<LicenseStatus>({ valid: true }),
docLinks: docLinksServiceMock.createStartContract(),
setBreadcrumbs: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { setup as watchCreateJsonSetup } from './watch_create_json.helpers';
import { setup as watchCreateThresholdSetup } from './watch_create_threshold.helpers';
import { setup as watchEditSetup } from './watch_edit.helpers';

export { nextTick, getRandomString, findTestSubject, TestBed } from '@kbn/test/jest';
export { getRandomString, findTestSubject, TestBed } from '@kbn/test/jest';
export { wrapBodyResponse, unwrapBodyResponse } from './body_response';
export { setupEnvironment } from './setup_environment';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';

import { init as initHttpRequests } from './http_requests';
import { setHttpClient, setSavedObjectsClient } from '../../../public/application/lib/api';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export type TestSubjects =
| 'toEmailAddressInput'
| 'triggerIntervalSizeInput'
| 'watchActionAccordion'
| 'watchActionAccordion.mockComboBox'
| 'watchActionAccordion.toEmailAddressInput'
| 'watchActionsPanel'
| 'watchThresholdButton'
| 'watchThresholdInput'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { act } from 'react-dom/test-utils';

import { registerTestBed, findTestSubject, TestBed, TestBedConfig, nextTick } from '@kbn/test/jest';
import { registerTestBed, findTestSubject, TestBed, TestBedConfig } from '@kbn/test/jest';
import { WatchList } from '../../../public/application/sections/watch_list/components/watch_list';
import { ROUTES, REFRESH_INTERVALS } from '../../../common/constants';
import { withAppContext } from './app_context.mock';
Expand All @@ -24,7 +24,6 @@ const initTestBed = registerTestBed(withAppContext(WatchList), testBedConfig);
export interface WatchListTestBed extends TestBed<WatchListTestSubjects> {
actions: {
selectWatchAt: (index: number) => void;
clickWatchAt: (index: number) => void;
clickWatchActionAt: (index: number, action: 'delete' | 'edit') => void;
searchWatches: (term: string) => void;
advanceTimeToTableRefresh: () => Promise<void>;
Expand All @@ -45,18 +44,6 @@ export const setup = async (): Promise<WatchListTestBed> => {
checkBox.simulate('change', { target: { checked: true } });
};

const clickWatchAt = async (index: number) => {
const { rows } = testBed.table.getMetaData('watchesTable');
const watchesLink = findTestSubject(rows[index].reactWrapper, 'watchesLink');

await act(async () => {
const { href } = watchesLink.props();
testBed.router.navigateTo(href!);
await nextTick();
testBed.component.update();
});
};

const clickWatchActionAt = async (index: number, action: 'delete' | 'edit') => {
const { component, table } = testBed;
const { rows } = table.getMetaData('watchesTable');
Expand Down Expand Up @@ -95,7 +82,6 @@ export const setup = async (): Promise<WatchListTestBed> => {
...testBed,
actions: {
selectWatchAt,
clickWatchAt,
clickWatchActionAt,
searchWatches,
advanceTimeToTableRefresh,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { act } from 'react-dom/test-utils';

import { registerTestBed, findTestSubject, TestBed, TestBedConfig, delay } from '@kbn/test/jest';
import { registerTestBed, findTestSubject, TestBed, TestBedConfig } from '@kbn/test/jest';
import { WatchStatus } from '../../../public/application/sections/watch_status/components/watch_status';
import { ROUTES } from '../../../common/constants';
import { WATCH_ID } from './jest_constants';
Expand Down Expand Up @@ -89,9 +89,8 @@ export const setup = async (): Promise<WatchStatusTestBed> => {

await act(async () => {
button.simulate('click');
await delay(100);
component.update();
});
component.update();
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { act } from 'react-dom/test-utils';

import { getExecuteDetails } from '../../__fixtures__';
import { defaultWatch } from '../../public/application/models/watch';
import { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
import { setupEnvironment, pageHelpers, wrapBodyResponse } from './helpers';
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';
import { WATCH } from './helpers/jest_constants';

Expand All @@ -19,19 +19,19 @@ describe('<JsonWatchEdit /> create route', () => {
const { server, httpRequestsMockHelpers } = setupEnvironment();
let testBed: WatchCreateJsonTestBed;

beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
server.restore();
});

describe('on component mount', () => {
beforeEach(async () => {
testBed = await setup();

await act(async () => {
const { component } = testBed;
await nextTick();
component.update();
});
testBed.component.update();
});

test('should set the correct page title', () => {
Expand Down Expand Up @@ -92,7 +92,6 @@ describe('<JsonWatchEdit /> create route', () => {

await act(async () => {
actions.clickSubmitButton();
await nextTick();
});

const latestRequest = server.requests[server.requests.length - 1];
Expand Down Expand Up @@ -141,9 +140,8 @@ describe('<JsonWatchEdit /> create route', () => {

await act(async () => {
actions.clickSubmitButton();
await nextTick();
component.update();
});
component.update();

expect(exists('sectionError')).toBe(true);
expect(find('sectionError').text()).toContain(error.message);
Expand All @@ -169,7 +167,6 @@ describe('<JsonWatchEdit /> create route', () => {

await act(async () => {
actions.clickSimulateButton();
await nextTick();
});

const latestRequest = server.requests[server.requests.length - 1];
Expand Down Expand Up @@ -230,9 +227,8 @@ describe('<JsonWatchEdit /> create route', () => {

await act(async () => {
actions.clickSimulateButton();
await nextTick();
component.update();
});
component.update();

const latestRequest = server.requests[server.requests.length - 1];

Expand Down
Loading

0 comments on commit 961fe75

Please sign in to comment.