From 90f61abd3f067e4e5fc74f4d30b407f462a82821 Mon Sep 17 00:00:00 2001 From: Daniil Suleiman <31325372+sulemanof@users.noreply.github.com> Date: Thu, 18 Jun 2020 18:27:46 +0300 Subject: [PATCH] Fix home page loading if telemetry plugin disabled (#69394) * Fix home page loading * Fix jest test, update telemetry mocks --- .../__snapshots__/welcome.test.tsx.snap | 3 -- .../application/components/welcome.test.tsx | 35 +++++-------------- .../public/application/components/welcome.tsx | 7 ++-- src/plugins/telemetry/public/mocks.ts | 23 +++++++++--- src/plugins/telemetry/public/plugin.ts | 7 ++++ 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/plugins/home/public/application/components/__snapshots__/welcome.test.tsx.snap b/src/plugins/home/public/application/components/__snapshots__/welcome.test.tsx.snap index 1c67f332a12ab..bdf1f075967cb 100644 --- a/src/plugins/home/public/application/components/__snapshots__/welcome.test.tsx.snap +++ b/src/plugins/home/public/application/components/__snapshots__/welcome.test.tsx.snap @@ -125,7 +125,6 @@ exports[`should render a Welcome screen with the telemetry disclaimer 1`] = ` values={Object {}} /> @@ -224,7 +223,6 @@ exports[`should render a Welcome screen with the telemetry disclaimer when optIn values={Object {}} /> @@ -323,7 +321,6 @@ exports[`should render a Welcome screen with the telemetry disclaimer when optIn values={Object {}} /> diff --git a/src/plugins/home/public/application/components/welcome.test.tsx b/src/plugins/home/public/application/components/welcome.test.tsx index 1332e03ffdc81..701fab3af7539 100644 --- a/src/plugins/home/public/application/components/welcome.test.tsx +++ b/src/plugins/home/public/application/components/welcome.test.tsx @@ -30,56 +30,39 @@ jest.mock('../kibana_services', () => ({ })); test('should render a Welcome screen with the telemetry disclaimer', () => { - const telemetry = telemetryPluginMock.createSetupContract(); - const component = shallow( - // @ts-ignore - {}} telemetry={telemetry} /> - ); + const telemetry = telemetryPluginMock.createStartContract(); + const component = shallow( {}} telemetry={telemetry} />); expect(component).toMatchSnapshot(); }); test('should render a Welcome screen with the telemetry disclaimer when optIn is true', () => { - const telemetry = telemetryPluginMock.createSetupContract(); + const telemetry = telemetryPluginMock.createStartContract(); telemetry.telemetryService.getIsOptedIn = jest.fn().mockReturnValue(true); - const component = shallow( - // @ts-ignore - {}} telemetry={telemetry} /> - ); + const component = shallow( {}} telemetry={telemetry} />); expect(component).toMatchSnapshot(); }); test('should render a Welcome screen with the telemetry disclaimer when optIn is false', () => { - const telemetry = telemetryPluginMock.createSetupContract(); + const telemetry = telemetryPluginMock.createStartContract(); telemetry.telemetryService.getIsOptedIn = jest.fn().mockReturnValue(false); - const component = shallow( - // @ts-ignore - {}} telemetry={telemetry} /> - ); + const component = shallow( {}} telemetry={telemetry} />); expect(component).toMatchSnapshot(); }); test('should render a Welcome screen with no telemetry disclaimer', () => { - // @ts-ignore - const component = shallow( - // @ts-ignore - {}} telemetry={null} /> - ); + const component = shallow( {}} />); expect(component).toMatchSnapshot(); }); test('fires opt-in seen when mounted', () => { - const telemetry = telemetryPluginMock.createSetupContract(); + const telemetry = telemetryPluginMock.createStartContract(); const mockSetOptedInNoticeSeen = jest.fn(); - // @ts-ignore telemetry.telemetryNotifications.setOptedInNoticeSeen = mockSetOptedInNoticeSeen; - shallow( - // @ts-ignore - {}} telemetry={telemetry} /> - ); + shallow( {}} telemetry={telemetry} />); expect(mockSetOptedInNoticeSeen).toHaveBeenCalled(); }); diff --git a/src/plugins/home/public/application/components/welcome.tsx b/src/plugins/home/public/application/components/welcome.tsx index d4dcaca317806..f82bd024b80b8 100644 --- a/src/plugins/home/public/application/components/welcome.tsx +++ b/src/plugins/home/public/application/components/welcome.tsx @@ -38,7 +38,6 @@ import { METRIC_TYPE } from '@kbn/analytics'; import { FormattedMessage } from '@kbn/i18n/react'; import { getServices } from '../kibana_services'; import { TelemetryPluginStart } from '../../../../telemetry/public'; -import { PRIVACY_STATEMENT_URL } from '../../../../telemetry/common/constants'; import { SampleDataCard } from './sample_data'; interface Props { @@ -162,7 +161,11 @@ export class Welcome extends React.Component { id="home.dataManagementDisclaimerPrivacy" defaultMessage="To learn about how usage data helps us manage and improve our products and services, see our " /> - + ; +export type Setup = jest.Mocked; +export type Start = jest.Mocked; export const telemetryPluginMock = { createSetupContract, + createStartContract, }; function createSetupContract(): Setup { const telemetryService = mockTelemetryService(); - const telemetryNotifications = mockTelemetryNotifications({ telemetryService }); const setupContract: Setup = { telemetryService, - telemetryNotifications, }; return setupContract; } + +function createStartContract(): Start { + const telemetryService = mockTelemetryService(); + const telemetryNotifications = mockTelemetryNotifications({ telemetryService }); + + const startContract: Start = { + telemetryService, + telemetryNotifications, + telemetryConstants: { + getPrivacyStatementUrl: jest.fn(), + }, + }; + + return startContract; +} diff --git a/src/plugins/telemetry/public/plugin.ts b/src/plugins/telemetry/public/plugin.ts index a363953978d79..3846e7cb96a19 100644 --- a/src/plugins/telemetry/public/plugin.ts +++ b/src/plugins/telemetry/public/plugin.ts @@ -38,6 +38,7 @@ import { getTelemetrySendUsageFrom, } from '../common/telemetry_config'; import { getNotifyUserAboutOptInDefault } from '../common/telemetry_config/get_telemetry_notify_user_about_optin_default'; +import { PRIVACY_STATEMENT_URL } from '../common/constants'; export interface TelemetryPluginSetup { telemetryService: TelemetryService; @@ -46,6 +47,9 @@ export interface TelemetryPluginSetup { export interface TelemetryPluginStart { telemetryService: TelemetryService; telemetryNotifications: TelemetryNotifications; + telemetryConstants: { + getPrivacyStatementUrl: () => string; + }; } export interface TelemetryPluginConfig { @@ -115,6 +119,9 @@ export class TelemetryPlugin implements Plugin PRIVACY_STATEMENT_URL, + }, }; }