Skip to content

Commit

Permalink
[7.10] [Telemetry] Add method to enable endpoint security data usage …
Browse files Browse the repository at this point in the history
…example (#80940) (#81170)
  • Loading branch information
Bamieh authored Oct 20, 2020
1 parent 20872b6 commit 71357a2
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 54 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('TelemetryManagementSectionComponent', () => {

it('renders as expected', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -51,6 +52,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={true}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
)
Expand All @@ -59,6 +61,7 @@ describe('TelemetryManagementSectionComponent', () => {

it('renders null because query does not match the SEARCH_TERMS', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -81,6 +84,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
</React.Suspense>
Expand All @@ -96,6 +100,7 @@ describe('TelemetryManagementSectionComponent', () => {
showAppliesSettingMessage={false}
enableSaving={true}
toasts={coreStart.notifications.toasts}
isSecurityExampleEnabled={isSecurityExampleEnabled}
/>
</React.Suspense>
);
Expand All @@ -108,6 +113,7 @@ describe('TelemetryManagementSectionComponent', () => {

it('renders because query matches the SEARCH_TERMS', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -128,6 +134,7 @@ describe('TelemetryManagementSectionComponent', () => {
telemetryService={telemetryService}
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
isSecurityExampleEnabled={isSecurityExampleEnabled}
enableSaving={true}
toasts={coreStart.notifications.toasts}
/>
Expand All @@ -152,6 +159,7 @@ describe('TelemetryManagementSectionComponent', () => {

it('renders null because allowChangingOptInStatus is false', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -173,6 +181,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={true}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
);
Expand All @@ -187,6 +196,7 @@ describe('TelemetryManagementSectionComponent', () => {

it('shows the OptInExampleFlyout', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -208,6 +218,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
);
Expand All @@ -223,6 +234,7 @@ describe('TelemetryManagementSectionComponent', () => {

it('shows the OptInSecurityExampleFlyout', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -243,6 +255,7 @@ describe('TelemetryManagementSectionComponent', () => {
telemetryService={telemetryService}
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
isSecurityExampleEnabled={isSecurityExampleEnabled}
enableSaving={true}
toasts={coreStart.notifications.toasts}
/>
Expand All @@ -257,8 +270,47 @@ describe('TelemetryManagementSectionComponent', () => {
}
});

it('does not show the endpoint link when isSecurityExampleEnabled returns false', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(false);
const telemetryService = new TelemetryService({
config: {
enabled: true,
url: '',
banner: true,
allowChangingOptInStatus: true,
optIn: false,
optInStatusUrl: '',
sendUsageFrom: 'browser',
},
reportOptInStatusChange: false,
notifications: coreStart.notifications,
http: coreSetup.http,
});

const component = mountWithIntl(
<TelemetryManagementSection
telemetryService={telemetryService}
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
isSecurityExampleEnabled={isSecurityExampleEnabled}
enableSaving={true}
toasts={coreStart.notifications.toasts}
/>
);

try {
const description = (component.instance() as TelemetryManagementSection).renderDescription();
expect(isSecurityExampleEnabled).toBeCalled();
expect(description).toMatchSnapshot();
} finally {
component.unmount();
}
});

it('toggles the OptIn button', async () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -280,6 +332,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
);
Expand All @@ -304,6 +357,7 @@ describe('TelemetryManagementSectionComponent', () => {

it('test the wrapper (for coverage purposes)', () => {
const onQueryMatchChange = jest.fn();
const isSecurityExampleEnabled = jest.fn().mockReturnValue(true);
const telemetryService = new TelemetryService({
config: {
enabled: true,
Expand All @@ -327,6 +381,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
enableSaving={true}
toasts={coreStart.notifications.toasts}
isSecurityExampleEnabled={isSecurityExampleEnabled}
/>
).html()
).toMatchSnapshot();
Expand Down
Loading

0 comments on commit 71357a2

Please sign in to comment.