mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-27 18:36:08 +00:00
This commit is contained in:
parent
62f4e21d7c
commit
d6fa02d8da
@ -21,6 +21,7 @@ import React, { forwardRef } from 'react';
|
|||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import { ProfilerDashboardType } from '../../../../enums/table.enum';
|
import { ProfilerDashboardType } from '../../../../enums/table.enum';
|
||||||
import { MOCK_TABLE } from '../../../../mocks/TableData.mock';
|
import { MOCK_TABLE } from '../../../../mocks/TableData.mock';
|
||||||
|
import { getListTestDefinitions } from '../../../../rest/testAPI';
|
||||||
import TestCaseForm from './TestCaseForm';
|
import TestCaseForm from './TestCaseForm';
|
||||||
|
|
||||||
const mockProps = {
|
const mockProps = {
|
||||||
@ -74,9 +75,10 @@ const mockTestDefinition = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
const mockUseHistory = { push: jest.fn() };
|
||||||
|
|
||||||
jest.mock('react-router-dom', () => ({
|
jest.mock('react-router-dom', () => ({
|
||||||
useHistory: jest.fn(),
|
useHistory: jest.fn().mockImplementation(() => mockUseHistory),
|
||||||
useParams: jest.fn().mockImplementation(() => mockParams),
|
useParams: jest.fn().mockImplementation(() => mockParams),
|
||||||
}));
|
}));
|
||||||
jest.mock('../../../../utils/DataQuality/DataQualityUtils', () => {
|
jest.mock('../../../../utils/DataQuality/DataQualityUtils', () => {
|
||||||
@ -186,6 +188,19 @@ describe('TestCaseForm', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should call getListTestDefinitions when test type is 'Table'", async () => {
|
||||||
|
await act(async () => {
|
||||||
|
render(<TestCaseForm {...mockProps} />);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(getListTestDefinitions).toHaveBeenCalledWith({
|
||||||
|
entityType: 'TABLE',
|
||||||
|
limit: 50,
|
||||||
|
supportedDataType: undefined,
|
||||||
|
testPlatform: 'OpenMetadata',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// column test case
|
// column test case
|
||||||
it("should show column section when test type is 'Column'", async () => {
|
it("should show column section when test type is 'Column'", async () => {
|
||||||
mockParams.dashboardType = ProfilerDashboardType.COLUMN;
|
mockParams.dashboardType = ProfilerDashboardType.COLUMN;
|
||||||
@ -194,6 +209,44 @@ describe('TestCaseForm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(await screen.findByTestId('column')).toBeInTheDocument();
|
expect(await screen.findByTestId('column')).toBeInTheDocument();
|
||||||
|
expect(getListTestDefinitions).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call getListTestDefinitions when column value change', async () => {
|
||||||
|
mockParams.dashboardType = ProfilerDashboardType.COLUMN;
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
render(<TestCaseForm {...mockProps} />);
|
||||||
|
});
|
||||||
|
|
||||||
|
const column = await findByRole(
|
||||||
|
await screen.findByTestId('column'),
|
||||||
|
'combobox'
|
||||||
|
);
|
||||||
|
await act(async () => {
|
||||||
|
userEvent.click(column);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(column).toBeInTheDocument();
|
||||||
|
|
||||||
|
await waitForElement(() => screen.findByText('last_name'));
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
userEvent.click(await screen.findByText('last_name'));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockUseHistory.push).toHaveBeenCalledWith({
|
||||||
|
search:
|
||||||
|
'activeColumnFqn=sample_data.ecommerce_db.shopify.dim_address.last_name',
|
||||||
|
});
|
||||||
|
expect(getListTestDefinitions).toHaveBeenCalledWith({
|
||||||
|
entityType: 'COLUMN',
|
||||||
|
limit: 50,
|
||||||
|
supportedDataType: 'VARCHAR',
|
||||||
|
testPlatform: 'OpenMetadata',
|
||||||
|
});
|
||||||
|
|
||||||
|
mockParams.dashboardType = ProfilerDashboardType.TABLE;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show compute row count field, if supportsRowLevelPassedFailed is true in test definition', async () => {
|
it('should show compute row count field, if supportsRowLevelPassedFailed is true in test definition', async () => {
|
||||||
|
@ -87,6 +87,7 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
initialValue?.testDefinition
|
initialValue?.testDefinition
|
||||||
);
|
);
|
||||||
const [testCases, setTestCases] = useState<TestCase[]>([]);
|
const [testCases, setTestCases] = useState<TestCase[]>([]);
|
||||||
|
const [currentColumnType, setCurrentColumnType] = useState<string>();
|
||||||
|
|
||||||
const columnName = Form.useWatch('column', form);
|
const columnName = Form.useWatch('column', form);
|
||||||
|
|
||||||
@ -105,17 +106,13 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const fetchAllTestDefinitions = async () => {
|
const fetchAllTestDefinitions = async (columnType?: string) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await getListTestDefinitions({
|
const { data } = await getListTestDefinitions({
|
||||||
limit: PAGE_SIZE_LARGE,
|
limit: PAGE_SIZE_LARGE,
|
||||||
entityType: isColumnFqn ? EntityType.Column : EntityType.Table,
|
entityType: isColumnFqn ? EntityType.Column : EntityType.Table,
|
||||||
testPlatform: TestPlatform.OpenMetadata,
|
testPlatform: TestPlatform.OpenMetadata,
|
||||||
supportedDataType: isColumnFqn
|
supportedDataType: columnType,
|
||||||
? table.columns.find(
|
|
||||||
(column) => column.fullyQualifiedName === columnName
|
|
||||||
)?.dataType
|
|
||||||
: undefined,
|
|
||||||
});
|
});
|
||||||
const updatedData = data.filter((definition) => {
|
const updatedData = data.filter((definition) => {
|
||||||
if (definition.fullyQualifiedName === TABLE_DIFF) {
|
if (definition.fullyQualifiedName === TABLE_DIFF) {
|
||||||
@ -227,6 +224,9 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
const handleValueChange: FormProps['onValuesChange'] = (value) => {
|
const handleValueChange: FormProps['onValuesChange'] = (value) => {
|
||||||
if (value.testTypeId) {
|
if (value.testTypeId) {
|
||||||
setSelectedTestType(value.testTypeId);
|
setSelectedTestType(value.testTypeId);
|
||||||
|
} else if (value.column) {
|
||||||
|
form.setFieldsValue({ testTypeId: undefined });
|
||||||
|
setSelectedTestType(undefined);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -237,10 +237,14 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAllTestDefinitions();
|
|
||||||
const selectedColumn = table.columns.find(
|
const selectedColumn = table.columns.find(
|
||||||
(column) => column.name === columnName
|
(column) => column.name === columnName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (selectedColumn?.dataType !== currentColumnType) {
|
||||||
|
fetchAllTestDefinitions(selectedColumn?.dataType);
|
||||||
|
setCurrentColumnType(selectedColumn?.dataType);
|
||||||
|
}
|
||||||
if (selectedColumn) {
|
if (selectedColumn) {
|
||||||
history.push({
|
history.push({
|
||||||
search: Qs.stringify({
|
search: Qs.stringify({
|
||||||
@ -254,6 +258,9 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
if (isEmpty(testCases)) {
|
if (isEmpty(testCases)) {
|
||||||
fetchAllTestCases();
|
fetchAllTestCases();
|
||||||
}
|
}
|
||||||
|
if (!isColumnFqn) {
|
||||||
|
fetchAllTestDefinitions();
|
||||||
|
}
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
testName: replaceAllSpacialCharWith_(initialValue?.name ?? ''),
|
testName: replaceAllSpacialCharWith_(initialValue?.name ?? ''),
|
||||||
testTypeId: initialValue?.testDefinition,
|
testTypeId: initialValue?.testDefinition,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user