Fix home page loading if telemetry plugin disabled (#69394)
* Fix home page loading * Fix jest test, update telemetry mocks
This commit is contained in:
parent
72111702e9
commit
90f61abd3f
|
@ -125,7 +125,6 @@ exports[`should render a Welcome screen with the telemetry disclaimer 1`] = `
|
|||
values={Object {}}
|
||||
/>
|
||||
<EuiLink
|
||||
href="https://www.elastic.co/legal/privacy-statement"
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
>
|
||||
|
@ -224,7 +223,6 @@ exports[`should render a Welcome screen with the telemetry disclaimer when optIn
|
|||
values={Object {}}
|
||||
/>
|
||||
<EuiLink
|
||||
href="https://www.elastic.co/legal/privacy-statement"
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
>
|
||||
|
@ -323,7 +321,6 @@ exports[`should render a Welcome screen with the telemetry disclaimer when optIn
|
|||
values={Object {}}
|
||||
/>
|
||||
<EuiLink
|
||||
href="https://www.elastic.co/legal/privacy-statement"
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
>
|
||||
|
|
|
@ -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
|
||||
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
|
||||
);
|
||||
const telemetry = telemetryPluginMock.createStartContract();
|
||||
const component = shallow(<Welcome urlBasePath="/" onSkip={() => {}} 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
|
||||
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
|
||||
);
|
||||
const component = shallow(<Welcome urlBasePath="/" onSkip={() => {}} 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
|
||||
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
|
||||
);
|
||||
const component = shallow(<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />);
|
||||
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render a Welcome screen with no telemetry disclaimer', () => {
|
||||
// @ts-ignore
|
||||
const component = shallow(
|
||||
// @ts-ignore
|
||||
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={null} />
|
||||
);
|
||||
const component = shallow(<Welcome urlBasePath="/" onSkip={() => {}} />);
|
||||
|
||||
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
|
||||
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
|
||||
);
|
||||
shallow(<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />);
|
||||
|
||||
expect(mockSetOptedInNoticeSeen).toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
@ -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<Props> {
|
|||
id="home.dataManagementDisclaimerPrivacy"
|
||||
defaultMessage="To learn about how usage data helps us manage and improve our products and services, see our "
|
||||
/>
|
||||
<EuiLink href={PRIVACY_STATEMENT_URL} target="_blank" rel="noopener">
|
||||
<EuiLink
|
||||
href={telemetry.telemetryConstants.getPrivacyStatementUrl()}
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
<FormattedMessage
|
||||
id="home.dataManagementDisclaimerPrivacyLink"
|
||||
defaultMessage="Privacy Statement."
|
||||
|
|
|
@ -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<TelemetryPluginStart>;
|
||||
export type Setup = jest.Mocked<TelemetryPluginSetup>;
|
||||
export type Start = jest.Mocked<TelemetryPluginStart>;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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<TelemetryPluginSetup, TelemetryPl
|
|||
return {
|
||||
telemetryService: this.telemetryService,
|
||||
telemetryNotifications: this.telemetryNotifications,
|
||||
telemetryConstants: {
|
||||
getPrivacyStatementUrl: () => PRIVACY_STATEMENT_URL,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue