Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telemetry] Add method to enable endpoint security data usage example #80940

Merged

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, but might be more DRY to just set these (isSecurityExampleEnabled && onQueryMatchChange) in a beforeEach at the top of the relevant describe blocks since they don't seem to change for any of the tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually prefer to keep them like that in the tests to make it easier to read what is happening. each it has almost all it needs encapsulated inside it, so you can update/refactor the tests more easily if needed in the future.

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