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
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 @@ -52,6 +53,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={true}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
)
Expand All @@ -60,6 +62,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 @@ -83,6 +86,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
</React.Suspense>
Expand All @@ -98,6 +102,7 @@ describe('TelemetryManagementSectionComponent', () => {
showAppliesSettingMessage={false}
enableSaving={true}
toasts={coreStart.notifications.toasts}
isSecurityExampleEnabled={isSecurityExampleEnabled}
/>
</React.Suspense>
);
Expand All @@ -110,6 +115,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 @@ -131,6 +137,7 @@ describe('TelemetryManagementSectionComponent', () => {
telemetryService={telemetryService}
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
isSecurityExampleEnabled={isSecurityExampleEnabled}
enableSaving={true}
toasts={coreStart.notifications.toasts}
/>
Expand All @@ -155,6 +162,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 @@ -177,6 +185,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={true}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
);
Expand All @@ -191,6 +200,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 @@ -213,6 +223,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
);
Expand All @@ -228,6 +239,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 @@ -249,6 +261,7 @@ describe('TelemetryManagementSectionComponent', () => {
telemetryService={telemetryService}
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
isSecurityExampleEnabled={isSecurityExampleEnabled}
enableSaving={true}
toasts={coreStart.notifications.toasts}
/>
Expand All @@ -263,8 +276,48 @@ 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,
currentKibanaVersion: 'mock_kibana_version',
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 @@ -287,6 +340,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
showAppliesSettingMessage={false}
enableSaving={true}
isSecurityExampleEnabled={isSecurityExampleEnabled}
toasts={coreStart.notifications.toasts}
/>
);
Expand All @@ -311,6 +365,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 @@ -335,6 +390,7 @@ describe('TelemetryManagementSectionComponent', () => {
onQueryMatchChange={onQueryMatchChange}
enableSaving={true}
toasts={coreStart.notifications.toasts}
isSecurityExampleEnabled={isSecurityExampleEnabled}
/>
).html()
).toMatchSnapshot();
Expand Down
Loading