From d484379828d8893d4e6657d94167a5d60f324f87 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Sun, 10 Dec 2023 14:09:06 +0200 Subject: [PATCH] Mock more hooks and use fake timers --- .../case_view/case_view_page.test.tsx | 23 +++++++++++++++++-- .../public/components/case_view/index.tsx | 1 - .../public/components/case_view/types.ts | 1 - .../use_get_case_user_actions_stats.test.tsx | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/cases/public/components/case_view/case_view_page.test.tsx b/x-pack/plugins/cases/public/components/case_view/case_view_page.test.tsx index 6d2be83b0cb46..87b81f82625b8 100644 --- a/x-pack/plugins/cases/public/components/case_view/case_view_page.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/case_view_page.test.tsx @@ -13,6 +13,8 @@ import { createAppMockRenderer } from '../../common/mock'; import '../../common/mock/match_media'; import { useCaseViewNavigation, useUrlParams } from '../../common/navigation/hooks'; import { useGetSupportedActionConnectors } from '../../containers/configure/use_get_supported_action_connectors'; +import { useGetActionTypes } from '../../containers/configure/use_action_types'; +import { useGetCaseConfiguration } from '../../containers/configure/use_get_case_configuration'; import { basicCaseClosed, connectorsMock, getCaseUsersMockResponse } from '../../containers/mock'; import type { UseGetCase } from '../../containers/use_get_case'; import { useGetCase } from '../../containers/use_get_case'; @@ -36,7 +38,7 @@ import { import type { CaseViewPageProps } from './types'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; import { CASE_VIEW_PAGE_TABS } from '../../../common/types'; -import { getCaseConnectorsMockResponse } from '../../common/mock/connectors'; +import { actionTypesMock, getCaseConnectorsMockResponse } from '../../common/mock/connectors'; import { useInfiniteFindCaseUserActions } from '../../containers/use_infinite_find_case_user_actions'; import { useGetCaseUserActionsStats } from '../../containers/use_get_case_user_actions_stats'; import { createQueryWithMarkup } from '../../common/test_utils'; @@ -44,6 +46,9 @@ import { useCasesFeatures } from '../../common/use_cases_features'; import { CaseMetricsFeature } from '../../../common/types/api'; import { useGetCategories } from '../../containers/use_get_categories'; import { useSuggestUserProfiles } from '../../containers/user_profiles/use_suggest_user_profiles'; +import { casesConfigurationsMock } from '../../containers/configure/mock'; +import { useGetCurrentUserProfile } from '../../containers/user_profiles/use_get_current_user_profile'; +import { userProfiles } from '../../containers/user_profiles/api.mock'; jest.mock('../../containers/use_get_action_license'); jest.mock('../../containers/use_update_case'); @@ -54,6 +59,8 @@ jest.mock('../../containers/use_get_case_user_actions_stats'); jest.mock('../../containers/use_get_tags'); jest.mock('../../containers/use_get_case'); jest.mock('../../containers/configure/use_get_supported_action_connectors'); +jest.mock('../../containers/configure/use_action_types'); +jest.mock('../../containers/configure/use_get_case_configuration'); jest.mock('../../containers/use_post_push_to_service'); jest.mock('../../containers/use_get_case_connectors'); jest.mock('../../containers/use_get_case_users'); @@ -68,6 +75,7 @@ jest.mock('../../common/hooks'); jest.mock('../connectors/resilient/api'); jest.mock('../../common/lib/kibana'); jest.mock('../../containers/use_get_categories'); +jest.mock('../../containers/user_profiles/use_get_current_user_profile'); const useFetchCaseMock = useGetCase as jest.Mock; const useUrlParamsMock = useUrlParams as jest.Mock; @@ -77,6 +85,8 @@ const useFindCaseUserActionsMock = useFindCaseUserActions as jest.Mock; const useInfiniteFindCaseUserActionsMock = useInfiniteFindCaseUserActions as jest.Mock; const useGetCaseUserActionsStatsMock = useGetCaseUserActionsStats as jest.Mock; const useGetConnectorsMock = useGetSupportedActionConnectors as jest.Mock; +const useGetActionTypesMock = useGetActionTypes as jest.Mock; +const useGetCaseConfigurationMock = useGetCaseConfiguration as jest.Mock; const usePostPushToServiceMock = usePostPushToService as jest.Mock; const useGetCaseConnectorsMock = useGetCaseConnectors as jest.Mock; const useGetCaseMetricsMock = useGetCaseMetrics as jest.Mock; @@ -85,6 +95,7 @@ const useGetCaseUsersMock = useGetCaseUsers as jest.Mock; const useCasesFeaturesMock = useCasesFeatures as jest.Mock; const useGetCategoriesMock = useGetCategories as jest.Mock; const useSuggestUserProfilesMock = useSuggestUserProfiles as jest.Mock; +const useGetCurrentUserProfileMock = useGetCurrentUserProfile as jest.Mock; const mockGetCase = (props: Partial = {}) => { const data = { @@ -101,7 +112,6 @@ const mockGetCase = (props: Partial = {}) => { export const caseProps: CaseViewPageProps = { ...caseViewProps, - caseId: caseData.id, caseData, fetchCase: jest.fn(), }; @@ -161,6 +171,8 @@ describe('CaseViewPage', () => { configurable: true, writable: true, }); + + jest.useFakeTimers(); }); beforeEach(() => { @@ -180,6 +192,11 @@ describe('CaseViewPage', () => { data: caseConnectors, }); useGetConnectorsMock.mockReturnValue({ data: connectorsMock, isLoading: false }); + useGetActionTypesMock.mockReturnValue({ data: actionTypesMock, isLoading: false }); + useGetCaseConfigurationMock.mockReturnValue({ + data: casesConfigurationsMock, + isLoading: false, + }); useGetTagsMock.mockReturnValue({ data: [], isLoading: false }); useGetCaseUsersMock.mockReturnValue({ isLoading: false, data: caseUsers }); useCasesFeaturesMock.mockReturnValue({ @@ -192,12 +209,14 @@ describe('CaseViewPage', () => { useGetCategoriesMock.mockReturnValue({ data: [], isLoading: false }); useSuggestUserProfilesMock.mockReturnValue({ data: [], isLoading: false }); useUrlParamsMock.mockReturnValue({}); + useGetCurrentUserProfileMock.mockReturnValue({ isLoading: false, data: userProfiles[0] }); appMockRenderer = createAppMockRenderer({ license: platinumLicense }); }); afterAll(() => { Object.defineProperty(window, 'getComputedStyle', originalGetComputedStyle); + jest.useRealTimers(); }); for (let index = 0; index < 50; index++) { diff --git a/x-pack/plugins/cases/public/components/case_view/index.tsx b/x-pack/plugins/cases/public/components/case_view/index.tsx index 4ba3f912b9d0b..ecbde67ba15df 100644 --- a/x-pack/plugins/cases/public/components/case_view/index.tsx +++ b/x-pack/plugins/cases/public/components/case_view/index.tsx @@ -86,7 +86,6 @@ export const CaseView = React.memo( {getLegacyUrlConflictCallout()} void; caseData: CaseUI; } diff --git a/x-pack/plugins/cases/public/containers/use_get_case_user_actions_stats.test.tsx b/x-pack/plugins/cases/public/containers/use_get_case_user_actions_stats.test.tsx index ce4e453ecbbf1..b81f9d1448aa2 100644 --- a/x-pack/plugins/cases/public/containers/use_get_case_user_actions_stats.test.tsx +++ b/x-pack/plugins/cases/public/containers/use_get_case_user_actions_stats.test.tsx @@ -22,7 +22,7 @@ const initialData = { isLoading: true, }; -describe('UseGetCaseUserActionsStats', () => { +describe('useGetCaseUserActionsStats', () => { let appMockRender: AppMockRenderer; beforeEach(() => {