Skip to content
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

[7.17] Get rid of axios dependency in the Upgrade Assistant tests. (#127122) #127716

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test/jest';

import { HttpSetup } from 'src/core/public';
import { App } from '../../../public/application/app';
import { WithAppDependencies } from '../helpers';

Expand Down Expand Up @@ -39,8 +40,14 @@ const createActions = (testBed: TestBed) => {
};
};

export const setupAppPage = async (overrides?: Record<string, unknown>): Promise<AppTestBed> => {
const initTestBed = registerTestBed(WithAppDependencies(App, overrides), testBedConfig);
export const setupAppPage = async (
httpSetup: HttpSetup,
overrides?: Record<string, unknown>
): Promise<AppTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(App, httpSetup, overrides),
testBedConfig
);
const testBed = await initTestBed();

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ import { AppTestBed, setupAppPage } from './app.helpers';

describe('Cluster upgrade', () => {
let testBed: AppTestBed;
let server: ReturnType<typeof setupEnvironment>['server'];
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];

beforeEach(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});

afterEach(() => {
server.restore();
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;
});

describe('when user is still preparing for upgrade', () => {
beforeEach(async () => {
testBed = await setupAppPage();
testBed = await setupAppPage(httpSetup);
});

test('renders overview', () => {
Expand All @@ -52,7 +49,7 @@ describe('Cluster upgrade', () => {
});

await act(async () => {
testBed = await setupAppPage();
testBed = await setupAppPage(httpSetup);
});
});

Expand All @@ -76,7 +73,7 @@ describe('Cluster upgrade', () => {
});

await act(async () => {
testBed = await setupAppPage();
testBed = await setupAppPage(httpSetup);
});
});

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

import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test/jest';
import { EsDeprecationLogs } from '../../../public/application/components/es_deprecation_logs';
import { HttpSetup } from 'src/core/public';
import { EsDeprecationLogs } from '../../../public/application/components';
import { WithAppDependencies } from '../helpers';

const testBedConfig: AsyncTestBedConfig = {
Expand Down Expand Up @@ -65,10 +66,11 @@ const createActions = (testBed: TestBed) => {
};

export const setupESDeprecationLogsPage = async (
httpSetup: HttpSetup,
overrides?: Record<string, unknown>
): Promise<EsDeprecationLogsTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(EsDeprecationLogs, overrides),
WithAppDependencies(EsDeprecationLogs, httpSetup, overrides),
testBedConfig
);
const testBed = await initTestBed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ const getLoggingResponse = (toggle: boolean): DeprecationLoggingStatus => ({

describe('ES deprecation logs', () => {
let testBed: EsDeprecationLogsTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();

let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];
let httpSetup: ReturnType<typeof setupEnvironment>['httpSetup'];
beforeEach(async () => {
const mockEnvironment = setupEnvironment();
httpRequestsMockHelpers = mockEnvironment.httpRequestsMockHelpers;
httpSetup = mockEnvironment.httpSetup;

httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(getLoggingResponse(true));
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
testBed.component.update();
});

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

describe('Documentation link', () => {
test('Has a link for migration info api docs in page header', () => {
const { exists } = testBed;
Expand All @@ -71,8 +71,11 @@ describe('ES deprecation logs', () => {

await actions.clickDeprecationToggle();

const latestRequest = server.requests[server.requests.length - 1];
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual({ isEnabled: false });
expect(httpSetup.put).toHaveBeenLastCalledWith(
`/api/upgrade_assistant/deprecation_logging`,
expect.objectContaining({ body: JSON.stringify({ isEnabled: false }) })
);

expect(find('deprecationLoggingToggle').props()['aria-checked']).toBe(false);
});

Expand All @@ -83,7 +86,7 @@ describe('ES deprecation logs', () => {
});

await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { exists, component } = testBed;
Expand Down Expand Up @@ -119,7 +122,7 @@ describe('ES deprecation logs', () => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(undefined, error);

await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { component, exists } = testBed;
Expand All @@ -136,7 +139,7 @@ describe('ES deprecation logs', () => {
});

await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { exists, component } = testBed;
Expand All @@ -156,7 +159,7 @@ describe('ES deprecation logs', () => {

test('Has a link to see logs in observability app', async () => {
await act(async () => {
testBed = await setupESDeprecationLogsPage({
testBed = await setupESDeprecationLogsPage(httpSetup, {
http: {
basePath: {
prepend: (url: string) => url,
Expand Down Expand Up @@ -194,7 +197,7 @@ describe('ES deprecation logs', () => {

test('Has a link to see logs in discover app', async () => {
await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { exists, component, find } = testBed;
Expand Down Expand Up @@ -233,7 +236,7 @@ describe('ES deprecation logs', () => {
});

await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { find, exists, component } = testBed;
Expand All @@ -250,7 +253,7 @@ describe('ES deprecation logs', () => {
});

await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { find, exists, component } = testBed;
Expand All @@ -271,7 +274,7 @@ describe('ES deprecation logs', () => {
httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse(undefined, error);

await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { exists, actions, component } = testBed;
Expand All @@ -295,7 +298,7 @@ describe('ES deprecation logs', () => {
});

await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { exists, actions, component } = testBed;
Expand Down Expand Up @@ -327,7 +330,7 @@ describe('ES deprecation logs', () => {

const addDanger = jest.fn();
await act(async () => {
testBed = await setupESDeprecationLogsPage({
testBed = await setupESDeprecationLogsPage(httpSetup, {
services: {
core: {
notifications: {
Expand Down Expand Up @@ -365,7 +368,7 @@ describe('ES deprecation logs', () => {
count: 0,
});

testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

afterEach(() => {
Expand Down Expand Up @@ -401,7 +404,7 @@ describe('ES deprecation logs', () => {

test('It shows copy with compatibility api header advice', async () => {
await act(async () => {
testBed = await setupESDeprecationLogsPage();
testBed = await setupESDeprecationLogsPage(httpSetup);
});

const { exists, component } = testBed;
Expand All @@ -425,7 +428,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({
testBed = await setupESDeprecationLogsPage(httpSetup, {
privileges: {
hasAllPrivileges: false,
missingPrivileges: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import { esDeprecationsMockResponse } from './mocked_responses';

describe('Cluster settings deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();
const clusterSettingDeprecation = esDeprecationsMockResponse.deprecations[4];

afterAll(() => {
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.setReindexStatusResponse({
httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', {
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
Expand All @@ -34,7 +34,7 @@ describe('Cluster settings deprecation flyout', () => {
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
testBed = await setupElasticsearchPage(httpSetup, { isReadOnlyMode: false });
});

const { actions, component } = testBed;
Expand Down Expand Up @@ -68,11 +68,10 @@ describe('Cluster settings deprecation flyout', () => {

await actions.clusterSettingsDeprecationFlyout.clickDeleteSettingsButton();

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

expect(request.method).toBe('POST');
expect(request.url).toBe(`/api/upgrade_assistant/cluster_settings`);
expect(request.status).toEqual(200);
expect(httpSetup.post).toHaveBeenLastCalledWith(
'/api/upgrade_assistant/cluster_settings',
expect.anything()
);

// Verify the "Resolution" column of the table is updated
expect(find('clusterSettingsResolutionStatusCell').at(0).text()).toEqual(
Expand Down Expand Up @@ -102,11 +101,10 @@ describe('Cluster settings deprecation flyout', () => {

await actions.clusterSettingsDeprecationFlyout.clickDeleteSettingsButton();

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

expect(request.method).toBe('POST');
expect(request.url).toBe(`/api/upgrade_assistant/cluster_settings`);
expect(request.status).toEqual(500);
expect(httpSetup.post).toHaveBeenLastCalledWith(
'/api/upgrade_assistant/cluster_settings',
expect.anything()
);

// Verify the "Resolution" column of the table is updated
expect(find('clusterSettingsResolutionStatusCell').at(0).text()).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './moc

describe('Default deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();

afterAll(() => {
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',
snapshotId: MOCK_SNAPSHOT_ID,
jobId: MOCK_JOB_ID,
status: 'idle',
});
httpRequestsMockHelpers.setReindexStatusResponse({
httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', {
reindexOp: null,
warnings: [],
hasRequiredPrivileges: true,
Expand All @@ -39,7 +39,9 @@ describe('Default deprecation flyout', () => {
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
testBed = await setupElasticsearchPage(httpSetup, {
isReadOnlyMode: false,
});
});

testBed.component.update();
Expand Down
Loading