mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-24 08:58:06 +00:00
parent
9817dfca89
commit
dec5f0dbff
@ -36,6 +36,7 @@ import {
|
|||||||
TestDataType,
|
TestDataType,
|
||||||
TestDefinition,
|
TestDefinition,
|
||||||
} from '../../../generated/tests/testDefinition';
|
} from '../../../generated/tests/testDefinition';
|
||||||
|
import { getNameFromFQN } from '../../../utils/CommonUtils';
|
||||||
import { generateEntityLink } from '../../../utils/TableUtils';
|
import { generateEntityLink } from '../../../utils/TableUtils';
|
||||||
import { showErrorToast } from '../../../utils/ToastUtils';
|
import { showErrorToast } from '../../../utils/ToastUtils';
|
||||||
import RichTextEditor from '../../common/rich-text-editor/RichTextEditor';
|
import RichTextEditor from '../../common/rich-text-editor/RichTextEditor';
|
||||||
@ -55,10 +56,10 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
const [selectedTestType, setSelectedTestType] = useState<string | undefined>(
|
const [selectedTestType, setSelectedTestType] = useState<string | undefined>(
|
||||||
initialValue?.testDefinition?.id
|
initialValue?.testDefinition?.id
|
||||||
);
|
);
|
||||||
const [testCases, setTestCases] = useState<{ [key: string]: TestCase }>({});
|
const [testCases, setTestCases] = useState<TestCase[]>([]);
|
||||||
const [sqlQuery, setSqlQuery] = useState({
|
const [sqlQuery, setSqlQuery] = useState({
|
||||||
name: 'sqlExpression',
|
name: 'sqlExpression',
|
||||||
value: initialValue?.parameterValues?.[0].value || '',
|
value: initialValue?.parameterValues?.[0]?.value || '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const fetchAllTestDefinitions = async () => {
|
const fetchAllTestDefinitions = async () => {
|
||||||
@ -80,10 +81,8 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
limit: API_RES_MAX_SIZE,
|
limit: API_RES_MAX_SIZE,
|
||||||
entityLink: generateEntityLink(entityTypeFQN, isColumnFqn),
|
entityLink: generateEntityLink(entityTypeFQN, isColumnFqn),
|
||||||
});
|
});
|
||||||
const modifiedData = data.reduce((acc, curr) => {
|
|
||||||
return { ...acc, [curr.testDefinition.fullyQualifiedName || '']: curr };
|
setTestCases(data);
|
||||||
}, {});
|
|
||||||
setTestCases(modifiedData);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showErrorToast(error as AxiosError);
|
showErrorToast(error as AxiosError);
|
||||||
}
|
}
|
||||||
@ -178,15 +177,33 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
[curr.name || '']:
|
[curr.name || '']:
|
||||||
getSelectedTestDefinition()?.parameterDefinition?.[0].dataType ===
|
getSelectedTestDefinition()?.parameterDefinition?.[0].dataType ===
|
||||||
TestDataType.Array
|
TestDataType.Array
|
||||||
? (JSON.parse(curr.value || '[]') as string[]).map((val) => ({
|
? (JSON.parse(curr?.value || '[]') as string[]).map((val) => ({
|
||||||
value: val,
|
value: val,
|
||||||
}))
|
}))
|
||||||
: curr.value,
|
: curr?.value,
|
||||||
}),
|
}),
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleValueChange: FormProps['onValuesChange'] = (value) => {
|
||||||
|
if (value.testTypeId) {
|
||||||
|
const testType = testDefinitions.find(
|
||||||
|
(test) => test.id === value.testTypeId
|
||||||
|
);
|
||||||
|
setSelectedTestType(value.testTypeId);
|
||||||
|
const testCount = testCases.filter((test) =>
|
||||||
|
test.name.includes(`${getNameFromFQN(entityTypeFQN)}_${testType?.name}`)
|
||||||
|
);
|
||||||
|
// generating dynamic unique name based on entity_testCase_number
|
||||||
|
form.setFieldsValue({
|
||||||
|
testName: `${getNameFromFQN(entityTypeFQN)}_${testType?.name}${
|
||||||
|
testCount.length ? `_${testCount.length}` : ''
|
||||||
|
}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (testDefinitions.length === 0) {
|
if (testDefinitions.length === 0) {
|
||||||
fetchAllTestDefinitions();
|
fetchAllTestDefinitions();
|
||||||
@ -194,24 +211,22 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
if (isEmpty(testCases)) {
|
if (isEmpty(testCases)) {
|
||||||
fetchAllTestCases();
|
fetchAllTestCases();
|
||||||
}
|
}
|
||||||
|
form.setFieldsValue({
|
||||||
|
testName: initialValue?.name ?? getNameFromFQN(entityTypeFQN),
|
||||||
|
testTypeId: initialValue?.testDefinition?.id,
|
||||||
|
params: initialValue?.parameterValues?.length
|
||||||
|
? getParamsValue()
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
initialValues={{
|
|
||||||
testName: initialValue?.name,
|
|
||||||
testTypeId: initialValue?.testDefinition?.id,
|
|
||||||
params: getParamsValue(),
|
|
||||||
}}
|
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
name="tableTestForm"
|
name="tableTestForm"
|
||||||
onFinish={handleFormSubmit}
|
onFinish={handleFormSubmit}
|
||||||
onValuesChange={(value) => {
|
onValuesChange={handleValueChange}>
|
||||||
if (value.testTypeId) {
|
|
||||||
setSelectedTestType(value.testTypeId);
|
|
||||||
}
|
|
||||||
}}>
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="Name:"
|
label="Name:"
|
||||||
name="testName"
|
name="testName"
|
||||||
@ -222,9 +237,7 @@ const TestCaseForm: React.FC<TestCaseFormProps> = ({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
validator: (_, value) => {
|
validator: (_, value) => {
|
||||||
if (
|
if (testCases.some((test) => test.name === value)) {
|
||||||
Object.values(testCases).some((suite) => suite.name === value)
|
|
||||||
) {
|
|
||||||
return Promise.reject('Name already exist!');
|
return Promise.reject('Name already exist!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user