Skip to content

Commit

Permalink
Get rid of axios dependency in the Upgrade Assistant tests. (elasti…
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin authored and maksimkovalev committed Mar 18, 2022
1 parent 61806b1 commit 42148bd
Show file tree
Hide file tree
Showing 28 changed files with 409 additions and 477 deletions.
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-helpers';

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-helpers';
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,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

0 comments on commit 42148bd

Please sign in to comment.