Skip to content

Commit

Permalink
Add tests for interstitial states.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Oct 4, 2021
1 parent 0c9b2c7 commit 7f0fa9c
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 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, TestBedConfig } from '@kbn/test/jest';

import { AppWithRouter } from '../../../public/application/app';
import { WithAppDependencies } from '../helpers';

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [`/overview`],
componentRoutePath: '/overview',
},
doMountAsync: true,
};

export type AppTestBed = TestBed & {
actions: ReturnType<typeof createActions>;
};

const createActions = (testBed: TestBed) => {
const clickDeprecationToggle = async () => {
const { find, component } = testBed;

await act(async () => {
find('deprecationLoggingToggle').simulate('click');
});

component.update();
};

return {
clickDeprecationToggle,
};
};

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

return {
...testBed,
actions: createActions(testBed),
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 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 { setupEnvironment } from '../helpers';
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();
});

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

test('renders overview', () => {
const { exists, find } = testBed;
expect(exists('overview')).toBe(true);
expect(exists('isUpgradingMessage')).toBe(false);
expect(exists('isUpgradeCompleteMessage')).toBe(false);
});
});

describe('when cluster is in the process of a rolling upgrade', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(null, {
statusCode: 426,
attributes: {
allNodesUpgraded: false,
},
});

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

test('renders rolling upgrade message', async () => {
const { component, exists } = testBed;
component.update();
expect(exists('overview')).toBe(false);
expect(exists('isUpgradingMessage')).toBe(true);
expect(exists('isUpgradeCompleteMessage')).toBe(false);
});
});

describe('when cluster has been upgraded', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(null, {
statusCode: 426,
attributes: {
allNodesUpgraded: true,
},
});

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

test('renders upgrade complete message', () => {
const { component, exists } = testBed;
component.update();
expect(exists('overview')).toBe(false);
expect(exists('isUpgradingMessage')).toBe(false);
expect(exists('isUpgradeCompleteMessage')).toBe(true);
});
});
});
2 changes: 2 additions & 0 deletions x-pack/plugins/upgrade_assistant/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const App: React.FunctionComponent = () => {
paddingSize="none"
verticalPosition="center"
horizontalPosition="center"
data-test-subj="isUpgradingMessage"
>
<EuiEmptyPrompt
iconType="logoElasticsearch"
Expand Down Expand Up @@ -100,6 +101,7 @@ const App: React.FunctionComponent = () => {
paddingSize="none"
verticalPosition="center"
horizontalPosition="center"
data-test-subj="isUpgradeCompleteMessage"
>
<EuiEmptyPrompt
iconType="logoElasticsearch"
Expand Down

0 comments on commit 7f0fa9c

Please sign in to comment.