fix: Add support for editing "Compute row coun" from parameter screen #22139 (#22158)

* fix: Add support for editing "Compute row coun" from parameter screen #22139

* fixed failing test
This commit is contained in:
Shailesh Parmar 2025-07-17 20:01:07 +05:30 committed by GitHub
parent 58fd1eb592
commit 5188673b5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 599 additions and 322 deletions

View File

@ -24,6 +24,7 @@ import {
MOCK_TEST_CASE,
MOCK_TEST_DEFINITION_COLUMN_VALUES_TO_MATCH_REGEX,
} from '../../../mocks/TestSuite.mock';
import { getTestDefinitionById } from '../../../rest/testAPI';
import { EditTestCaseModalProps } from './AddDataQualityTest.interface';
import EditTestCaseModal from './EditTestCaseModal';
@ -274,6 +275,132 @@ describe('EditTestCaseModal Component', () => {
).not.toBeInTheDocument();
});
it('should render compute row count field in parameter-only mode when test definition supports it', async () => {
// Mock a test definition that supports row-level passed/failed counting
const mockTestDefinitionWithRowSupport = {
...MOCK_TEST_DEFINITION_COLUMN_VALUES_TO_MATCH_REGEX,
supportsRowLevelPassedFailed: true,
};
// Mock the API to return the test definition with row support
(getTestDefinitionById as jest.Mock).mockResolvedValue(
mockTestDefinitionWithRowSupport
);
const parameterOnlyProps = {
...mockProps,
showOnlyParameter: true,
};
render(<EditTestCaseModal {...parameterOnlyProps} />);
// Wait for the form to load
await waitFor(() => {
expect(screen.getByTestId('edit-test-form')).toBeInTheDocument();
});
// Should render compute row count field even in parameter-only mode
expect(
screen.getByTestId('compute-passed-failed-row-count')
).toBeInTheDocument();
});
it('should not render compute row count field when test definition does not support it', async () => {
// Mock a test definition that does not support row-level passed/failed counting
const mockTestDefinitionWithoutRowSupport = {
...MOCK_TEST_DEFINITION_COLUMN_VALUES_TO_MATCH_REGEX,
supportsRowLevelPassedFailed: false,
};
// Mock the API to return the test definition without row support
(getTestDefinitionById as jest.Mock).mockResolvedValue(
mockTestDefinitionWithoutRowSupport
);
const parameterOnlyProps = {
...mockProps,
showOnlyParameter: true,
};
render(<EditTestCaseModal {...parameterOnlyProps} />);
// Wait for the form to load
await waitFor(() => {
expect(screen.getByTestId('edit-test-form')).toBeInTheDocument();
});
// Should not render compute row count field when not supported
expect(
screen.queryByTestId('compute-passed-failed-row-count')
).not.toBeInTheDocument();
});
it('should render compute row count field in full mode when test definition supports it', async () => {
// Mock a test definition that supports row-level passed/failed counting
const mockTestDefinitionWithRowSupport = {
...MOCK_TEST_DEFINITION_COLUMN_VALUES_TO_MATCH_REGEX,
supportsRowLevelPassedFailed: true,
};
// Mock the API to return the test definition with row support
(getTestDefinitionById as jest.Mock).mockResolvedValue(
mockTestDefinitionWithRowSupport
);
render(<EditTestCaseModal {...mockProps} />);
// Wait for the form to load
await waitFor(() => {
expect(screen.getByTestId('edit-test-form')).toBeInTheDocument();
});
// Should render compute row count field in full mode
expect(
screen.getByTestId('compute-passed-failed-row-count')
).toBeInTheDocument();
});
it('should preserve compute row count value when updating in parameter-only mode', async () => {
// Mock a test definition that supports row-level passed/failed counting
const mockTestDefinitionWithRowSupport = {
...MOCK_TEST_DEFINITION_COLUMN_VALUES_TO_MATCH_REGEX,
supportsRowLevelPassedFailed: true,
};
// Mock the API to return the test definition with row support
(getTestDefinitionById as jest.Mock).mockResolvedValue(
mockTestDefinitionWithRowSupport
);
const testCaseWithComputeRowCount = {
...MOCK_TEST_CASE[0],
computePassedFailedRowCount: true,
};
const parameterOnlyProps = {
...mockProps,
testCase: testCaseWithComputeRowCount,
showOnlyParameter: true,
};
render(<EditTestCaseModal {...parameterOnlyProps} />);
// Wait for the form to load
await waitFor(() => {
expect(screen.getByTestId('edit-test-form')).toBeInTheDocument();
});
// Submit the form
const submitBtn = await screen.findByText('label.save');
await act(async () => {
fireEvent.click(submitBtn);
});
// Verify that onUpdate was called (indicating form submission with compute row count preserved)
expect(mockProps.onUpdate).toHaveBeenCalled();
});
it('should include tags and glossary terms in form submission', async () => {
render(<EditTestCaseModal {...mockProps} />);

View File

@ -403,14 +403,10 @@ const EditTestCaseModal: React.FC<EditTestCaseModalProps> = ({
}
</Form.Item>
{!showOnlyParameter && (
<>
{generateFormFields(formField)}
{isComputeRowCountFieldVisible
? generateFormFields(formFields)
: null}
</>
)}
{!showOnlyParameter && <>{generateFormFields(formField)}</>}
{isComputeRowCountFieldVisible
? generateFormFields(formFields)
: null}
</Form>
)}
</EntityAttachmentProvider>

View File

@ -15,7 +15,7 @@ import Icon from '@ant-design/icons/lib/components/Icon';
import { Col, Divider, Row, Space, Typography } from 'antd';
import { AxiosError } from 'axios';
import { compare } from 'fast-json-patch';
import { isEmpty, isUndefined, startCase } from 'lodash';
import { isEmpty, isUndefined, startCase, toString } from 'lodash';
import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { CSMode } from '../../../../enums/codemirror.enum';
@ -35,6 +35,7 @@ import {
import { useTestCaseStore } from '../../../../pages/IncidentManager/IncidentManagerDetailPage/useTestCase.store';
import { updateTestCaseById } from '../../../../rest/testAPI';
import {
getComputeRowCountDiffDisplay,
getEntityVersionByField,
getEntityVersionTags,
getParameterValueDiffDisplay,
@ -210,6 +211,21 @@ const TestCaseResultTab = () => {
)
: getTagsWithoutTier(testCaseData?.tags ?? []);
const computeRowCountDisplay = useMemo(() => {
if (isVersionPage) {
return getComputeRowCountDiffDisplay(
testCaseData?.changeDescription as ChangeDescription,
testCaseData?.computePassedFailedRowCount
);
}
return toString(testCaseData?.computePassedFailedRowCount);
}, [
testCaseData?.changeDescription,
testCaseData?.computePassedFailedRowCount,
isVersionPage,
]);
const testCaseParams = useMemo(() => {
if (isVersionPage) {
return getParameterValueDiffDisplay(
@ -298,6 +314,29 @@ const TestCaseResultTab = () => {
{testCaseParams}
</Space>
</Col>
{!isUndefined(testCaseData?.computePassedFailedRowCount) && (
<Col data-testid="computed-row-count-container" span={24}>
<Space direction="vertical" size="small">
<Space align="center" size={8}>
<Typography.Text className="right-panel-label">
{t('label.compute-row-count')}
</Typography.Text>
{hasEditPermission && !isVersionPage && (
<EditIconButton
newLook
data-testid="edit-compute-row-count-icon"
size="small"
title={t('label.edit-entity', {
entity: t('label.compute-row-count'),
})}
onClick={() => setIsParameterEdit(true)}
/>
)}
</Space>
<Typography.Text>{computeRowCountDisplay}</Typography.Text>
</Space>
</Col>
)}
{!isUndefined(withSqlParams) && !isVersionPage ? (
<Col>

View File

@ -21,8 +21,14 @@ import {
DataType as TableDataType,
} from '../generated/entity/data/table';
import { DataTypeTopic, Field } from '../generated/entity/data/topic';
import { FieldChange } from '../generated/entity/services/databaseService';
import { getStringEntityDiff } from './EntityVersionUtils';
import {
ChangeDescription,
FieldChange,
} from '../generated/entity/services/databaseService';
import {
getComputeRowCountDiffDisplay,
getStringEntityDiff,
} from './EntityVersionUtils';
// Mock data for testing
const createMockTableColumn = (
@ -81,346 +87,419 @@ const createMockEntityDiff = (
updated,
});
describe('getStringEntityDiff', () => {
describe('TableColumn entity', () => {
it('should update displayName with diff when entity name matches', () => {
const oldDisplayName = 'Old Display Name';
const newDisplayName = 'New Display Name';
const entityName = 'testColumn';
describe('EntityVersionUtils', () => {
describe('getStringEntityDiff', () => {
describe('TableColumn entity', () => {
it('should update displayName with diff when entity name matches', () => {
const oldDisplayName = 'Old Display Name';
const newDisplayName = 'New Display Name';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const columns = [
createMockTableColumn(entityName, oldDisplayName),
createMockTableColumn('otherColumn', 'Other Display Name'),
];
const columns = [
createMockTableColumn(entityName, oldDisplayName),
createMockTableColumn('otherColumn', 'Other Display Name'),
];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
expect(result).toHaveLength(2);
expect(result[0].displayName).toContain('diff-removed');
expect(result[0].displayName).toContain('diff-added');
expect(result[1].displayName).toBe('Other Display Name');
expect(result).toHaveLength(2);
expect(result[0].displayName).toContain('diff-removed');
expect(result[0].displayName).toContain('diff-added');
expect(result[1].displayName).toBe('Other Display Name');
});
it('should update description field when DESCRIPTION field is passed', () => {
const oldDescription = 'Old description';
const newDescription = 'New description';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('description', oldDescription, newDescription)
);
const columns = [
{ ...createMockTableColumn(entityName), description: oldDescription },
createMockTableColumn('otherColumn', 'Other Display Name'),
];
const result = getStringEntityDiff(
entityDiff,
EntityField.DESCRIPTION,
entityName,
columns
);
expect(result).toHaveLength(2);
expect(result[0].description).toContain('diff-removed');
expect(result[0].description).toContain('diff-added');
expect(result[1].description).toBeUndefined();
});
it('should handle nested children entities', () => {
const oldDisplayName = 'Old Child Display Name';
const newDisplayName = 'New Child Display Name';
const childEntityName = 'childColumn';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const childColumn = createMockTableColumn(
childEntityName,
oldDisplayName
);
const parentColumn = {
...createMockTableColumn('parentColumn', 'Parent Display Name'),
children: [childColumn],
};
const columns = [parentColumn];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
childEntityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].children?.[0].displayName).toContain('diff-removed');
expect(result[0].children?.[0].displayName).toContain('diff-added');
expect(result[0].displayName).toBe('Parent Display Name');
});
it('should not modify entities when name does not match', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', 'Old Name', 'New Name')
);
const columns = [
createMockTableColumn('differentColumn', 'Original Display Name'),
];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
'nonExistentColumn',
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toBe('Original Display Name');
});
});
it('should update description field when DESCRIPTION field is passed', () => {
const oldDescription = 'Old description';
const newDescription = 'New description';
const entityName = 'testColumn';
describe('ContainerColumn entity', () => {
it('should update displayName for ContainerColumn', () => {
const oldDisplayName = 'Old Container Display Name';
const newDisplayName = 'New Container Display Name';
const entityName = 'containerColumn';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('description', oldDescription, newDescription)
);
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const columns = [
{ ...createMockTableColumn(entityName), description: oldDescription },
createMockTableColumn('otherColumn', 'Other Display Name'),
];
const columns = [createMockContainerColumn(entityName, oldDisplayName)];
const result = getStringEntityDiff(
entityDiff,
EntityField.DESCRIPTION,
entityName,
columns
);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
expect(result).toHaveLength(2);
expect(result[0].description).toContain('diff-removed');
expect(result[0].description).toContain('diff-added');
expect(result[1].description).toBeUndefined();
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-removed');
expect(result[0].displayName).toContain('diff-added');
});
});
it('should handle nested children entities', () => {
const oldDisplayName = 'Old Child Display Name';
const newDisplayName = 'New Child Display Name';
const childEntityName = 'childColumn';
describe('Field entity', () => {
it('should update displayName for Field', () => {
const oldDisplayName = 'Old Field Display Name';
const newDisplayName = 'New Field Display Name';
const entityName = 'fieldName';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const childColumn = createMockTableColumn(
childEntityName,
oldDisplayName
);
const parentColumn = {
...createMockTableColumn('parentColumn', 'Parent Display Name'),
children: [childColumn],
const fields = [createMockField(entityName, oldDisplayName)];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
fields
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-removed');
expect(result[0].displayName).toContain('diff-added');
});
});
describe('Edge cases', () => {
it('should handle empty entity list', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', 'Old', 'New')
);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
'anyEntity',
[]
);
expect(result).toHaveLength(0);
});
it('should handle undefined changedEntityName', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', 'Old', 'New')
);
const columns = [
createMockTableColumn('testColumn', 'Test Display Name'),
];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
undefined,
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toBe('Test Display Name');
});
it('should handle empty old and new values', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', '', '')
);
const columns = [
createMockTableColumn('testColumn', 'Existing Display Name'),
];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
'testColumn',
columns
);
expect(result).toHaveLength(1);
// Should preserve the existing display name when both old and new are empty
expect(result[0].displayName).toBe('Existing Display Name');
});
it('should handle added field change', () => {
const newDisplayName = 'New Added Display Name';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
createMockFieldChange('displayName', '', newDisplayName),
undefined,
undefined
);
const columns = [createMockTableColumn(entityName, '')];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-added');
});
it('should handle deleted field change', () => {
const oldDisplayName = 'Deleted Display Name';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
undefined,
createMockFieldChange('displayName', oldDisplayName, ''),
undefined
);
const columns = [createMockTableColumn(entityName, oldDisplayName)];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-removed');
});
});
describe('Different EntityField values', () => {
it('should handle DATA_TYPE_DISPLAY field', () => {
const oldDataTypeDisplay = 'VARCHAR(255)';
const newDataTypeDisplay = 'TEXT';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange(
EntityField.DATA_TYPE_DISPLAY,
oldDataTypeDisplay,
newDataTypeDisplay
)
);
const columns = [
{
...createMockTableColumn(entityName),
dataTypeDisplay: oldDataTypeDisplay,
},
];
const result = getStringEntityDiff(
entityDiff,
EntityField.DATA_TYPE_DISPLAY,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].dataTypeDisplay).toContain('diff-removed');
expect(result[0].dataTypeDisplay).toContain('diff-added');
});
it('should handle NAME field', () => {
const oldName = 'oldColumnName';
const newName = 'newColumnName';
const entityName = 'oldColumnName';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('name', oldName, newName)
);
const columns = [
{ ...createMockTableColumn(entityName), name: oldName },
];
const result = getStringEntityDiff(
entityDiff,
EntityField.NAME,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].name).toContain('diff-removed');
expect(result[0].name).toContain('diff-added');
});
});
});
describe('getComputeRowCountDiffDisplay', () => {
it('should return fallback value as string when no diff exists', () => {
const changeDescription: ChangeDescription = {
fieldsAdded: [],
fieldsDeleted: [],
fieldsUpdated: [],
};
const columns = [parentColumn];
const result = getComputeRowCountDiffDisplay(changeDescription, true);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
childEntityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].children?.[0].displayName).toContain('diff-removed');
expect(result[0].children?.[0].displayName).toContain('diff-added');
expect(result[0].displayName).toBe('Parent Display Name');
expect(result).toBe('true');
});
it('should not modify entities when name does not match', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', 'Old Name', 'New Name')
);
it('should return diff elements when field is updated', () => {
const changeDescription: ChangeDescription = {
fieldsAdded: [],
fieldsDeleted: [],
fieldsUpdated: [
{
name: 'computePassedFailedRowCount',
oldValue: 'false',
newValue: 'true',
},
],
};
const columns = [
createMockTableColumn('differentColumn', 'Original Display Name'),
];
const result = getComputeRowCountDiffDisplay(changeDescription, false);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
'nonExistentColumn',
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toBe('Original Display Name');
});
});
describe('ContainerColumn entity', () => {
it('should update displayName for ContainerColumn', () => {
const oldDisplayName = 'Old Container Display Name';
const newDisplayName = 'New Container Display Name';
const entityName = 'containerColumn';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const columns = [createMockContainerColumn(entityName, oldDisplayName)];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-removed');
expect(result[0].displayName).toContain('diff-added');
});
});
describe('Field entity', () => {
it('should update displayName for Field', () => {
const oldDisplayName = 'Old Field Display Name';
const newDisplayName = 'New Field Display Name';
const entityName = 'fieldName';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', oldDisplayName, newDisplayName)
);
const fields = [createMockField(entityName, oldDisplayName)];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
fields
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-removed');
expect(result[0].displayName).toContain('diff-added');
});
});
describe('Edge cases', () => {
it('should handle empty entity list', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', 'Old', 'New')
);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
'anyEntity',
[]
);
expect(result).toHaveLength(0);
// Should return an array of React elements for diff display
expect(Array.isArray(result)).toBe(true);
});
it('should handle undefined changedEntityName', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', 'Old', 'New')
);
it('should return added diff element when field is added', () => {
const changeDescription: ChangeDescription = {
fieldsAdded: [
{
name: 'computePassedFailedRowCount',
newValue: 'true',
},
],
fieldsDeleted: [],
fieldsUpdated: [],
};
const columns = [
createMockTableColumn('testColumn', 'Test Display Name'),
];
const result = getComputeRowCountDiffDisplay(changeDescription, false);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
undefined,
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toBe('Test Display Name');
// Should return a React element for added diff
expect(result).toBeDefined();
});
it('should handle empty old and new values', () => {
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('displayName', '', '')
);
it('should return removed diff element when field is deleted', () => {
const changeDescription: ChangeDescription = {
fieldsAdded: [],
fieldsDeleted: [
{
name: 'computePassedFailedRowCount',
oldValue: 'true',
},
],
fieldsUpdated: [],
};
const columns = [
createMockTableColumn('testColumn', 'Existing Display Name'),
];
const result = getComputeRowCountDiffDisplay(changeDescription, false);
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
'testColumn',
columns
);
expect(result).toHaveLength(1);
// Should preserve the existing display name when both old and new are empty
expect(result[0].displayName).toBe('Existing Display Name');
});
it('should handle added field change', () => {
const newDisplayName = 'New Added Display Name';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
createMockFieldChange('displayName', '', newDisplayName),
undefined,
undefined
);
const columns = [createMockTableColumn(entityName, '')];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-added');
});
it('should handle deleted field change', () => {
const oldDisplayName = 'Deleted Display Name';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
undefined,
createMockFieldChange('displayName', oldDisplayName, ''),
undefined
);
const columns = [createMockTableColumn(entityName, oldDisplayName)];
const result = getStringEntityDiff(
entityDiff,
EntityField.DISPLAYNAME,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].displayName).toContain('diff-removed');
});
});
describe('Different EntityField values', () => {
it('should handle DATA_TYPE_DISPLAY field', () => {
const oldDataTypeDisplay = 'VARCHAR(255)';
const newDataTypeDisplay = 'TEXT';
const entityName = 'testColumn';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange(
EntityField.DATA_TYPE_DISPLAY,
oldDataTypeDisplay,
newDataTypeDisplay
)
);
const columns = [
{
...createMockTableColumn(entityName),
dataTypeDisplay: oldDataTypeDisplay,
},
];
const result = getStringEntityDiff(
entityDiff,
EntityField.DATA_TYPE_DISPLAY,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].dataTypeDisplay).toContain('diff-removed');
expect(result[0].dataTypeDisplay).toContain('diff-added');
});
it('should handle NAME field', () => {
const oldName = 'oldColumnName';
const newName = 'newColumnName';
const entityName = 'oldColumnName';
const entityDiff = createMockEntityDiff(
undefined,
undefined,
createMockFieldChange('name', oldName, newName)
);
const columns = [{ ...createMockTableColumn(entityName), name: oldName }];
const result = getStringEntityDiff(
entityDiff,
EntityField.NAME,
entityName,
columns
);
expect(result).toHaveLength(1);
expect(result[0].name).toContain('diff-removed');
expect(result[0].name).toContain('diff-added');
// Should return a React element for removed diff
expect(result).toBeDefined();
});
});
});

View File

@ -1245,6 +1245,42 @@ export const getParameterValueDiffDisplay = (
);
};
export const getComputeRowCountDiffDisplay = (
changeDescription: ChangeDescription,
fallbackValue?: boolean
): React.ReactNode => {
const fieldDiff = getDiffByFieldName(
'computePassedFailedRowCount',
changeDescription,
true
);
const oldValue = getChangedEntityOldValue(fieldDiff);
const newValue = getChangedEntityNewValue(fieldDiff);
const isOldValueUndefined = isUndefined(oldValue);
const isNewValueUndefined = isUndefined(newValue);
// If there's no diff, return the fallback value as normal text
if (isOldValueUndefined && isNewValueUndefined) {
return toString(fallbackValue);
}
// If there's a diff, show the diff styling
if (!isOldValueUndefined && !isNewValueUndefined) {
// Field was updated
return getTextDiffElements(toString(oldValue), toString(newValue));
} else if (isOldValueUndefined && !isNewValueUndefined) {
// Field was added
return getAddedDiffElement(toString(newValue));
} else if (!isOldValueUndefined && isNewValueUndefined) {
// Field was deleted
return getRemovedDiffElement(toString(oldValue));
}
// Fallback
return toString(fallbackValue);
};
export const getOwnerVersionLabel = (
entity: {
[TabSpecificField.OWNERS]?: EntityReference[];