From c1b56afcb3df857d62ee4992bc3b2fd9baf044e1 Mon Sep 17 00:00:00 2001 From: sulemanof Date: Wed, 17 Jun 2020 17:34:10 +0300 Subject: [PATCH] Fix jest test, update telemetry mocks --- .../__snapshots__/welcome.test.tsx.snap | 3 -- .../application/components/welcome.test.tsx | 35 +++++-------------- src/plugins/telemetry/public/mocks.ts | 23 +++++++++--- 3 files changed, 28 insertions(+), 33 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/telemetry/public/mocks.ts b/src/plugins/telemetry/public/mocks.ts index 9ec4a3ae86cc7..dd7e5a4cc4ce3 100644 --- a/src/plugins/telemetry/public/mocks.ts +++ b/src/plugins/telemetry/public/mocks.ts @@ -25,7 +25,7 @@ import { httpServiceMock } from '../../../core/public/http/http_service.mock'; import { notificationServiceMock } from '../../../core/public/notifications/notifications_service.mock'; import { TelemetryService } from './services/telemetry_service'; import { TelemetryNotifications } from './services/telemetry_notifications/telemetry_notifications'; -import { TelemetryPluginStart, TelemetryPluginConfig } from './plugin'; +import { TelemetryPluginStart, TelemetryPluginSetup, TelemetryPluginConfig } from './plugin'; // The following is to be able to access private methods /* eslint-disable dot-notation */ @@ -77,20 +77,35 @@ export function mockTelemetryNotifications({ }); } -export type Setup = jest.Mocked; +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; +}