Skip to content

Commit f9c45c9

Browse files
committed
test: Enhance UserPreferenceCheckboxField and UserPreferenceDropdownField tests by mocking useTelemetry hook
1 parent ed98edb commit f9c45c9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

frontend/packages/console-app/src/components/user-preferences/__tests__/UserPreferenceCheckboxField.spec.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import * as React from 'react';
22
import { Checkbox, Skeleton } from '@patternfly/react-core';
33
import { shallow, ShallowWrapper } from 'enzyme';
44
import { UserPreferenceFieldType } from '@console/dynamic-plugin-sdk/src/extensions/user-preferences';
5-
import { useUserSettings } from '@console/shared';
5+
import { useUserSettings, useTelemetry } from '@console/shared';
66
import UserPreferenceCheckboxField from '../UserPreferenceCheckboxField';
77

88
jest.mock('@console/shared/src/hooks/useUserSettings', () => ({
99
useUserSettings: jest.fn(),
1010
}));
1111

12+
jest.mock('@console/shared/src/hooks/useTelemetry', () => ({
13+
useTelemetry: jest.fn(),
14+
}));
15+
1216
const mockUserSettings = useUserSettings as jest.Mock;
17+
const mockUseTelemetry = useTelemetry as jest.Mock;
1318

1419
describe('UserPreferenceCheckboxField', () => {
1520
type UserPreferenceCheckboxFieldProps = React.ComponentProps<typeof UserPreferenceCheckboxField>;
@@ -23,6 +28,10 @@ describe('UserPreferenceCheckboxField', () => {
2328
};
2429
let wrapper: ShallowWrapper<UserPreferenceCheckboxFieldProps>;
2530

31+
beforeEach(() => {
32+
mockUseTelemetry.mockReturnValue(jest.fn());
33+
});
34+
2635
afterEach(() => {
2736
jest.resetAllMocks();
2837
});

frontend/packages/console-app/src/components/user-preferences/__tests__/UserPreferenceDropdownField.spec.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import * as React from 'react';
22
import { Select, SelectProps } from '@patternfly/react-core';
33
import { shallow, ShallowWrapper } from 'enzyme';
44
import { UserPreferenceFieldType } from '@console/dynamic-plugin-sdk/src/extensions/user-preferences';
5-
import { useUserSettings } from '@console/shared';
5+
import { useUserSettings, useTelemetry } from '@console/shared';
66
import UserPreferenceDropdownField from '../UserPreferenceDropdownField';
77

88
jest.mock('@console/shared/src/hooks/useUserSettings', () => ({
99
useUserSettings: jest.fn(),
1010
}));
1111

12+
jest.mock('@console/shared/src/hooks/useTelemetry', () => ({
13+
useTelemetry: jest.fn(),
14+
}));
15+
1216
const mockUserSettings = useUserSettings as jest.Mock;
17+
const mockUseTelemetry = useTelemetry as jest.Mock;
1318

1419
describe('UserPreferenceDropdownField', () => {
1520
type UserPreferenceDropdownFieldProps = React.ComponentProps<typeof UserPreferenceDropdownField>;
@@ -24,6 +29,10 @@ describe('UserPreferenceDropdownField', () => {
2429
};
2530
let wrapper: ShallowWrapper<UserPreferenceDropdownFieldProps>;
2631

32+
beforeEach(() => {
33+
mockUseTelemetry.mockReturnValue(jest.fn());
34+
});
35+
2736
afterEach(() => {
2837
jest.resetAllMocks();
2938
});

0 commit comments

Comments
 (0)