Revert "Get rid of axios dependency in the Upgrade Assistant tests. (#127122)"

This reverts commit 53420d8658.
This commit is contained in:
Jonathan Budzenski 2022-03-15 09:40:36 -05:00
parent c4ccc00227
commit 7b86f00528
28 changed files with 476 additions and 408 deletions

View file

@ -8,7 +8,6 @@
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers';
import { HttpSetup } from 'src/core/public';
import { App } from '../../../public/application/app';
import { WithAppDependencies } from '../helpers';
@ -40,14 +39,8 @@ const createActions = (testBed: TestBed) => {
};
};
export const setupAppPage = async (
httpSetup: HttpSetup,
overrides?: Record<string, unknown>
): Promise<AppTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(App, httpSetup, overrides),
testBedConfig
);
export const setupAppPage = async (overrides?: Record<string, unknown>): Promise<AppTestBed> => {
const initTestBed = registerTestBed(WithAppDependencies(App, overrides), testBedConfig);
const testBed = await initTestBed();
return {

View file

@ -12,17 +12,20 @@ import { AppTestBed, setupAppPage } from './app.helpers';
describe('Cluster upgrade', () => {
let testBed: AppTestBed;
let server: ReturnType<typeof setupEnvironment>['server'];
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
beforeEach(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});
afterEach(() => {
server.restore();
});
describe('when user is still preparing for upgrade', () => {
beforeEach(async () => {
testBed = await setupAppPage(httpSetup);
testBed = await setupAppPage();
});
test('renders overview', () => {
@ -49,7 +52,7 @@ describe('Cluster upgrade', () => {
});
await act(async () => {
testBed = await setupAppPage(httpSetup);
testBed = await setupAppPage();
});
});
@ -73,7 +76,7 @@ describe('Cluster upgrade', () => {
});
await act(async () => {
testBed = await setupAppPage(httpSetup);
testBed = await setupAppPage();
});
});

View file

@ -7,8 +7,7 @@
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers';
import { HttpSetup } from 'src/core/public';
import { EsDeprecationLogs } from '../../../public/application/components';
import { EsDeprecationLogs } from '../../../public/application/components/es_deprecation_logs';
import { WithAppDependencies } from '../helpers';
const testBedConfig: AsyncTestBedConfig = {
@ -66,11 +65,10 @@ const createActions = (testBed: TestBed) => {
};
export const setupESDeprecationLogsPage = async (
httpSetup: HttpSetup,
overrides?: Record<string, unknown>
): Promise<EsDeprecationLogsTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(EsDeprecationLogs, httpSetup, overrides),
WithAppDependencies(EsDeprecationLogs, overrides),
testBedConfig
);
const testBed = await initTestBed();

View file

@ -41,18 +41,18 @@ const getLoggingResponse = (toggle: boolean): DeprecationLoggingStatus => ({
describe('ES deprecation logs', () => {
let testBed: EsDeprecationLogsTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
beforeEach(async () => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(getLoggingResponse(true));
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
testBed.component.update();
});
afterAll(() => {
server.restore();
});
describe('Documentation link', () => {
test('Has a link for migration info api docs in page header', () => {
const { exists } = testBed;
@ -71,11 +71,8 @@ describe('ES deprecation logs', () => {
await actions.clickDeprecationToggle();
expect(httpSetup.put).toHaveBeenLastCalledWith(
`/api/upgrade_assistant/deprecation_logging`,
expect.objectContaining({ body: JSON.stringify({ isEnabled: false }) })
);
const latestRequest = server.requests[server.requests.length - 1];
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual({ isEnabled: false });
expect(find('deprecationLoggingToggle').props()['aria-checked']).toBe(false);
});
@ -86,7 +83,7 @@ describe('ES deprecation logs', () => {
});
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { exists, component } = testBed;
@ -122,7 +119,7 @@ describe('ES deprecation logs', () => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(undefined, error);
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { component, exists } = testBed;
@ -139,7 +136,7 @@ describe('ES deprecation logs', () => {
});
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { exists, component } = testBed;
@ -159,7 +156,7 @@ describe('ES deprecation logs', () => {
test('Has a link to see logs in observability app', async () => {
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup, {
testBed = await setupESDeprecationLogsPage({
http: {
basePath: {
prepend: (url: string) => url,
@ -197,7 +194,7 @@ describe('ES deprecation logs', () => {
test('Has a link to see logs in discover app', async () => {
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { exists, component, find } = testBed;
@ -236,7 +233,7 @@ describe('ES deprecation logs', () => {
});
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { find, exists, component } = testBed;
@ -253,7 +250,7 @@ describe('ES deprecation logs', () => {
});
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { find, exists, component } = testBed;
@ -274,7 +271,7 @@ describe('ES deprecation logs', () => {
httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse(undefined, error);
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { exists, actions, component } = testBed;
@ -298,7 +295,7 @@ describe('ES deprecation logs', () => {
});
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { exists, actions, component } = testBed;
@ -330,7 +327,7 @@ describe('ES deprecation logs', () => {
const addDanger = jest.fn();
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup, {
testBed = await setupESDeprecationLogsPage({
services: {
core: {
notifications: {
@ -368,7 +365,7 @@ describe('ES deprecation logs', () => {
count: 0,
});
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
afterEach(() => {
@ -404,7 +401,7 @@ describe('ES deprecation logs', () => {
test('It shows copy with compatibility api header advice', async () => {
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed = await setupESDeprecationLogsPage();
});
const { exists, component } = testBed;
@ -428,7 +425,7 @@ describe('ES deprecation logs', () => {
test(`doesn't show analyze and resolve logs if it doesn't have the right privileges`, async () => {
await act(async () => {
testBed = await setupESDeprecationLogsPage(httpSetup, {
testBed = await setupESDeprecationLogsPage({
privileges: {
hasAllPrivileges: false,
missingPrivileges: {

View file

@ -13,13 +13,13 @@ import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './moc
describe('Default deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
afterAll(() => {
server.restore();
});
beforeEach(async () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esDeprecationsMockResponse);
httpRequestsMockHelpers.setUpgradeMlSnapshotStatusResponse({
nodeId: 'my_node',
@ -27,7 +27,7 @@ describe('Default deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
@ -39,9 +39,7 @@ describe('Default deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, {
isReadOnlyMode: false,
});
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();

View file

@ -20,13 +20,13 @@ import {
describe('ES deprecations table', () => {
let testBed: ElasticsearchTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
afterAll(() => {
server.restore();
});
beforeEach(async () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esDeprecationsMockResponse);
httpRequestsMockHelpers.setUpgradeMlSnapshotStatusResponse({
nodeId: 'my_node',
@ -34,7 +34,7 @@ describe('ES deprecations table', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
@ -47,7 +47,7 @@ describe('ES deprecations table', () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse([]);
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -66,6 +66,7 @@ describe('ES deprecations table', () => {
it('refreshes deprecation data', async () => {
const { actions } = testBed;
const totalRequests = server.requests.length;
await actions.table.clickRefreshButton();
@ -73,24 +74,21 @@ describe('ES deprecations table', () => {
const reindexDeprecation = esDeprecationsMockResponse.deprecations[3];
// Since upgradeStatusMockResponse includes ML and reindex actions (which require fetching status), there will be 4 requests made
expect(httpSetup.get).toHaveBeenCalledWith(
`${API_BASE_PATH}/es_deprecations`,
expect.anything()
expect(server.requests.length).toBe(totalRequests + 4);
expect(server.requests[server.requests.length - 4].url).toBe(
`${API_BASE_PATH}/es_deprecations`
);
expect(httpSetup.get).toHaveBeenCalledWith(
expect(server.requests[server.requests.length - 3].url).toBe(
`${API_BASE_PATH}/ml_snapshots/${(mlDeprecation.correctiveAction as MlAction).jobId}/${
(mlDeprecation.correctiveAction as MlAction).snapshotId
}`,
expect.anything()
}`
);
expect(httpSetup.get).toHaveBeenCalledWith(
`${API_BASE_PATH}/reindex/${reindexDeprecation.index}`,
expect.anything()
expect(server.requests[server.requests.length - 2].url).toBe(
`${API_BASE_PATH}/reindex/${reindexDeprecation.index}`
);
expect(httpSetup.get).toHaveBeenCalledWith(
`${API_BASE_PATH}/ml_upgrade_mode`,
expect.anything()
expect(server.requests[server.requests.length - 1].url).toBe(
`${API_BASE_PATH}/ml_upgrade_mode`
);
});
@ -113,9 +111,7 @@ describe('ES deprecations table', () => {
httpRequestsMockHelpers.setLoadRemoteClustersResponse(['test_remote_cluster']);
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, {
isReadOnlyMode: false,
});
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -221,9 +217,7 @@ describe('ES deprecations table', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, {
isReadOnlyMode: false,
});
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -305,7 +299,7 @@ describe('ES deprecations table', () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(noDeprecationsResponse);
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();

View file

@ -12,12 +12,10 @@ import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.
describe('Error handling', () => {
let testBed: ElasticsearchTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
afterAll(() => {
server.restore();
});
it('handles 403', async () => {
@ -30,7 +28,7 @@ describe('Error handling', () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { component, find } = testBed;
@ -55,7 +53,7 @@ describe('Error handling', () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { component, find } = testBed;
@ -78,7 +76,7 @@ describe('Error handling', () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { component, find } = testBed;
@ -98,7 +96,7 @@ describe('Error handling', () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { component, find } = testBed;

View file

@ -7,8 +7,7 @@
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers';
import { HttpSetup } from 'src/core/public';
import { EsDeprecations } from '../../../public/application/components';
import { EsDeprecations } from '../../../public/application/components/es_deprecations';
import { WithAppDependencies } from '../helpers';
const testBedConfig: AsyncTestBedConfig = {
@ -147,11 +146,10 @@ const createActions = (testBed: TestBed) => {
};
export const setupElasticsearchPage = async (
httpSetup: HttpSetup,
overrides?: Record<string, unknown>
): Promise<ElasticsearchTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(EsDeprecations, httpSetup, overrides),
WithAppDependencies(EsDeprecations, overrides),
testBedConfig
);
const testBed = await initTestBed();

View file

@ -9,23 +9,18 @@ import { act } from 'react-dom/test-utils';
import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';
import {
esDeprecationsMockResponse,
MOCK_SNAPSHOT_ID,
MOCK_JOB_ID,
MOCK_REINDEX_DEPRECATION,
} from './mocked_responses';
import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './mocked_responses';
describe('Index settings deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
const { server, httpRequestsMockHelpers } = setupEnvironment();
const indexSettingDeprecation = esDeprecationsMockResponse.deprecations[1];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
afterAll(() => {
server.restore();
});
beforeEach(async () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esDeprecationsMockResponse);
httpRequestsMockHelpers.setUpgradeMlSnapshotStatusResponse({
nodeId: 'my_node',
@ -33,7 +28,7 @@ describe('Index settings deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
@ -45,7 +40,7 @@ describe('Index settings deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { actions, component } = testBed;
@ -53,7 +48,7 @@ describe('Index settings deprecation flyout', () => {
await actions.table.clickDeprecationRowAt('indexSetting', 0);
});
it('renders a flyout with deprecation details', async () => {
test('renders a flyout with deprecation details', async () => {
const { find, exists } = testBed;
expect(exists('indexSettingsDetails')).toBe(true);
@ -69,7 +64,7 @@ describe('Index settings deprecation flyout', () => {
it('removes deprecated index settings', async () => {
const { find, actions, exists } = testBed;
httpRequestsMockHelpers.setUpdateIndexSettingsResponse(indexSettingDeprecation.index!, {
httpRequestsMockHelpers.setUpdateIndexSettingsResponse({
acknowledged: true,
});
@ -77,10 +72,13 @@ describe('Index settings deprecation flyout', () => {
await actions.indexSettingsDeprecationFlyout.clickDeleteSettingsButton();
expect(httpSetup.post).toHaveBeenLastCalledWith(
`/api/upgrade_assistant/${indexSettingDeprecation.index!}/index_settings`,
expect.anything()
const request = server.requests[server.requests.length - 1];
expect(request.method).toBe('POST');
expect(request.url).toBe(
`/api/upgrade_assistant/${indexSettingDeprecation.index!}/index_settings`
);
expect(request.status).toEqual(200);
// Verify the "Resolution" column of the table is updated
expect(find('indexSettingsResolutionStatusCell').at(0).text()).toEqual(
@ -106,18 +104,17 @@ describe('Index settings deprecation flyout', () => {
message: 'Remove index settings error',
};
httpRequestsMockHelpers.setUpdateIndexSettingsResponse(
indexSettingDeprecation.index!,
undefined,
error
);
httpRequestsMockHelpers.setUpdateIndexSettingsResponse(undefined, error);
await actions.indexSettingsDeprecationFlyout.clickDeleteSettingsButton();
expect(httpSetup.post).toHaveBeenLastCalledWith(
`/api/upgrade_assistant/${indexSettingDeprecation.index!}/index_settings`,
expect.anything()
const request = server.requests[server.requests.length - 1];
expect(request.method).toBe('POST');
expect(request.url).toBe(
`/api/upgrade_assistant/${indexSettingDeprecation.index!}/index_settings`
);
expect(request.status).toEqual(500);
// Verify the "Resolution" column of the table is updated
expect(find('indexSettingsResolutionStatusCell').at(0).text()).toEqual(

View file

@ -14,14 +14,14 @@ import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './moc
describe('Machine learning deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();
const mlDeprecation = esDeprecationsMockResponse.deprecations[0];
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
afterAll(() => {
server.restore();
});
beforeEach(async () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esDeprecationsMockResponse);
httpRequestsMockHelpers.setLoadMlUpgradeModeResponse({ mlUpgradeModeEnabled: false });
httpRequestsMockHelpers.setUpgradeMlSnapshotStatusResponse({
@ -30,7 +30,7 @@ describe('Machine learning deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
@ -42,7 +42,7 @@ describe('Machine learning deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(mockEnvironment.httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { actions, component } = testBed;
@ -84,15 +84,15 @@ describe('Machine learning deprecation flyout', () => {
await actions.mlDeprecationFlyout.clickUpgradeSnapshot();
// First, we expect a POST request to upgrade the snapshot
expect(httpSetup.post).toHaveBeenLastCalledWith(
'/api/upgrade_assistant/ml_snapshots',
expect.anything()
);
const upgradeRequest = server.requests[server.requests.length - 2];
expect(upgradeRequest.method).toBe('POST');
expect(upgradeRequest.url).toBe('/api/upgrade_assistant/ml_snapshots');
// Next, we expect a GET request to check the status of the upgrade
expect(httpSetup.get).toHaveBeenLastCalledWith(
`/api/upgrade_assistant/ml_snapshots/${MOCK_JOB_ID}/${MOCK_SNAPSHOT_ID}`,
expect.anything()
const statusRequest = server.requests[server.requests.length - 1];
expect(statusRequest.method).toBe('GET');
expect(statusRequest.url).toBe(
`/api/upgrade_assistant/ml_snapshots/${MOCK_JOB_ID}/${MOCK_SNAPSHOT_ID}`
);
// Verify the "Resolution" column of the table is updated
@ -128,10 +128,9 @@ describe('Machine learning deprecation flyout', () => {
await actions.mlDeprecationFlyout.clickUpgradeSnapshot();
expect(httpSetup.post).toHaveBeenLastCalledWith(
'/api/upgrade_assistant/ml_snapshots',
expect.anything()
);
const upgradeRequest = server.requests[server.requests.length - 1];
expect(upgradeRequest.method).toBe('POST');
expect(upgradeRequest.url).toBe('/api/upgrade_assistant/ml_snapshots');
// Verify the "Resolution" column of the table is updated
expect(find('mlActionResolutionCell').text()).toContain('Upgrade failed');
@ -148,12 +147,10 @@ describe('Machine learning deprecation flyout', () => {
});
it('Disables actions if ml_upgrade_mode is enabled', async () => {
httpRequestsMockHelpers.setLoadMlUpgradeModeResponse({
mlUpgradeModeEnabled: true,
});
httpRequestsMockHelpers.setLoadMlUpgradeModeResponse({ mlUpgradeModeEnabled: true });
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { actions, exists, component } = testBed;
@ -175,9 +172,7 @@ describe('Machine learning deprecation flyout', () => {
it('successfully deletes snapshots', async () => {
const { find, actions, exists } = testBed;
const jobId = (mlDeprecation.correctiveAction! as MlAction).jobId;
const snapshotId = (mlDeprecation.correctiveAction! as MlAction).snapshotId;
httpRequestsMockHelpers.setDeleteMlSnapshotResponse(jobId, snapshotId, {
httpRequestsMockHelpers.setDeleteMlSnapshotResponse({
acknowledged: true,
});
@ -186,9 +181,13 @@ describe('Machine learning deprecation flyout', () => {
await actions.mlDeprecationFlyout.clickDeleteSnapshot();
expect(httpSetup.delete).toHaveBeenLastCalledWith(
`/api/upgrade_assistant/ml_snapshots/${jobId}/${snapshotId}`,
expect.anything()
const request = server.requests[server.requests.length - 1];
expect(request.method).toBe('DELETE');
expect(request.url).toBe(
`/api/upgrade_assistant/ml_snapshots/${
(mlDeprecation.correctiveAction! as MlAction).jobId
}/${(mlDeprecation.correctiveAction! as MlAction).snapshotId}`
);
// Verify the "Resolution" column of the table is updated
@ -213,15 +212,17 @@ describe('Machine learning deprecation flyout', () => {
message: 'Upgrade snapshot error',
};
const jobId = (mlDeprecation.correctiveAction! as MlAction).jobId;
const snapshotId = (mlDeprecation.correctiveAction! as MlAction).snapshotId;
httpRequestsMockHelpers.setDeleteMlSnapshotResponse(jobId, snapshotId, undefined, error);
httpRequestsMockHelpers.setDeleteMlSnapshotResponse(undefined, error);
await actions.mlDeprecationFlyout.clickDeleteSnapshot();
expect(httpSetup.delete).toHaveBeenLastCalledWith(
`/api/upgrade_assistant/ml_snapshots/${jobId}/${snapshotId}`,
expect.anything()
const request = server.requests[server.requests.length - 1];
expect(request.method).toBe('DELETE');
expect(request.url).toBe(
`/api/upgrade_assistant/ml_snapshots/${
(mlDeprecation.correctiveAction! as MlAction).jobId
}/${(mlDeprecation.correctiveAction! as MlAction).snapshotId}`
);
// Verify the "Resolution" column of the table is updated

View file

@ -26,7 +26,7 @@ export const MOCK_ML_DEPRECATION: EnrichedDeprecationInfo = {
},
};
export const MOCK_REINDEX_DEPRECATION: EnrichedDeprecationInfo = {
const MOCK_REINDEX_DEPRECATION: EnrichedDeprecationInfo = {
isCritical: true,
resolveDuringUpgrade: false,
type: 'index_settings',

View file

@ -10,12 +10,7 @@ import { act } from 'react-dom/test-utils';
import { ReindexStatus, ReindexStep, ReindexStatusResponse } from '../../../common/types';
import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';
import {
esDeprecationsMockResponse,
MOCK_SNAPSHOT_ID,
MOCK_JOB_ID,
MOCK_REINDEX_DEPRECATION,
} from './mocked_responses';
import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './mocked_responses';
const defaultReindexStatusMeta: ReindexStatusResponse['meta'] = {
indexName: 'foo',
@ -26,6 +21,7 @@ const defaultReindexStatusMeta: ReindexStatusResponse['meta'] = {
// Note: The reindexing flyout UX is subject to change; more tests should be added here once functionality is built out
describe('Reindex deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();
beforeAll(() => {
jest.useFakeTimers();
@ -33,15 +29,10 @@ describe('Reindex deprecation flyout', () => {
afterAll(() => {
jest.useRealTimers();
server.restore();
});
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esDeprecationsMockResponse);
httpRequestsMockHelpers.setUpgradeMlSnapshotStatusResponse({
nodeId: 'my_node',
@ -49,7 +40,7 @@ describe('Reindex deprecation flyout', () => {
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
@ -61,7 +52,7 @@ describe('Reindex deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -80,8 +71,15 @@ describe('Reindex deprecation flyout', () => {
});
it('renders error callout when reindex fails', async () => {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
meta: defaultReindexStatusMeta,
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -90,7 +88,7 @@ describe('Reindex deprecation flyout', () => {
await actions.table.clickDeprecationRowAt('reindex', 0);
httpRequestsMockHelpers.setStartReindexingResponse(MOCK_REINDEX_DEPRECATION.index!, undefined, {
httpRequestsMockHelpers.setStartReindexingResponse(undefined, {
statusCode: 404,
message: 'no such index [test]',
});
@ -101,13 +99,13 @@ describe('Reindex deprecation flyout', () => {
});
it('renders error callout when fetch status fails', async () => {
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, undefined, {
httpRequestsMockHelpers.setReindexStatusResponse(undefined, {
statusCode: 404,
message: 'no such index [test]',
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -129,7 +127,7 @@ describe('Reindex deprecation flyout', () => {
});
it('has started but not yet reindexing documents', async () => {
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.inProgress,
lastCompletedStep: ReindexStep.readonly,
@ -141,7 +139,7 @@ describe('Reindex deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -154,7 +152,7 @@ describe('Reindex deprecation flyout', () => {
});
it('has started reindexing documents', async () => {
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.inProgress,
lastCompletedStep: ReindexStep.reindexStarted,
@ -166,7 +164,7 @@ describe('Reindex deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -179,7 +177,7 @@ describe('Reindex deprecation flyout', () => {
});
it('has completed reindexing documents', async () => {
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.inProgress,
lastCompletedStep: ReindexStep.reindexCompleted,
@ -191,7 +189,7 @@ describe('Reindex deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
testBed.component.update();
@ -204,7 +202,7 @@ describe('Reindex deprecation flyout', () => {
});
it('has completed', async () => {
httpRequestsMockHelpers.setReindexStatusResponse(MOCK_REINDEX_DEPRECATION.index!, {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.completed,
lastCompletedStep: ReindexStep.aliasCreated,
@ -216,7 +214,7 @@ describe('Reindex deprecation flyout', () => {
});
await act(async () => {
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});
const { actions, find, exists, component } = testBed;

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { httpServiceMock } from '../../../../../../src/core/public/mocks';
import sinon, { SinonFakeServer } from 'sinon';
import { API_BASE_PATH } from '../../../common/constants';
import {
@ -15,132 +15,204 @@ import {
ResponseError,
} from '../../../common/types';
type HttpMethod = 'GET' | 'PUT' | 'DELETE' | 'POST';
// Register helpers to mock HTTP Requests
const registerHttpRequestMockHelpers = (
httpSetup: ReturnType<typeof httpServiceMock.createStartContract>,
shouldDelayResponse: () => boolean
) => {
const mockResponses = new Map<HttpMethod, Map<string, Promise<unknown>>>(
['GET', 'PUT', 'DELETE', 'POST'].map(
(method) => [method, new Map()] as [HttpMethod, Map<string, Promise<unknown>>]
)
);
const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const setLoadCloudBackupStatusResponse = (
response?: CloudBackupStatus,
error?: ResponseError
) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const mockMethodImplementation = (method: HttpMethod, path: string) => {
const responsePromise = mockResponses.get(method)?.get(path) ?? Promise.resolve({});
if (shouldDelayResponse()) {
return new Promise((resolve) => {
setTimeout(() => resolve(responsePromise), 1000);
});
}
return responsePromise;
server.respondWith('GET', `${API_BASE_PATH}/cloud_backup_status`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
httpSetup.get.mockImplementation((path) =>
mockMethodImplementation('GET', path as unknown as string)
);
httpSetup.delete.mockImplementation((path) =>
mockMethodImplementation('DELETE', path as unknown as string)
);
httpSetup.post.mockImplementation((path) =>
mockMethodImplementation('POST', path as unknown as string)
);
httpSetup.put.mockImplementation((path) =>
mockMethodImplementation('PUT', path as unknown as string)
);
const setLoadEsDeprecationsResponse = (response?: ESUpgradeStatus, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const mockResponse = (method: HttpMethod, path: string, response?: unknown, error?: unknown) => {
const defuse = (promise: Promise<unknown>) => {
promise.catch(() => {});
return promise;
};
return mockResponses
.get(method)!
.set(path, error ? defuse(Promise.reject({ body: error })) : Promise.resolve(response));
server.respondWith('GET', `${API_BASE_PATH}/es_deprecations`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setLoadCloudBackupStatusResponse = (response?: CloudBackupStatus, error?: ResponseError) =>
mockResponse('GET', `${API_BASE_PATH}/cloud_backup_status`, response, error);
const setLoadEsDeprecationsResponse = (response?: ESUpgradeStatus, error?: ResponseError) =>
mockResponse('GET', `${API_BASE_PATH}/es_deprecations`, response, error);
const setLoadDeprecationLoggingResponse = (
response?: DeprecationLoggingStatus,
error?: ResponseError
) => mockResponse('GET', `${API_BASE_PATH}/deprecation_logging`, response, error);
) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('GET', `${API_BASE_PATH}/deprecation_logging`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setLoadDeprecationLogsCountResponse = (
response?: { count: number },
error?: ResponseError
) => mockResponse('GET', `${API_BASE_PATH}/deprecation_logging/count`, response, error);
) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const setDeleteLogsCacheResponse = (response?: string, error?: ResponseError) =>
mockResponse('DELETE', `${API_BASE_PATH}/deprecation_logging/cache`, response, error);
server.respondWith('GET', `${API_BASE_PATH}/deprecation_logging/count`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setDeleteLogsCacheResponse = (response?: string, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('DELETE', `${API_BASE_PATH}/deprecation_logging/cache`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setUpdateDeprecationLoggingResponse = (
response?: DeprecationLoggingStatus,
error?: ResponseError
) => mockResponse('PUT', `${API_BASE_PATH}/deprecation_logging`, response, error);
) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const setUpdateIndexSettingsResponse = (
indexName: string,
response?: object,
error?: ResponseError
) => mockResponse('POST', `${API_BASE_PATH}/${indexName}/index_settings`, response, error);
server.respondWith('PUT', `${API_BASE_PATH}/deprecation_logging`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setUpgradeMlSnapshotResponse = (response?: object, error?: ResponseError) =>
mockResponse('POST', `${API_BASE_PATH}/ml_snapshots`, response, error);
const setUpdateIndexSettingsResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('POST', `${API_BASE_PATH}/:indexName/index_settings`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setUpgradeMlSnapshotStatusResponse = (
response?: Record<string, unknown>,
error?: ResponseError
) =>
mockResponse(
'GET',
`${API_BASE_PATH}/ml_snapshots/${response?.jobId}/${response?.snapshotId}`,
response,
error
);
const setUpgradeMlSnapshotResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const setReindexStatusResponse = (
indexName: string,
response?: Record<string, any>,
error?: ResponseError
) => mockResponse('GET', `${API_BASE_PATH}/reindex/${indexName}`, response, error);
server.respondWith('POST', `${API_BASE_PATH}/ml_snapshots`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setStartReindexingResponse = (
indexName: string,
response?: object,
error?: ResponseError
) => mockResponse('POST', `${API_BASE_PATH}/reindex/${indexName}`, response, error);
const setUpgradeMlSnapshotStatusResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const setDeleteMlSnapshotResponse = (
jobId: string,
snapshotId: string,
response?: object,
error?: ResponseError
) =>
mockResponse('DELETE', `${API_BASE_PATH}/ml_snapshots/${jobId}/${snapshotId}`, response, error);
server.respondWith('GET', `${API_BASE_PATH}/ml_snapshots/:jobId/:snapshotId`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setLoadSystemIndicesMigrationStatus = (response?: object, error?: ResponseError) =>
mockResponse('GET', `${API_BASE_PATH}/system_indices_migration`, response, error);
const setReindexStatusResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const setLoadMlUpgradeModeResponse = (response?: object, error?: ResponseError) =>
mockResponse('GET', `${API_BASE_PATH}/ml_upgrade_mode`, response, error);
server.respondWith('GET', `${API_BASE_PATH}/reindex/:indexName`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setSystemIndicesMigrationResponse = (response?: object, error?: ResponseError) =>
mockResponse('POST', `${API_BASE_PATH}/system_indices_migration`, response, error);
const setStartReindexingResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
const setGetUpgradeStatusResponse = (response?: object, error?: ResponseError) =>
mockResponse('GET', `${API_BASE_PATH}/status`, response, error);
server.respondWith('POST', `${API_BASE_PATH}/reindex/:indexName`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setLoadRemoteClustersResponse = (response?: object, error?: ResponseError) =>
mockResponse('GET', `${API_BASE_PATH}/remote_clusters`, response, error);
const setDeleteMlSnapshotResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('DELETE', `${API_BASE_PATH}/ml_snapshots/:jobId/:snapshotId`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setLoadSystemIndicesMigrationStatus = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('GET', `${API_BASE_PATH}/system_indices_migration`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setLoadMlUpgradeModeResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('GET', `${API_BASE_PATH}/ml_upgrade_mode`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setSystemIndicesMigrationResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('POST', `${API_BASE_PATH}/system_indices_migration`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setGetUpgradeStatusResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('GET', `${API_BASE_PATH}/status`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
const setLoadRemoteClustersResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
server.respondWith('GET', `${API_BASE_PATH}/remote_clusters`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};
return {
setLoadCloudBackupStatusResponse,
@ -164,18 +236,29 @@ const registerHttpRequestMockHelpers = (
};
export const init = () => {
let isResponseDelayed = false;
const getDelayResponse = () => isResponseDelayed;
const setDelayResponse = (shouldDelayResponse: boolean) => {
isResponseDelayed = shouldDelayResponse;
const server = sinon.fakeServer.create();
server.respondImmediately = true;
// Define default response for unhandled requests.
// We make requests to APIs which don't impact the component under test, e.g. UI metric telemetry,
// and we can mock them all with a 200 instead of mocking each one individually.
server.respondWith([200, {}, 'DefaultMockedResponse']);
const httpRequestsMockHelpers = registerHttpRequestMockHelpers(server);
const setServerAsync = (isAsync: boolean, timeout: number = 200) => {
if (isAsync) {
server.autoRespond = true;
server.autoRespondAfter = 1000;
server.respondImmediately = false;
} else {
server.respondImmediately = true;
}
};
const httpSetup = httpServiceMock.createSetupContract();
const httpRequestsMockHelpers = registerHttpRequestMockHelpers(httpSetup, getDelayResponse);
return {
setDelayResponse,
httpSetup,
server,
setServerAsync,
httpRequestsMockHelpers,
};
};

View file

@ -6,8 +6,11 @@
*/
import React from 'react';
import axios from 'axios';
import SemVer from 'semver/classes/semver';
import { merge } from 'lodash';
// @ts-ignore
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import { HttpSetup } from 'src/core/public';
import { MAJOR_VERSION } from '../../../common/constants';
@ -23,6 +26,8 @@ import { init as initHttpRequests } from './http_requests';
const { GlobalFlyoutProvider } = GlobalFlyout;
const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });
export const kibanaVersion = new SemVer(MAJOR_VERSION);
const createAuthorizationContextValue = (privileges: Privileges) => {
@ -33,9 +38,9 @@ const createAuthorizationContextValue = (privileges: Privileges) => {
};
export const WithAppDependencies =
(Comp: any, httpSetup: HttpSetup, { privileges, ...overrides }: Record<string, unknown> = {}) =>
(Comp: any, { privileges, ...overrides }: Record<string, unknown> = {}) =>
(props: Record<string, unknown>) => {
apiService.setup(httpSetup);
apiService.setup(mockHttpClient as unknown as HttpSetup);
breadcrumbService.setup(() => '');
const appContextMock = getAppContextMock(kibanaVersion) as unknown as AppDependencies;
@ -54,5 +59,11 @@ export const WithAppDependencies =
};
export const setupEnvironment = () => {
return initHttpRequests();
const { server, setServerAsync, httpRequestsMockHelpers } = initHttpRequests();
return {
server,
setServerAsync,
httpRequestsMockHelpers,
};
};

View file

@ -14,15 +14,21 @@ import { KibanaTestBed, setupKibanaPage } from '../kibana_deprecations.helpers';
describe('Kibana deprecations - Deprecation details flyout', () => {
let testBed: KibanaTestBed;
const { server } = setupEnvironment();
const {
defaultMockedResponses: { mockedKibanaDeprecations },
} = kibanaDeprecationsServiceHelpers;
const deprecationService = deprecationsServiceMock.createStartContract();
afterAll(() => {
server.restore();
});
beforeEach(async () => {
await act(async () => {
kibanaDeprecationsServiceHelpers.setLoadDeprecations({ deprecationService });
testBed = await setupKibanaPage(setupEnvironment().httpSetup, {
testBed = await setupKibanaPage({
services: {
core: {
deprecations: deprecationService,

View file

@ -17,6 +17,7 @@ describe('Kibana deprecations - Deprecations table', () => {
let testBed: KibanaTestBed;
let deprecationService: jest.Mocked<DeprecationsServiceStart>;
const { server } = setupEnvironment();
const {
mockedKibanaDeprecations,
mockedCriticalKibanaDeprecations,
@ -24,16 +25,17 @@ describe('Kibana deprecations - Deprecations table', () => {
mockedConfigKibanaDeprecations,
} = kibanaDeprecationsServiceHelpers.defaultMockedResponses;
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
afterAll(() => {
server.restore();
});
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpSetup = mockEnvironment.httpSetup;
deprecationService = deprecationsServiceMock.createStartContract();
await act(async () => {
kibanaDeprecationsServiceHelpers.setLoadDeprecations({ deprecationService });
testBed = await setupKibanaPage(httpSetup, {
testBed = await setupKibanaPage({
services: {
core: {
deprecations: deprecationService,
@ -106,7 +108,7 @@ describe('Kibana deprecations - Deprecations table', () => {
describe('No deprecations', () => {
beforeEach(async () => {
await act(async () => {
testBed = await setupKibanaPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupKibanaPage({ isReadOnlyMode: false });
});
const { component } = testBed;

View file

@ -14,12 +14,11 @@ import { KibanaTestBed, setupKibanaPage } from '../kibana_deprecations.helpers';
describe('Kibana deprecations - Deprecations table - Error handling', () => {
let testBed: KibanaTestBed;
const { server } = setupEnvironment();
const deprecationService = deprecationsServiceMock.createStartContract();
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpSetup = mockEnvironment.httpSetup;
afterAll(() => {
server.restore();
});
test('handles plugin errors', async () => {
@ -58,7 +57,7 @@ describe('Kibana deprecations - Deprecations table - Error handling', () => {
],
});
testBed = await setupKibanaPage(httpSetup, {
testBed = await setupKibanaPage({
services: {
core: {
deprecations: deprecationService,
@ -84,7 +83,7 @@ describe('Kibana deprecations - Deprecations table - Error handling', () => {
mockRequestErrorMessage: 'Internal Server Error',
});
testBed = await setupKibanaPage(httpSetup, {
testBed = await setupKibanaPage({
services: {
core: {
deprecations: deprecationService,

View file

@ -11,7 +11,6 @@ import {
AsyncTestBedConfig,
findTestSubject,
} from '@kbn/test-jest-helpers';
import { HttpSetup } from 'src/core/public';
import { KibanaDeprecations } from '../../../public/application/components';
import { WithAppDependencies } from '../helpers';
@ -119,11 +118,10 @@ const createActions = (testBed: TestBed) => {
};
export const setupKibanaPage = async (
httpSetup: HttpSetup,
overrides?: Record<string, unknown>
): Promise<KibanaTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(KibanaDeprecations, httpSetup, overrides),
WithAppDependencies(KibanaDeprecations, overrides),
testBedConfig
);
const testBed = await initTestBed();

View file

@ -14,19 +14,21 @@ import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
describe('Overview - Backup Step', () => {
let testBed: OverviewTestBed;
let server: ReturnType<typeof setupEnvironment>['server'];
let setServerAsync: ReturnType<typeof setupEnvironment>['setServerAsync'];
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
let setDelayResponse: ReturnType<typeof setupEnvironment>['setDelayResponse'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
setDelayResponse = mockEnvironment.setDelayResponse;
beforeEach(() => {
({ server, setServerAsync, httpRequestsMockHelpers } = setupEnvironment());
});
afterEach(() => {
server.restore();
});
describe('On-prem', () => {
beforeEach(async () => {
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
test('Shows link to Snapshot and Restore', () => {
@ -43,7 +45,7 @@ describe('Overview - Backup Step', () => {
describe('On Cloud', () => {
const setupCloudOverviewPage = async () =>
setupOverviewPage(httpSetup, {
setupOverviewPage({
plugins: {
cloud: {
isCloudEnabled: true,
@ -55,10 +57,14 @@ describe('Overview - Backup Step', () => {
describe('initial loading state', () => {
beforeEach(async () => {
// We don't want the request to load backup status to resolve immediately.
setDelayResponse(true);
setServerAsync(true);
testBed = await setupCloudOverviewPage();
});
afterEach(() => {
setServerAsync(false);
});
test('is rendered', () => {
const { exists } = testBed;
expect(exists('cloudBackupLoading')).toBe(true);

View file

@ -19,12 +19,10 @@ import {
describe('Overview - Fix deprecation issues step - Elasticsearch deprecations', () => {
let testBed: OverviewTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
afterAll(() => {
server.restore();
});
describe('When load succeeds', () => {
@ -34,7 +32,7 @@ describe('Overview - Fix deprecation issues step - Elasticsearch deprecations',
const deprecationService = deprecationsServiceMock.createStartContract();
kibanaDeprecationsServiceHelpers.setLoadDeprecations({ deprecationService, response: [] });
testBed = await setupOverviewPage(httpSetup, {
testBed = await setupOverviewPage({
services: {
core: {
deprecations: deprecationService,
@ -118,7 +116,7 @@ describe('Overview - Fix deprecation issues step - Elasticsearch deprecations',
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
const { component, find } = testBed;
@ -138,7 +136,7 @@ describe('Overview - Fix deprecation issues step - Elasticsearch deprecations',
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
const { component, find } = testBed;
@ -161,7 +159,7 @@ describe('Overview - Fix deprecation issues step - Elasticsearch deprecations',
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupOverviewPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupOverviewPage({ isReadOnlyMode: false });
});
const { component, find } = testBed;
@ -184,7 +182,7 @@ describe('Overview - Fix deprecation issues step - Elasticsearch deprecations',
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);
await act(async () => {
testBed = await setupOverviewPage(httpSetup, { isReadOnlyMode: false });
testBed = await setupOverviewPage({ isReadOnlyMode: false });
});
const { component, find } = testBed;

View file

@ -15,12 +15,10 @@ import { esCriticalAndWarningDeprecations, esNoDeprecations } from './mock_es_is
describe('Overview - Fix deprecation issues step', () => {
let testBed: OverviewTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
afterAll(() => {
server.restore();
});
describe('when there are critical issues in one panel', () => {
@ -31,7 +29,7 @@ describe('Overview - Fix deprecation issues step', () => {
const deprecationService = deprecationsServiceMock.createStartContract();
kibanaDeprecationsServiceHelpers.setLoadDeprecations({ deprecationService, response: [] });
testBed = await setupOverviewPage(httpSetup, {
testBed = await setupOverviewPage({
services: {
core: {
deprecations: deprecationService,
@ -57,7 +55,7 @@ describe('Overview - Fix deprecation issues step', () => {
const deprecationService = deprecationsServiceMock.createStartContract();
kibanaDeprecationsServiceHelpers.setLoadDeprecations({ deprecationService, response: [] });
testBed = await setupOverviewPage(httpSetup, {
testBed = await setupOverviewPage({
services: {
core: {
deprecations: deprecationService,

View file

@ -16,14 +16,12 @@ import { esNoDeprecations } from './mock_es_issues';
describe('Overview - Fix deprecation issues step - Kibana deprecations', () => {
let testBed: OverviewTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();
const { mockedKibanaDeprecations, mockedCriticalKibanaDeprecations } =
kibanaDeprecationsServiceHelpers.defaultMockedResponses;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
afterAll(() => {
server.restore();
});
describe('When load succeeds', () => {
@ -35,7 +33,7 @@ describe('Overview - Fix deprecation issues step - Kibana deprecations', () => {
const deprecationService = deprecationsServiceMock.createStartContract();
kibanaDeprecationsServiceHelpers.setLoadDeprecations({ deprecationService, response });
testBed = await setupOverviewPage(httpSetup, {
testBed = await setupOverviewPage({
services: {
core: {
deprecations: deprecationService,
@ -116,7 +114,7 @@ describe('Overview - Fix deprecation issues step - Kibana deprecations', () => {
mockRequestErrorMessage: 'Internal Server Error',
});
testBed = await setupOverviewPage(httpSetup, {
testBed = await setupOverviewPage({
services: {
core: {
deprecations: deprecationService,

View file

@ -13,22 +13,22 @@ import { systemIndicesMigrationStatus } from './mocks';
describe('Overview - Migrate system indices - Flyout', () => {
let testBed: OverviewTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
beforeEach(async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus(systemIndicesMigrationStatus);
await act(async () => {
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
testBed.component.update();
});
afterAll(() => {
server.restore();
});
test('shows correct features in flyout table', async () => {
const { actions, table } = testBed;

View file

@ -12,17 +12,17 @@ import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
describe('Overview - Migrate system indices', () => {
let testBed: OverviewTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
testBed = await setupOverviewPage(httpSetup);
beforeEach(async () => {
testBed = await setupOverviewPage();
testBed.component.update();
});
afterAll(() => {
server.restore();
});
describe('Error state', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus(undefined, {
@ -30,7 +30,7 @@ describe('Overview - Migrate system indices', () => {
message: 'error',
});
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
test('Is rendered', () => {
@ -59,7 +59,7 @@ describe('Overview - Migrate system indices', () => {
migration_status: 'NO_MIGRATION_NEEDED',
});
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
const { exists, component } = testBed;
@ -75,7 +75,7 @@ describe('Overview - Migrate system indices', () => {
migration_status: 'IN_PROGRESS',
});
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
const { exists, component, find } = testBed;
@ -94,7 +94,7 @@ describe('Overview - Migrate system indices', () => {
migration_status: 'MIGRATION_NEEDED',
});
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
const { exists, component, find } = testBed;
@ -116,7 +116,7 @@ describe('Overview - Migrate system indices', () => {
message: 'error',
});
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
const { exists, component, find } = testBed;
@ -154,7 +154,7 @@ describe('Overview - Migrate system indices', () => {
],
});
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
const { exists } = testBed;

View file

@ -13,12 +13,10 @@ import { SYSTEM_INDICES_MIGRATION_POLL_INTERVAL_MS } from '../../../../common/co
describe('Overview - Migrate system indices - Step completion', () => {
let testBed: OverviewTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
const { server, httpRequestsMockHelpers } = setupEnvironment();
afterAll(() => {
server.restore();
});
test(`It's complete when no upgrade is needed`, async () => {
@ -27,7 +25,7 @@ describe('Overview - Migrate system indices - Step completion', () => {
});
await act(async () => {
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
const { exists, component } = testBed;
@ -43,7 +41,7 @@ describe('Overview - Migrate system indices - Step completion', () => {
});
await act(async () => {
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
const { exists, component } = testBed;
@ -62,7 +60,7 @@ describe('Overview - Migrate system indices - Step completion', () => {
migration_status: 'IN_PROGRESS',
});
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
});
afterEach(() => {

View file

@ -7,8 +7,7 @@
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers';
import { HttpSetup } from 'src/core/public';
import { Overview } from '../../../public/application/components';
import { Overview } from '../../../public/application/components/overview';
import { WithAppDependencies } from '../helpers';
const testBedConfig: AsyncTestBedConfig = {
@ -55,13 +54,9 @@ const createActions = (testBed: TestBed) => {
};
export const setupOverviewPage = async (
httpSetup: HttpSetup,
overrides?: Record<string, unknown>
): Promise<OverviewTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(Overview, httpSetup, overrides),
testBedConfig
);
const initTestBed = registerTestBed(WithAppDependencies(Overview, overrides), testBedConfig);
const testBed = await initTestBed();
return {

View file

@ -10,11 +10,17 @@ import { OverviewTestBed, setupOverviewPage } from './overview.helpers';
describe('Overview Page', () => {
let testBed: OverviewTestBed;
const { server } = setupEnvironment();
beforeEach(async () => {
testBed = await setupOverviewPage(setupEnvironment().httpSetup);
testBed = await setupOverviewPage();
testBed.component.update();
});
afterAll(() => {
server.restore();
});
describe('Documentation links', () => {
test('Has a whatsNew link and it references target version', () => {
const { exists, find } = testBed;

View file

@ -9,33 +9,28 @@ import { setupEnvironment } from '../../helpers';
import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
const DEPLOYMENT_URL = 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63';
const setupCloudOverviewPage = () => {
return setupOverviewPage({
plugins: {
cloud: {
isCloudEnabled: true,
deploymentUrl: DEPLOYMENT_URL,
},
},
});
};
describe('Overview - Upgrade Step', () => {
let testBed: OverviewTestBed;
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
let setDelayResponse: ReturnType<typeof setupEnvironment>['setDelayResponse'];
const setupCloudOverviewPage = () => {
return setupOverviewPage(httpSetup, {
plugins: {
cloud: {
isCloudEnabled: true,
deploymentUrl: DEPLOYMENT_URL,
},
},
});
};
const { server, httpRequestsMockHelpers, setServerAsync } = setupEnvironment();
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
setDelayResponse = mockEnvironment.setDelayResponse;
afterAll(() => {
server.restore();
});
describe('On-prem', () => {
test('Shows link to setup upgrade docs', async () => {
testBed = await setupOverviewPage(httpSetup);
testBed = await setupOverviewPage();
const { exists } = testBed;
expect(exists('upgradeSetupDocsLink')).toBe(true);
@ -80,10 +75,10 @@ describe('Overview - Upgrade Step', () => {
});
test('An error callout is displayed, if status check failed', async () => {
httpRequestsMockHelpers.setGetUpgradeStatusResponse(undefined, {
statusCode: 500,
message: 'Status check failed',
});
httpRequestsMockHelpers.setGetUpgradeStatusResponse(
{},
{ statusCode: 500, message: 'Status check failed' }
);
testBed = await setupCloudOverviewPage();
const { exists, component } = testBed;
@ -95,7 +90,7 @@ describe('Overview - Upgrade Step', () => {
});
test('The CTA button displays loading indicator', async () => {
setDelayResponse(true);
setServerAsync(true);
testBed = await setupCloudOverviewPage();
const { exists, find } = testBed;