fix(frontend): Table diff not working when row count does not change

This commit is contained in:
2025-12-30 19:20:08 +01:00
parent 6ef6f74c4e
commit 99cecdbcb2
2 changed files with 34 additions and 6 deletions

View File

@@ -627,6 +627,31 @@ describe('formDiff', () => {
expect(diff.changedAnswers[0].tableDiff!.rows[1].currentValues['Name']).toBe('Janet')
})
it('should detect modified rows when row count is the same', () => {
const current = createForm([
createFormElement('table_1', 'Employees', 'TABLE', [
createOption('["John", "Janet"]', 'Name'),
createOption('["Developer", "Designer"]', 'Role')
])
])
const version = createSnapshot([
createSnapshotElement('table_1', 'Employees', 'TABLE', [
createOption('["John", "Jane"]', 'Name'),
createOption('["Developer", "Designer"]', 'Role')
])
])
const diff = compareApplicationFormValues(current, version)
expect(diff.changedAnswers).toHaveLength(1)
expect(diff.changedAnswers[0].tableDiff).toBeDefined()
expect(diff.changedAnswers[0].tableDiff!.addedCount).toBe(0)
expect(diff.changedAnswers[0].tableDiff!.modifiedCount).toBe(1)
expect(diff.changedAnswers[0].tableDiff!.rows[1].changeType).toBe('modified')
expect(diff.changedAnswers[0].tableDiff!.rows[1].previousValues['Name']).toBe('Jane')
expect(diff.changedAnswers[0].tableDiff!.rows[1].currentValues['Name']).toBe('Janet')
})
it('should detect mixed changes (added, removed, modified)', () => {
const current = createForm([
createFormElement('table_1', 'Employees', 'TABLE', [
@@ -673,8 +698,6 @@ describe('formDiff', () => {
})
it('should handle boolean values in table cells', () => {
// Note: The diff algorithm compares by label first ("N Zeilen").
// If row count is the same, no change is detected at the label level.
// To detect boolean cell changes, we need a row count change too.
const current = createForm([
createFormElement('table_1', 'Settings', 'TABLE', [
@@ -697,8 +720,6 @@ describe('formDiff', () => {
})
it('should handle array values in table cells', () => {
// Note: The diff algorithm compares by label first ("N Zeilen").
// To detect array cell changes, we need a row count change too.
const current = createForm([
createFormElement('table_1', 'Projects', 'TABLE', [
createOption('["Project A", "Project B"]', 'Name'),