diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/TableProfilerProvider.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/TableProfilerProvider.test.tsx new file mode 100644 index 00000000000..ed1d0fc5c9e --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/TableProfilerProvider.test.tsx @@ -0,0 +1,102 @@ +/* + * Copyright 2024 Collate. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* eslint-disable i18next/no-literal-string */ +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import { OperationPermission } from '../../../../context/PermissionProvider/PermissionProvider.interface'; +import { getListTestCase } from '../../../../rest/testAPI'; +import { TableProfilerProvider } from './TableProfilerProvider'; + +// Mock dependencies +jest.mock('react-router-dom', () => ({ + useLocation: jest + .fn() + .mockReturnValue({ search: '?activeTab=Data%20Quality' }), +})); +jest.mock('../../../../context/TourProvider/TourProvider', () => ({ + useTourProvider: jest.fn().mockReturnValue({ isTourOpen: false }), +})); +jest.mock('../../../../hooks/paging/usePaging', () => ({ + usePaging: jest + .fn() + .mockReturnValue({ handlePagingChange: jest.fn(), pageSize: 10 }), +})); +jest.mock('../../../../rest/tableAPI', () => ({ + getLatestTableProfileByFqn: jest.fn().mockResolvedValue({}), + getTableDetailsByFQN: jest.fn().mockResolvedValue({}), +})); +jest.mock('../../../../rest/testAPI', () => ({ + getListTestCase: jest.fn().mockResolvedValue({ data: [], paging: {} }), +})); +jest.mock('../../../../utils/ToastUtils', () => ({ + showErrorToast: jest.fn(), +})); +jest.mock('../../../../utils/TableUtils', () => ({ + generateEntityLink: jest.fn().mockReturnValue('entityLink'), +})); +jest.mock('../../../../constants/mockTourData.constants', () => ({ + mockDatasetData: { tableDetails: {} }, +})); +jest.mock('../../../../hooks/useFqn', () => ({ + useFqn: jest.fn().mockReturnValue('table1'), +})); +jest.mock('../../../../constants/profiler.constant', () => ({ + DEFAULT_RANGE_DATA: { + startTs: 1710825218156, + endTs: 1711084418157, + }, +})); +jest.mock('./ProfilerSettingsModal/ProfilerSettingsModal', () => + jest.fn().mockReturnValue(
ProfilerSettingsModal.component
) +); +jest.mock('../../../../constants/constants', () => ({ + PAGE_SIZE: 10, +})); +const mockPermissions = { + ViewAll: true, + ViewBasic: true, + ViewTests: true, +} as OperationPermission; + +describe('TableProfilerProvider', () => { + it('renders children without crashing', async () => { + render( + +
Test Children
+
+ ); + + expect(await screen.findByText('Test Children')).toBeInTheDocument(); + }); + + it('test cases should be fetch on data quality tab', async () => { + const mockGetListTestCase = getListTestCase as jest.Mock; + render( + +
Test Children
+
+ ); + + expect(mockGetListTestCase).toHaveBeenCalledTimes(1); + expect(mockGetListTestCase).toHaveBeenCalledWith({ + entityLink: 'entityLink', + fields: 'testCaseResult, incidentId', + includeAllTests: true, + limit: 10, + }); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/TableProfilerProvider.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/TableProfilerProvider.tsx index d0046399607..06a7df8f639 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/TableProfilerProvider.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/TableProfilerProvider.tsx @@ -246,6 +246,7 @@ export const TableProfilerProvider = ({ if (fetchTest) { fetchAllTests(); } else { + setAllTestCases([]); setIsTestsLoading(false); } }, [viewTest, isTourOpen, activeTab, testCasePaging.pageSize]);