Skip to content

Commit

Permalink
Create common deprecation issues panel component in UA (elastic#111231)
Browse files Browse the repository at this point in the history
* Refine success state behavior and add tests.
* Refactor components into a components directory.
* Refactor SCSS to colocate styles with their components.
* Refactor tests to reduce boilerplate and clarify conditions under test.
  • Loading branch information
cjcenizal authored and sabarasaba committed Oct 26, 2021
1 parent f9c9c1e commit d6ac3f0
Show file tree
Hide file tree
Showing 23 changed files with 706 additions and 559 deletions.
7 changes: 0 additions & 7 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -25220,17 +25220,10 @@
"xpack.upgradeAssistant.esDeprecations.mlSnapshots.flyout.upgradeSnapshotErrorTitle": "スナップショットのアップグレードエラー",
"xpack.upgradeAssistant.esDeprecations.pageDescription": "廃止予定のクラスターとインデックス設定をレビューします。アップグレード前に重要な問題を解決する必要があります。",
"xpack.upgradeAssistant.esDeprecations.pageTitle": "Elasticsearch",
"xpack.upgradeAssistant.esDeprecationStats.criticalDeprecationsTitle": "重大",
"xpack.upgradeAssistant.esDeprecationStats.statsTitle": "Elasticsearch",
"xpack.upgradeAssistant.kibanaDeprecations.deprecationLabel": "Kibana",
"xpack.upgradeAssistant.kibanaDeprecations.docLinkText": "ドキュメント",
"xpack.upgradeAssistant.kibanaDeprecations.loadingText": "廃止予定を読み込んでいます...",
"xpack.upgradeAssistant.kibanaDeprecations.pageTitle": "Kibana",
"xpack.upgradeAssistant.kibanaDeprecationStats.criticalDeprecationsLabel": "Kibanaには{criticalDeprecations}個の重大な廃止予定があります",
"xpack.upgradeAssistant.kibanaDeprecationStats.criticalDeprecationsTitle": "重大",
"xpack.upgradeAssistant.kibanaDeprecationStats.loadingErrorMessage": "Kibana廃止予定の取得中にエラーが発生しました。",
"xpack.upgradeAssistant.kibanaDeprecationStats.statsTitle": "Kibana",
"xpack.upgradeAssistant.kibanaDeprecationStats.warningDeprecationsTitle": "警告",
"xpack.upgradeAssistant.noDeprecationsPrompt.nextStepsDescription": "他のスタック廃止予定については、{overviewButton}を確認してください。",
"xpack.upgradeAssistant.noDeprecationsPrompt.overviewLinkText": "概要ページ",
"xpack.upgradeAssistant.overview.analyzeTitle": "廃止予定ログを分析",
Expand Down
6 changes: 0 additions & 6 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -25649,16 +25649,10 @@
"xpack.upgradeAssistant.esDeprecations.mlSnapshots.flyout.upgradeSnapshotErrorTitle": "升级快照时出错",
"xpack.upgradeAssistant.esDeprecations.pageDescription": "查看已弃用的群集和索引设置。在升级之前必须解决任何紧急问题。",
"xpack.upgradeAssistant.esDeprecations.pageTitle": "Elasticsearch",
"xpack.upgradeAssistant.esDeprecationStats.criticalDeprecationsTitle": "紧急",
"xpack.upgradeAssistant.esDeprecationStats.statsTitle": "Elasticsearch",
"xpack.upgradeAssistant.kibanaDeprecations.deprecationLabel": "Kibana",
"xpack.upgradeAssistant.kibanaDeprecations.docLinkText": "文档",
"xpack.upgradeAssistant.kibanaDeprecations.loadingText": "正在加载弃用……",
"xpack.upgradeAssistant.kibanaDeprecations.pageTitle": "Kibana",
"xpack.upgradeAssistant.kibanaDeprecationStats.criticalDeprecationsTitle": "紧急",
"xpack.upgradeAssistant.kibanaDeprecationStats.loadingErrorMessage": "检索 Kibana 弃用时发生错误。",
"xpack.upgradeAssistant.kibanaDeprecationStats.statsTitle": "Kibana",
"xpack.upgradeAssistant.kibanaDeprecationStats.warningDeprecationsTitle": "警告",
"xpack.upgradeAssistant.noDeprecationsPrompt.nextStepsDescription": "查看{overviewButton}以了解其他 Stack 弃用。",
"xpack.upgradeAssistant.noDeprecationsPrompt.overviewLinkText": "“概览”页面",
"xpack.upgradeAssistant.overview.analyzeTitle": "分析弃用日志",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { DeprecationsServiceStart, DomainDeprecationDetails } from 'kibana/public';

const kibanaDeprecations: DomainDeprecationDetails[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* 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 { deprecationsServiceMock } from 'src/core/public/mocks';

import { setupEnvironment, kibanaDeprecationsServiceHelpers } from '../../helpers';
import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
import {
esCriticalAndWarningDeprecations,
esCriticalOnlyDeprecations,
esNoDeprecations,
} from './mock_es_issues';

describe('Overview - Fix deprecation issues step - Elasticsearch deprecations', () => {
let testBed: OverviewTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();

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

describe('When load succeeds', () => {
const setup = async () => {
// Set up with no Kibana deprecations.
await act(async () => {
const deprecationService = deprecationsServiceMock.createStartContract();
kibanaDeprecationsServiceHelpers.setLoadDeprecations({ deprecationService, response: [] });

testBed = await setupOverviewPage({
services: {
core: {
deprecations: deprecationService,
},
},
});
});

const { component } = testBed;
component.update();
};

describe('when there are critical and warning issues', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esCriticalAndWarningDeprecations);
await setup();
});

test('renders counts for both', () => {
const { exists, find } = testBed;
expect(exists('esStatsPanel')).toBe(true);
expect(find('esStatsPanel.warningDeprecations').text()).toContain('1');
expect(find('esStatsPanel.criticalDeprecations').text()).toContain('1');
});

test('panel links to ES deprecations page', () => {
const { component, find } = testBed;
component.update();
expect(find('esStatsPanel').find('a').props().href).toBe('/es_deprecations');
});
});

describe('when there are critical but no warning issues', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esCriticalOnlyDeprecations);
await setup();
});

test('renders a count for critical issues and success state for warning issues', () => {
const { exists, find } = testBed;
expect(exists('esStatsPanel')).toBe(true);
expect(find('esStatsPanel.criticalDeprecations').text()).toContain('1');
expect(exists('esStatsPanel.noWarningDeprecationIssues')).toBe(true);
});

test('panel links to ES deprecations page', () => {
const { component, find } = testBed;
component.update();
expect(find('esStatsPanel').find('a').props().href).toBe('/es_deprecations');
});
});

describe('when there no critical or warning issues', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadEsDeprecationsResponse(esNoDeprecations);
await setup();
});

test('renders a count for critical issues and success state for warning issues', () => {
const { exists } = testBed;
expect(exists('esStatsPanel')).toBe(true);
expect(exists('esStatsPanel.noDeprecationIssues')).toBe(true);
});

test(`panel doesn't link to ES deprecations page`, () => {
const { component, find } = testBed;
component.update();
expect(find('esStatsPanel').find('a').length).toBe(0);
});
});
});

describe(`When there's a load error`, () => {
test('handles network failure', async () => {
const error = {
statusCode: 500,
error: 'Internal server error',
message: 'Internal server error',
};

httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);

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

const { component, exists } = testBed;
component.update();
expect(exists('esRequestErrorIconTip')).toBe(true);
});

test('handles unauthorized error', async () => {
const error = {
statusCode: 403,
error: 'Forbidden',
message: 'Forbidden',
};

httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);

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

const { component, exists } = testBed;
component.update();
expect(exists('unauthorizedErrorIconTip')).toBe(true);
});

test('handles partially upgraded error', async () => {
const error = {
statusCode: 426,
error: 'Upgrade required',
message: 'There are some nodes running a different version of Elasticsearch',
attributes: {
allNodesUpgraded: false,
},
};

httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);

await act(async () => {
testBed = await setupOverviewPage({ isReadOnlyMode: false });
});

const { component, exists } = testBed;
component.update();
expect(exists('partiallyUpgradedErrorIconTip')).toBe(true);
});

test('handles upgrade error', async () => {
const error = {
statusCode: 426,
error: 'Upgrade required',
message: 'There are some nodes running a different version of Elasticsearch',
attributes: {
allNodesUpgraded: true,
},
};

httpRequestsMockHelpers.setLoadEsDeprecationsResponse(undefined, error);

await act(async () => {
testBed = await setupOverviewPage({ isReadOnlyMode: false });
});

const { component, exists } = testBed;
component.update();
expect(exists('upgradedErrorIconTip')).toBe(true);
});
});
});
Loading

0 comments on commit d6ac3f0

Please sign in to comment.