From 67f3cdefd3f7c4704a8635600cb1b2550b058ebb Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Thu, 19 Aug 2021 19:03:17 -0700 Subject: [PATCH 01/12] Add backup step with static content. --- .../overview/backup_step/backup_step.tsx | 50 +++++++++++++++++++ .../components/overview/backup_step/index.ts | 8 +++ .../components/overview/overview.tsx | 2 + .../overview/upgrade_step/upgrade_step.tsx | 2 +- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx create mode 100644 x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/index.ts diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx new file mode 100644 index 0000000000000..f8a8c0be24e05 --- /dev/null +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx @@ -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 React from 'react'; + +import { EuiText } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import type { EuiStepProps } from '@elastic/eui/src/components/steps/step'; + +interface Props { + nextMajor: number; +} + +const i18nTexts = { + backupStepTitle: i18n.translate('xpack.upgradeAssistant.overview.backupStepTitle', { + defaultMessage: 'Back up your data', + }), + + backupStepDescription: (nextMajor: number) => + i18n.translate('xpack.upgradeAssistant.overview.backupStepDescription', { + defaultMessage: 'Back up your data before addressing any deprecation issues.', + values: { nextMajor }, + }), +}; + +const BackupStep: React.FunctionComponent = ({ nextMajor }) => { + return ( + <> + +

{i18nTexts.backupStepDescription(nextMajor)}

+
+ + ); +}; + +interface GetStepConfig { + nextMajor: number; +} + +export const getBackupStep = ({ nextMajor }: GetStepConfig): EuiStepProps => { + return { + title: i18nTexts.backupStepTitle, + status: 'incomplete', + children: , + }; +}; diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/index.ts b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/index.ts new file mode 100644 index 0000000000000..8daac9645fa12 --- /dev/null +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export { getBackupStep } from './backup_step'; diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx index f900416873b83..8b2c1fc56c776 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx @@ -21,6 +21,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { useAppContext } from '../../app_context'; +import { getBackupStep } from './backup_step'; import { getReviewLogsStep } from './review_logs_step'; import { getFixDeprecationLogsStep } from './fix_deprecation_logs_step'; import { getUpgradeStep } from './upgrade_step'; @@ -83,6 +84,7 @@ export const Overview: FunctionComponent = () => { Date: Fri, 20 Aug 2021 12:40:06 -0700 Subject: [PATCH 02/12] Add link to Snapshot and Restore from "Back up data" step. * Add snapshot_restore locator. --- x-pack/plugins/snapshot_restore/kibana.json | 2 +- .../snapshot_restore/public/locator.ts | 45 +++++++++++++++++++ .../plugins/snapshot_restore/public/plugin.ts | 15 +++++-- x-pack/plugins/upgrade_assistant/kibana.json | 2 +- .../public/application/app_context.tsx | 5 ++- .../overview/backup_step/backup_step.tsx | 44 ++++++++++++++++-- ...ection.ts => mount_management_section.tsx} | 22 ++++++++- .../upgrade_assistant/public/plugin.ts | 3 +- .../plugins/upgrade_assistant/public/types.ts | 5 ++- 9 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 x-pack/plugins/snapshot_restore/public/locator.ts rename x-pack/plugins/upgrade_assistant/public/application/{mount_management_section.ts => mount_management_section.tsx} (67%) diff --git a/x-pack/plugins/snapshot_restore/kibana.json b/x-pack/plugins/snapshot_restore/kibana.json index bd2a85126c0c6..66c4023337af1 100644 --- a/x-pack/plugins/snapshot_restore/kibana.json +++ b/x-pack/plugins/snapshot_restore/kibana.json @@ -7,7 +7,7 @@ "name": "Stack Management", "githubTeam": "kibana-stack-management" }, - "requiredPlugins": ["licensing", "management", "features"], + "requiredPlugins": ["licensing", "management", "features", "share"], "optionalPlugins": ["usageCollection", "security", "cloud", "home"], "configPath": ["xpack", "snapshot_restore"], "requiredBundles": ["esUiShared", "kibanaReact", "home"] diff --git a/x-pack/plugins/snapshot_restore/public/locator.ts b/x-pack/plugins/snapshot_restore/public/locator.ts new file mode 100644 index 0000000000000..ba57446a03887 --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/locator.ts @@ -0,0 +1,45 @@ +/* + * 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 type { SerializableRecord } from '@kbn/utility-types'; +import { ManagementAppLocator } from 'src/plugins/management/common'; +import { LocatorDefinition } from '../../../../src/plugins/share/public/'; +import { linkToSnapshots } from './application/services/navigation'; +import { PLUGIN } from '../common/constants'; + +export const SNAPSHOT_RESTORE_LOCATOR_ID = 'SNAPSHOT_RESTORE_LOCATOR'; + +export interface SnapshotRestoreLocatorParams extends SerializableRecord { + page: 'snapshots'; +} + +export interface SnapshotRestoreLocatorDefinitionDependencies { + managementAppLocator: ManagementAppLocator; +} + +export class SnapshotRestoreLocatorDefinition + implements LocatorDefinition { + constructor(protected readonly deps: SnapshotRestoreLocatorDefinitionDependencies) {} + + public readonly id = SNAPSHOT_RESTORE_LOCATOR_ID; + + public readonly getLocation = async (params: SnapshotRestoreLocatorParams) => { + const location = await this.deps.managementAppLocator.getLocation({ + sectionId: 'data', + appId: PLUGIN.id, + }); + + switch (params.page) { + case 'snapshots': { + return { + ...location, + path: location.path + linkToSnapshots(), + }; + } + } + }; +} diff --git a/x-pack/plugins/snapshot_restore/public/plugin.ts b/x-pack/plugins/snapshot_restore/public/plugin.ts index fbd59db531d9e..bb091a1fd1831 100644 --- a/x-pack/plugins/snapshot_restore/public/plugin.ts +++ b/x-pack/plugins/snapshot_restore/public/plugin.ts @@ -7,13 +7,14 @@ import { i18n } from '@kbn/i18n'; import { CoreSetup, PluginInitializerContext } from 'src/core/public'; - -import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public'; -import { ManagementSetup } from '../../../../src/plugins/management/public'; +import { UsageCollectionSetup } from 'src/plugins/usage_collection/public'; +import { ManagementSetup } from 'src/plugins/management/public'; +import { SharePluginSetup } from 'src/plugins/share/public'; import { FeatureCatalogueCategory, HomePublicPluginSetup, } from '../../../../src/plugins/home/public'; + import { PLUGIN } from '../common/constants'; import { ClientConfigType } from './types'; @@ -22,10 +23,12 @@ import { httpService, setUiMetricService } from './application/services/http'; import { textService } from './application/services/text'; import { UiMetricService } from './application/services'; import { UIM_APP_NAME } from './application/constants'; +import { SnapshotRestoreLocatorDefinition } from './locator'; interface PluginsDependencies { usageCollection: UsageCollectionSetup; management: ManagementSetup; + share: SharePluginSetup; home?: HomePublicPluginSetup; } @@ -79,6 +82,12 @@ export class SnapshotRestoreUIPlugin { order: 630, }); } + + plugins.share.url.locators.create( + new SnapshotRestoreLocatorDefinition({ + managementAppLocator: plugins.management.locator, + }) + ); } public start() {} diff --git a/x-pack/plugins/upgrade_assistant/kibana.json b/x-pack/plugins/upgrade_assistant/kibana.json index e66f25318a28c..a250ecd55f1a9 100644 --- a/x-pack/plugins/upgrade_assistant/kibana.json +++ b/x-pack/plugins/upgrade_assistant/kibana.json @@ -8,7 +8,7 @@ "githubTeam": "kibana-stack-management" }, "configPath": ["xpack", "upgrade_assistant"], - "requiredPlugins": ["management", "discover", "data", "licensing", "features", "infra"], + "requiredPlugins": ["management", "discover", "data", "licensing", "features", "infra", "share"], "optionalPlugins": ["usageCollection", "cloud"], "requiredBundles": ["esUiShared", "kibanaReact"] } diff --git a/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx b/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx index 88b5bd4721c36..7731ec734fed8 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx @@ -5,6 +5,7 @@ * 2.0. */ +import React, { createContext, useContext } from 'react'; import { CoreStart, DeprecationsServiceStart, @@ -12,7 +13,8 @@ import { HttpSetup, NotificationsStart, } from 'src/core/public'; -import React, { createContext, useContext } from 'react'; +import { SharePluginSetup } from 'src/plugins/share/public'; + import { ApiService } from './lib/api'; import { BreadcrumbService } from './lib/breadcrumbs'; @@ -32,6 +34,7 @@ export interface ContextValue { breadcrumbs: BreadcrumbService; getUrlForApp: CoreStart['application']['getUrlForApp']; deprecations: DeprecationsServiceStart; + share: SharePluginSetup; } export const AppContext = createContext({} as any); diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx index f8a8c0be24e05..7a2dd017b75e9 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx @@ -5,12 +5,14 @@ * 2.0. */ -import React from 'react'; - -import { EuiText } from '@elastic/eui'; +import React, { useState, useEffect } from 'react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; +import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui'; import type { EuiStepProps } from '@elastic/eui/src/components/steps/step'; +import { useAppContext } from '../../../app_context'; + interface Props { nextMajor: number; } @@ -27,12 +29,48 @@ const i18nTexts = { }), }; +const SnapshotRestoreAppLink: React.FunctionComponent = () => { + const { share } = useAppContext(); + + const [snapshotRestoreUrl, setSnapshotRestoreUrl] = useState(); + + useEffect(() => { + const getSnapshotRestoreUrl = async () => { + const locator = share.url.locators.get('SNAPSHOT_RESTORE_LOCATOR'); + + if (!locator) { + return; + } + + const url = await locator.getUrl({ + page: 'snapshots', + }); + setSnapshotRestoreUrl(url); + }; + + getSnapshotRestoreUrl(); + }, [share]); + + return ( + + + + ); +}; + const BackupStep: React.FunctionComponent = ({ nextMajor }) => { return ( <>

{i18nTexts.backupStepDescription(nextMajor)}

+ + + + ); }; diff --git a/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.ts b/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.tsx similarity index 67% rename from x-pack/plugins/upgrade_assistant/public/application/mount_management_section.ts rename to x-pack/plugins/upgrade_assistant/public/application/mount_management_section.tsx index 9fa52e90c9d0e..938b43672a4d1 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.ts +++ b/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.tsx @@ -5,19 +5,36 @@ * 2.0. */ +import React from 'react'; +import { render, unmountComponentAtNode } from 'react-dom'; import { CoreSetup } from 'src/core/public'; -import { ManagementAppMountParams } from '../../../../../src/plugins/management/public'; -import { renderApp } from './render_app'; +import { ManagementAppMountParams } from 'src/plugins/management/public'; +import { SharePluginSetup } from 'src/plugins/share/public'; + import { KibanaVersionContext } from './app_context'; +import { AppDependencies, RootComponent } from './app'; import { apiService } from './lib/api'; import { breadcrumbService } from './lib/breadcrumbs'; import { AppServicesContext } from '../types'; +interface BootDependencies extends AppDependencies { + element: HTMLElement; +} + +const renderApp = (deps: BootDependencies) => { + const { element, ...appDependencies } = deps; + render(, element); + return () => { + unmountComponentAtNode(element); + }; +}; + export async function mountManagementSection( coreSetup: CoreSetup, params: ManagementAppMountParams, kibanaVersionInfo: KibanaVersionContext, readonly: boolean, + share: SharePluginSetup, services: AppServicesContext ) { const [ @@ -44,6 +61,7 @@ export async function mountManagementSection( getUrlForApp: application.getUrlForApp, deprecations, application, + share, services, }); } diff --git a/x-pack/plugins/upgrade_assistant/public/plugin.ts b/x-pack/plugins/upgrade_assistant/public/plugin.ts index 558deffe43d94..ca7ee174b20f5 100644 --- a/x-pack/plugins/upgrade_assistant/public/plugin.ts +++ b/x-pack/plugins/upgrade_assistant/public/plugin.ts @@ -15,7 +15,7 @@ import { Config } from '../common/config'; export class UpgradeAssistantUIPlugin implements Plugin { constructor(private ctx: PluginInitializerContext) {} - setup(coreSetup: CoreSetup, { management, cloud }: SetupDependencies) { + setup(coreSetup: CoreSetup, { management, cloud, share }: SetupDependencies) { const { enabled, readonly } = this.ctx.config.get(); if (!enabled) { @@ -56,6 +56,7 @@ export class UpgradeAssistantUIPlugin params, kibanaVersionInfo, readonly, + share, services ); diff --git a/x-pack/plugins/upgrade_assistant/public/types.ts b/x-pack/plugins/upgrade_assistant/public/types.ts index a2b49305c32d4..356a2e22c3c7f 100644 --- a/x-pack/plugins/upgrade_assistant/public/types.ts +++ b/x-pack/plugins/upgrade_assistant/public/types.ts @@ -8,19 +8,22 @@ import { DiscoverStart } from 'src/plugins/discover/public'; import { ManagementSetup } from 'src/plugins/management/public'; import { DataPublicPluginStart } from 'src/plugins/data/public'; +import { SharePluginSetup } from 'src/plugins/share/public'; import { CloudSetup } from '../../cloud/public'; import { LicensingPluginStart } from '../../licensing/public'; export interface AppServicesContext { - cloud?: CloudSetup; discover: DiscoverStart; data: DataPublicPluginStart; + cloud?: CloudSetup; } export interface SetupDependencies { management: ManagementSetup; + share: SharePluginSetup; cloud?: CloudSetup; } + export interface StartDependencies { licensing: LicensingPluginStart; discover: DiscoverStart; From fb7106cecc655ec2864d59ffe3eb4299e80e28b2 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Fri, 20 Aug 2021 14:08:36 -0700 Subject: [PATCH 03/12] Remove unused dependency upon nextMajor. --- .../overview/backup_step/backup_step.tsx | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx index 7a2dd017b75e9..6baa0a3e3537c 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx @@ -13,20 +13,14 @@ import type { EuiStepProps } from '@elastic/eui/src/components/steps/step'; import { useAppContext } from '../../../app_context'; -interface Props { - nextMajor: number; -} - const i18nTexts = { backupStepTitle: i18n.translate('xpack.upgradeAssistant.overview.backupStepTitle', { defaultMessage: 'Back up your data', }), - backupStepDescription: (nextMajor: number) => - i18n.translate('xpack.upgradeAssistant.overview.backupStepDescription', { - defaultMessage: 'Back up your data before addressing any deprecation issues.', - values: { nextMajor }, - }), + backupStepDescription: i18n.translate('xpack.upgradeAssistant.overview.backupStepDescription', { + defaultMessage: 'Back up your data before addressing any deprecation issues.', + }), }; const SnapshotRestoreAppLink: React.FunctionComponent = () => { @@ -61,11 +55,11 @@ const SnapshotRestoreAppLink: React.FunctionComponent = () => { ); }; -const BackupStep: React.FunctionComponent = ({ nextMajor }) => { +const BackupStep: React.FunctionComponent = () => { return ( <> -

{i18nTexts.backupStepDescription(nextMajor)}

+

{i18nTexts.backupStepDescription}

@@ -75,14 +69,10 @@ const BackupStep: React.FunctionComponent = ({ nextMajor }) => { ); }; -interface GetStepConfig { - nextMajor: number; -} - -export const getBackupStep = ({ nextMajor }: GetStepConfig): EuiStepProps => { +export const getBackupStep = (): EuiStepProps => { return { title: i18nTexts.backupStepTitle, status: 'incomplete', - children: , + children: , }; }; From 58f7a223cd3601152d041583baf7a822d8fc26c1 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 23 Aug 2021 11:36:20 -0700 Subject: [PATCH 04/12] Mock share service. Fix share service TS error. --- .../__jest__/client_integration/helpers/app_context.mock.ts | 2 ++ .../upgrade_assistant/public/application/app_context.tsx | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts index ce9a1fbf79197..40952df8815ea 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts @@ -11,6 +11,7 @@ import { notificationServiceMock, applicationServiceMock, } from 'src/core/public/mocks'; +import { sharePluginMock } from 'src/plugins/share/public/mocks'; import { HttpSetup } from 'src/core/public'; import { mockKibanaSemverVersion } from '../../../common/constants'; @@ -31,4 +32,5 @@ export const getAppContextMock = (mockHttpClient: HttpSetup) => ({ breadcrumbs: breadcrumbService, getUrlForApp: applicationServiceMock.createStartContract().getUrlForApp, deprecations: deprecationsServiceMock.createStartContract(), + share: sharePluginMock.createSetupContract(), }); diff --git a/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx b/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx index 7731ec734fed8..9543c1c4db385 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx @@ -14,7 +14,6 @@ import { NotificationsStart, } from 'src/core/public'; import { SharePluginSetup } from 'src/plugins/share/public'; - import { ApiService } from './lib/api'; import { BreadcrumbService } from './lib/breadcrumbs'; From b94b6d915c13c3cca4af2828aed45bc384414004 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 23 Aug 2021 12:38:11 -0700 Subject: [PATCH 05/12] Fix nextMajor TS error. --- .../public/application/components/overview/overview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx index 8b2c1fc56c776..9399de6630a95 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx @@ -84,7 +84,7 @@ export const Overview: FunctionComponent = () => { Date: Mon, 23 Aug 2021 13:52:51 -0700 Subject: [PATCH 06/12] Remove unnecessary describe block from Upgrade Step tests. --- .../upgrade_step/upgrade_step.test.tsx | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx index 617aea19a129d..9b28b538734f6 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx @@ -23,36 +23,33 @@ describe('Overview - Upgrade Step', () => { server.restore(); }); - describe('Step 3 - Upgrade stack', () => { - test('Shows link to setup upgrade docs for on-prem installations', () => { - const { exists } = testBed; + test('Shows link to setup upgrade docs for on-prem installations', () => { + const { exists } = testBed; - expect(exists('upgradeSetupDocsLink')).toBe(true); - expect(exists('upgradeSetupCloudLink')).toBe(false); - }); + expect(exists('upgradeSetupDocsLink')).toBe(true); + expect(exists('upgradeSetupCloudLink')).toBe(false); + }); - test('Shows upgrade cta and link to docs for cloud installations', async () => { - await act(async () => { - testBed = await setupOverviewPage({ - kibanaContextOverrides: { - cloud: { - isCloudEnabled: true, - deploymentUrl: - 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63', - }, + test('Shows upgrade CTA and link to docs for cloud installations', async () => { + await act(async () => { + testBed = await setupOverviewPage({ + kibanaContextOverrides: { + cloud: { + isCloudEnabled: true, + deploymentUrl: 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63', }, - }); + }, }); + }); - const { component, exists, find } = testBed; - component.update(); + const { component, exists, find } = testBed; + component.update(); - expect(exists('upgradeSetupCloudLink')).toBe(true); - expect(exists('upgradeSetupDocsLink')).toBe(true); + expect(exists('upgradeSetupCloudLink')).toBe(true); + expect(exists('upgradeSetupDocsLink')).toBe(true); - expect(find('upgradeSetupCloudLink').props().href).toBe( - 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63' - ); - }); + expect(find('upgradeSetupCloudLink').props().href).toBe( + 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63' + ); }); }); From f3ea2ff6d18db17aaafcf4773943e2f7b85ebf5c Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 23 Aug 2021 13:55:37 -0700 Subject: [PATCH 07/12] Add CIT. --- .../overview/backup_step/backup_step.test.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx new file mode 100644 index 0000000000000..3f77adbb31381 --- /dev/null +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx @@ -0,0 +1,32 @@ +/* + * 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 { OverviewTestBed, setupOverviewPage } from '../overview.helpers'; + +describe('Overview - Backup Step', () => { + let testBed: OverviewTestBed; + const { server } = setupEnvironment(); + + beforeEach(async () => { + testBed = await setupOverviewPage(); + testBed.component.update(); + }); + + afterAll(() => { + server.restore(); + }); + + describe('On-prem', () => { + test('Shows link to Snapshot and Restore', () => { + const { exists } = testBed; + expect(exists('snapshotRestoreLink')).toBe(true); + }); + }); +}); From c75ff8fa2481a84f6d3aa4e7bf8097eb43c1d53a Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 23 Aug 2021 15:15:07 -0700 Subject: [PATCH 08/12] Remove unused import. --- .../overview/backup_step/backup_step.test.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx index 3f77adbb31381..9294966f51eb5 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx @@ -5,8 +5,6 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; - import { setupEnvironment } from '../../helpers'; import { OverviewTestBed, setupOverviewPage } from '../overview.helpers'; From 4fc94075fd2efd9b717c6f3797a19f644df58869 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 23 Aug 2021 15:19:05 -0700 Subject: [PATCH 09/12] Differentiate between Cloud and on-prem scenarios more clearly in Upgrade Step tests. --- .../upgrade_step/upgrade_step.test.tsx | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx index 9b28b538734f6..61fc6b45fa4c7 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx @@ -23,33 +23,38 @@ describe('Overview - Upgrade Step', () => { server.restore(); }); - test('Shows link to setup upgrade docs for on-prem installations', () => { - const { exists } = testBed; + describe('On-prem', () => { + test('Shows link to setup upgrade docs', () => { + const { exists } = testBed; - expect(exists('upgradeSetupDocsLink')).toBe(true); - expect(exists('upgradeSetupCloudLink')).toBe(false); + expect(exists('upgradeSetupDocsLink')).toBe(true); + expect(exists('upgradeSetupCloudLink')).toBe(false); + }); }); - test('Shows upgrade CTA and link to docs for cloud installations', async () => { - await act(async () => { - testBed = await setupOverviewPage({ - kibanaContextOverrides: { - cloud: { - isCloudEnabled: true, - deploymentUrl: 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63', + describe('On Cloud', () => { + test('Shows upgrade CTA and link to docs', async () => { + await act(async () => { + testBed = await setupOverviewPage({ + kibanaContextOverrides: { + cloud: { + isCloudEnabled: true, + deploymentUrl: + 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63', + }, }, - }, + }); }); - }); - const { component, exists, find } = testBed; - component.update(); + const { component, exists, find } = testBed; + component.update(); - expect(exists('upgradeSetupCloudLink')).toBe(true); - expect(exists('upgradeSetupDocsLink')).toBe(true); + expect(exists('upgradeSetupDocsLink')).toBe(true); + expect(exists('upgradeSetupCloudLink')).toBe(true); - expect(find('upgradeSetupCloudLink').props().href).toBe( - 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63' - ); + expect(find('upgradeSetupCloudLink').props().href).toBe( + 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63' + ); + }); }); }); From 165879aba36cd494b3bc72da36165c90325ec498 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 23 Aug 2021 19:35:08 -0700 Subject: [PATCH 10/12] Remove unused render_app.tsx. --- .../public/application/render_app.tsx | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 x-pack/plugins/upgrade_assistant/public/application/render_app.tsx diff --git a/x-pack/plugins/upgrade_assistant/public/application/render_app.tsx b/x-pack/plugins/upgrade_assistant/public/application/render_app.tsx deleted file mode 100644 index 248e6961a74e5..0000000000000 --- a/x-pack/plugins/upgrade_assistant/public/application/render_app.tsx +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 React from 'react'; -import { render, unmountComponentAtNode } from 'react-dom'; -import { AppDependencies, RootComponent } from './app'; - -interface BootDependencies extends AppDependencies { - element: HTMLElement; -} - -export const renderApp = (deps: BootDependencies) => { - const { element, ...appDependencies } = deps; - render(, element); - return () => { - unmountComponentAtNode(element); - }; -}; From ff9780313c68d16fd8e950585256e372d6912d13 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 23 Aug 2021 19:37:34 -0700 Subject: [PATCH 11/12] Convert FormattedMessage to i18n.translate. --- .../components/overview/backup_step/backup_step.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx index 6baa0a3e3537c..006d8ed3d38ae 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx @@ -6,7 +6,6 @@ */ import React, { useState, useEffect } from 'react'; -import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui'; import type { EuiStepProps } from '@elastic/eui/src/components/steps/step'; @@ -47,10 +46,9 @@ const SnapshotRestoreAppLink: React.FunctionComponent = () => { return ( - + {i18n.translate('xpack.upgradeAssistant.overview.snapshotRestoreLink', { + defaultMessage: 'Create snapshot', + })} ); }; From 993ca8faec8097c0c929f37be1a5cd65a4ae7fd5 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 24 Aug 2021 09:50:43 -0700 Subject: [PATCH 12/12] Add test for href value of Snapshot and Restore link. --- .../client_integration/helpers/app_context.mock.ts | 13 ++++++++++++- .../overview/backup_step/backup_step.test.tsx | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts index 40952df8815ea..b8d8e3d2505ef 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts @@ -18,6 +18,17 @@ import { mockKibanaSemverVersion } from '../../../common/constants'; import { apiService } from '../../../public/application/lib/api'; import { breadcrumbService } from '../../../public/application/lib/breadcrumbs'; +// We'll mock these values to avoid testing the locators themselves. +const idToUrlMap = { + SNAPSHOT_RESTORE_LOCATOR: 'snapshotAndRestoreUrl', +}; + +const shareMock = sharePluginMock.createSetupContract(); +shareMock.url.locators.get = (id) => ({ + // @ts-expect-error This object is missing some properties that we're not using in the UI + getUrl: (): string | undefined => idToUrlMap[id], +}); + export const getAppContextMock = (mockHttpClient: HttpSetup) => ({ http: mockHttpClient, docLinks: docLinksServiceMock.createStartContract(), @@ -32,5 +43,5 @@ export const getAppContextMock = (mockHttpClient: HttpSetup) => ({ breadcrumbs: breadcrumbService, getUrlForApp: applicationServiceMock.createStartContract().getUrlForApp, deprecations: deprecationsServiceMock.createStartContract(), - share: sharePluginMock.createSetupContract(), + share: shareMock, }); diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx index 9294966f51eb5..ab571790d56c6 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx @@ -23,8 +23,9 @@ describe('Overview - Backup Step', () => { describe('On-prem', () => { test('Shows link to Snapshot and Restore', () => { - const { exists } = testBed; + const { exists, find } = testBed; expect(exists('snapshotRestoreLink')).toBe(true); + expect(find('snapshotRestoreLink').props().href).toBe('snapshotAndRestoreUrl'); }); }); });