Skip to content

Commit

Permalink
[React18] Migrated test suites to accommodate changes to testing libr…
Browse files Browse the repository at this point in the history
…ary owned by security-entity-analytics
  • Loading branch information
eokoneyo committed Nov 21, 2024
1 parent 51a84eb commit 3aec23a
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* 2.0.
*/

import { act, renderHook } from '@testing-library/react-hooks';
import { TestProviders } from '../../../common/mock';
import { RiskScoreEntity } from '../../../../common/search_strategy';
import { useCalculateEntityRiskScore } from './use_calculate_entity_risk_score';
import { waitFor } from '@testing-library/react';
import { waitFor, renderHook, act } from '@testing-library/react';
import { RiskEngineStatusEnum } from '../../../../common/api/entity_analytics/risk_engine/engine_status_route.gen';

const enabledRiskEngineStatus = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { renderHook } from '@testing-library/react-hooks';

import { waitFor, renderHook } from '@testing-library/react';
import { useRiskScore } from './use_risk_score';
import { TestProviders } from '../../../common/mock';

Expand Down Expand Up @@ -218,7 +219,7 @@ describe.each([RiskScoreEntity.host, RiskScoreEntity.user])(
totalCount: 0,
},
});
const { result, waitFor } = renderHook(() => useRiskScore({ riskEntity }), {
const { result } = renderHook(() => useRiskScore({ riskEntity }), {
wrapper: TestProviders,
});
await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { act, renderHook } from '@testing-library/react-hooks';

import { renderHook, act } from '@testing-library/react';
import { TestProviders } from '../../../common/mock';

import { useRiskScoreFeatureStatus } from './use_risk_score_feature_status';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { act } from '@testing-library/react-hooks';
import { act } from '@testing-library/react';
import { useScheduleNowRiskEngineMutation } from './use_schedule_now_risk_engine_mutation';
import { renderMutation } from '../../../management/hooks/test_utils';
import { RISK_ENGINE_SCHEDULE_NOW_URL } from '../../../../common/constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { renderMutation, renderQuery } from '../../../management/hooks/test_utils';
import {
renderMutation,
renderQuery,
renderWrappedHook,
} from '../../../management/hooks/test_utils';
import type { Entity } from './use_asset_criticality';
import { useAssetCriticalityPrivileges, useAssetCriticalityData } from './use_asset_criticality';

Expand Down Expand Up @@ -69,10 +73,7 @@ describe('useAssetCriticality', () => {
mockCreateAssetCriticality.mockResolvedValue({});
const entity: Entity = { name: 'test_entity_name', type: 'host' };

const { mutation } = await renderQuery(
() => useAssetCriticalityData({ entity }),
'isSuccess'
);
const { mutation } = await renderWrappedHook(() => useAssetCriticalityData({ entity }));

await renderMutation(async () =>
mutation.mutate({
Expand All @@ -91,10 +92,7 @@ describe('useAssetCriticality', () => {
mockCreateAssetCriticality.mockResolvedValue({});
const entity: Entity = { name: 'test_entity_name', type: 'host' };

const { mutation } = await renderQuery(
() => useAssetCriticalityData({ entity }),
'isSuccess'
);
const { mutation } = await renderWrappedHook(() => useAssetCriticalityData({ entity }));

await renderMutation(async () =>
mutation.mutate({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import { createTelemetryServiceMock } from '../../../common/lib/telemetry/telemetry_service.mock';
import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { waitFor } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import { waitFor, renderHook } from '@testing-library/react';
import { useFileValidation } from './hooks';
import { useKibana as mockUseKibana } from '../../../common/lib/kibana/__mocks__';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { AnomalyEntity } from '../../../common/components/ml/anomaly/use_anomalies_search';
import type { SecurityJob } from '../../../common/components/ml_popover/types';
import { useAnomaliesColumns } from './columns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { RiskScoreEntity } from '../../../../common/search_strategy/security_solution/risk_score';
import { useEntityInfo } from './use_entity';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import type { EuiContextMenuPanelDescriptor } from '@elastic/eui';
import { EuiContextMenu } from '@elastic/eui';
import { casesPluginMock } from '@kbn/cases-plugin/public/mocks';
import { render } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import { render, renderHook } from '@testing-library/react';
import React from 'react';
import { TestProviders } from '../../../../common/mock';
import { alertInputDataMock } from '../mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { useEntitiesListFilters } from './use_entities_list_filters';
import { useGlobalFilterQuery } from '../../../../common/hooks/use_global_filter_query';
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useEntitiesListQuery } from './use_entities_list_query';
import { useEntityAnalyticsRoutes } from '../../../api/api';
Expand All @@ -31,17 +31,14 @@ describe('useEntitiesListQuery', () => {

fetchEntitiesListMock.mockResolvedValueOnce({ data: 'test data' });

const { result, waitFor } = renderHook(
() => useEntitiesListQuery({ ...searchParams, skip: false }),
{
wrapper: TestWrapper,
}
);

await waitFor(() => result.current.isSuccess);
const { result } = renderHook(() => useEntitiesListQuery({ ...searchParams, skip: false }), {
wrapper: TestWrapper,
});

expect(fetchEntitiesListMock).toHaveBeenCalledWith({ params: searchParams });
expect(result.current.data).toEqual({ data: 'test data' });
await waitFor(() => {
expect(fetchEntitiesListMock).toHaveBeenCalledWith({ params: searchParams });
expect(result.current.data).toEqual({ data: 'test data' });
});
});

it('should not call fetchEntitiesList if skip is true', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { RiskSeverity } from '../../../../common/search_strategy';
import { useRiskDonutChartData } from './use_risk_donut_chart_data';
import type { SeverityCount } from '../severity/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { wrapper } from '../../common/components/visualization_actions/mocks';
import { useLensAttributes } from '../../common/components/visualization_actions/use_lens_attributes';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import type { XYState } from '@kbn/lens-plugin/public';

import { getRiskScoreOverTimeAreaAttributes } from './risk_score_over_time_area';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { RiskScoreEntity } from '../../../common/entity_analytics/risk_engine';
import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { getRiskScoreSummaryAttributes } from './risk_score_summary';
import { RiskSeverity } from '../../../common/search_strategy';
import type { MetricVisualizationState } from '@kbn/lens-plugin/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { useObservedHostFields } from './use_observed_host_fields';
import { mockObservedHostData } from '../../mocks';
import { TestProviders } from '../../../../common/mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import type { Integration } from '../../../../../common/api/detection_engine';
import { TestProviders } from '../../../../common/mock';
import { ENTRA_ID_PACKAGE_NAME } from '../constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { mockGlobalState, TestProviders, createMockStore } from '../../../../common/mock';
import { useManagedUserItems } from './use_managed_user_items';
import { mockEntraUserFields, mockOktaUserFields } from '../mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { mockObservedUser } from '../mocks';
import { TestProviders } from '../../../../common/mock';
import { useObservedUserItems } from './use_observed_user_items';
Expand Down

0 comments on commit 3aec23a

Please sign in to comment.