#15651 UI: Duplicate API calls in the data quality tab on the table details page (#15663)

This commit is contained in:
Shailesh Parmar 2024-03-22 14:40:01 +05:30 committed by GitHub
parent 8b880bbf91
commit 39b645a0ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 103 additions and 0 deletions

View File

@ -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(<div>ProfilerSettingsModal.component</div>)
);
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(
<TableProfilerProvider
isTableDeleted={false}
permissions={mockPermissions}>
<div>Test Children</div>
</TableProfilerProvider>
);
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(
<TableProfilerProvider
isTableDeleted={false}
permissions={mockPermissions}>
<div>Test Children</div>
</TableProfilerProvider>
);
expect(mockGetListTestCase).toHaveBeenCalledTimes(1);
expect(mockGetListTestCase).toHaveBeenCalledWith({
entityLink: 'entityLink',
fields: 'testCaseResult, incidentId',
includeAllTests: true,
limit: 10,
});
});
});

View File

@ -246,6 +246,7 @@ export const TableProfilerProvider = ({
if (fetchTest) {
fetchAllTests();
} else {
setAllTestCases([]);
setIsTestsLoading(false);
}
}, [viewTest, isTourOpen, activeTab, testCasePaging.pageSize]);