Skip to content

Commit

Permalink
[Watcher] Re-enable jest tests (#162592)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Aug 9, 2023
1 parent fb6c9f0 commit 9fb83fe
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 159 deletions.
4 changes: 1 addition & 3 deletions .buildkite/disabled_jest_configs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[
"x-pack/plugins/watcher/jest.config.js"
]
[]
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

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

import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers';
import { HttpSetup } from '@kbn/core/public';

Expand All @@ -24,32 +26,45 @@ const testBedConfig: AsyncTestBedConfig = {

export interface WatchCreateJsonTestBed extends TestBed<WatchCreateJsonTestSubjects> {
actions: {
selectTab: (tab: 'edit' | 'simulate') => void;
clickSubmitButton: () => void;
clickSimulateButton: () => void;
selectTab: (tab: 'edit' | 'simulate') => Promise<void>;
clickSubmitButton: () => Promise<void>;
clickSimulateButton: () => Promise<void>;
};
}

export const setup = async (httpSetup: HttpSetup): Promise<WatchCreateJsonTestBed> => {
const initTestBed = registerTestBed(WithAppDependencies(WatchEditPage, httpSetup), testBedConfig);
const testBed = await initTestBed();
const { find, component } = testBed;

/**
* User Actions
*/

const selectTab = (tab: 'edit' | 'simulate') => {
const selectTab = async (tab: 'edit' | 'simulate') => {
const tabs = ['edit', 'simulate'];

testBed.find('tab').at(tabs.indexOf(tab)).simulate('click');
await act(async () => {
find('tab').at(tabs.indexOf(tab)).simulate('click');
});

component.update();
};

const clickSubmitButton = () => {
testBed.find('saveWatchButton').simulate('click');
const clickSubmitButton = async () => {
await act(async () => {
testBed.find('saveWatchButton').simulate('click');
});

component.update();
};

const clickSimulateButton = () => {
testBed.find('simulateWatchButton').simulate('click');
const clickSimulateButton = async () => {
await act(async () => {
testBed.find('simulateWatchButton').simulate('click');
});

component.update();
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

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

import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers';
import { HttpSetup } from '@kbn/core/public';

Expand All @@ -24,39 +26,56 @@ const testBedConfig: AsyncTestBedConfig = {

export interface WatchCreateThresholdTestBed extends TestBed<WatchCreateThresholdTestSubjects> {
actions: {
clickSubmitButton: () => void;
clickAddActionButton: () => void;
clickSubmitButton: () => Promise<void>;
clickAddActionButton: () => Promise<void>;
clickActionLink: (
actionType: 'logging' | 'email' | 'webhook' | 'index' | 'slack' | 'jira' | 'pagerduty'
) => void;
clickSimulateButton: () => void;
) => Promise<void>;
clickSimulateButton: () => Promise<void>;
};
}

export const setup = async (httpSetup: HttpSetup): Promise<WatchCreateThresholdTestBed> => {
const initTestBed = registerTestBed(WithAppDependencies(WatchEditPage, httpSetup), testBedConfig);
const testBed = await initTestBed();
const { find, component } = testBed;

/**
* User Actions
*/

const clickSubmitButton = () => {
testBed.find('saveWatchButton').simulate('click');
const clickSubmitButton = async () => {
await act(async () => {
find('saveWatchButton').simulate('click');
});

component.update();
};

const clickAddActionButton = () => {
testBed.find('addWatchActionButton').simulate('click');
const clickAddActionButton = async () => {
await act(async () => {
find('addWatchActionButton').simulate('click');
});

component.update();
};

const clickSimulateButton = () => {
testBed.find('simulateActionButton').simulate('click');
const clickSimulateButton = async () => {
await act(async () => {
find('simulateActionButton').simulate('click');
});

component.update();
};

const clickActionLink = (
const clickActionLink = async (
actionType: 'logging' | 'email' | 'webhook' | 'index' | 'slack' | 'jira' | 'pagerduty'
) => {
testBed.find(`${actionType}ActionButton`).simulate('click');
await act(async () => {
find(`${actionType}ActionButton`).simulate('click');
});

component.update();
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { act } from 'react-dom/test-utils';

import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers';
import { HttpSetup } from '@kbn/core/public';
Expand All @@ -25,7 +26,7 @@ const testBedConfig: AsyncTestBedConfig = {

export interface WatchEditTestBed extends TestBed<WatchEditSubjects> {
actions: {
clickSubmitButton: () => void;
clickSubmitButton: () => Promise<void>;
};
}

Expand All @@ -37,8 +38,12 @@ export const setup = async (httpSetup: HttpSetup): Promise<WatchEditTestBed> =>
* User Actions
*/

const clickSubmitButton = () => {
testBed.find('saveWatchButton').simulate('click');
const clickSubmitButton = async () => {
await act(async () => {
testBed.find('saveWatchButton').simulate('click');
});

testBed.component.update();
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const testBedConfig: AsyncTestBedConfig = {

export interface WatchListTestBed extends TestBed<WatchListTestSubjects> {
actions: {
selectWatchAt: (index: number) => void;
clickWatchActionAt: (index: number, action: 'delete' | 'edit') => void;
searchWatches: (term: string) => void;
selectWatchAt: (index: number) => Promise<void>;
clickWatchActionAt: (index: number, action: 'delete' | 'edit') => Promise<void>;
searchWatches: (term: string) => Promise<void>;
advanceTimeToTableRefresh: () => Promise<void>;
};
}
Expand All @@ -42,11 +42,15 @@ export const setup = async (httpSetup: HttpSetup): Promise<WatchListTestBed> =>
* User Actions
*/

const selectWatchAt = (index: number) => {
const selectWatchAt = async (index: number) => {
const { rows } = testBed.table.getMetaData('watchesTable');
const row = rows[index];
const checkBox = row.reactWrapper.find('input').hostNodes();
checkBox.simulate('change', { target: { checked: true } });

await act(async () => {
checkBox.simulate('change', { target: { checked: true } });
});
testBed.component.update();
};

const clickWatchActionAt = async (index: number, action: 'delete' | 'edit') => {
Expand All @@ -58,18 +62,21 @@ export const setup = async (httpSetup: HttpSetup): Promise<WatchListTestBed> =>

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

const searchWatches = (term: string) => {
const searchWatches = async (term: string) => {
const { find, component } = testBed;
const searchInput = find('watchesTableContainer').find('.euiFieldSearch');

// Enter input into the search box
// @ts-ignore
searchInput.instance().value = term;
searchInput.simulate('keyup', { key: 'Enter', keyCode: 13, which: 13 });

await act(async () => {
searchInput.simulate('keyup', { key: 'Enter', keyCode: 13, which: 13 });
});

component.update();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const testBedConfig: AsyncTestBedConfig = {

export interface WatchStatusTestBed extends TestBed<WatchStatusTestSubjects> {
actions: {
selectTab: (tab: 'execution history' | 'action statuses') => void;
clickToggleActivationButton: () => void;
clickAcknowledgeButton: (index: number) => void;
clickDeleteWatchButton: () => void;
clickWatchExecutionAt: (index: number, tableCellText: string) => void;
selectTab: (tab: 'execution history' | 'action statuses') => Promise<void>;
clickToggleActivationButton: () => Promise<void>;
clickAcknowledgeButton: (index: number) => Promise<void>;
clickDeleteWatchButton: () => Promise<void>;
clickWatchExecutionAt: (index: number, tableCellText: string) => Promise<void>;
};
}

Expand All @@ -51,10 +51,14 @@ export const setup = async (httpSetup: HttpSetup): Promise<WatchStatusTestBed> =
* User Actions
*/

const selectTab = (tab: 'execution history' | 'action statuses') => {
const selectTab = async (tab: 'execution history' | 'action statuses') => {
const { component, find } = testBed;
const tabs = ['execution history', 'action statuses'];

testBed.find('tab').at(tabs.indexOf(tab)).simulate('click');
await act(async () => {
find('tab').at(tabs.indexOf(tab)).simulate('click');
});
component.update();
};

const clickToggleActivationButton = async () => {
Expand All @@ -63,8 +67,8 @@ export const setup = async (httpSetup: HttpSetup): Promise<WatchStatusTestBed> =

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

const clickAcknowledgeButton = async (index: number) => {
Expand All @@ -76,8 +80,8 @@ export const setup = async (httpSetup: HttpSetup): Promise<WatchStatusTestBed> =

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

const clickDeleteWatchButton = async () => {
Expand All @@ -86,8 +90,8 @@ export const setup = async (httpSetup: HttpSetup): Promise<WatchStatusTestBed> =

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

const clickWatchExecutionAt = async (index: number, tableCellText: string) => {
Expand Down
Loading

0 comments on commit 9fb83fe

Please sign in to comment.