diff --git a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.test.ts b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.test.ts index a39c6fd5c0..c6f448d0e4 100644 --- a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.test.ts +++ b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.test.ts @@ -1,5 +1,6 @@ import { IChangeRequestUpdateStrategy } from 'component/changeRequest/changeRequest.types'; import { IFeatureStrategy } from 'interfaces/strategy'; +import omit from 'lodash.omit'; import { getChangesThatWouldBeOverwritten } from './strategy-change-diff-calculation'; describe('Strategy change conflict detection', () => { @@ -287,4 +288,59 @@ describe('Strategy change conflict detection', () => { expect(result).toBeNull(); }); + + test('It treats `null` and `""` for `title` in the change as equal to `""` in the existing strategy', () => { + const emptyTitleExistingStrategy = { + ...existingStrategy, + title: '', + }; + const undefinedTitleExistingStrategy = omit(existingStrategy, 'title'); + + const { title: _snapshotTitle, ...snapshot } = change.payload.snapshot!; + + const nullTitleInSnapshot = { + ...change, + payload: { + ...change.payload, + snapshot: { + ...snapshot, + title: null, + }, + }, + }; + + const emptyTitleInSnapshot = { + ...change, + payload: { + ...change.payload, + snapshot: { + ...snapshot, + title: '', + }, + }, + }; + + const missingTitleInSnapshot = { + ...change, + payload: { + ...change.payload, + snapshot, + }, + }; + + const cases = [ + undefinedTitleExistingStrategy, + emptyTitleExistingStrategy, + ].flatMap((existing) => + [ + nullTitleInSnapshot, + emptyTitleInSnapshot, + missingTitleInSnapshot, + ].map((changeValue) => + getChangesThatWouldBeOverwritten(existing, changeValue), + ), + ); + + expect(cases.every((result) => result === null)).toBeTruthy(); + }); }); diff --git a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.ts b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.ts index 225566be1a..1cfa553d55 100644 --- a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.ts +++ b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/strategy-change-diff-calculation.ts @@ -55,6 +55,16 @@ export const getChangesThatWouldBeOverwritten = ( newValue: snapshotValue, }; } + } else if (key === 'title') { + // the title can be defined as `null` or + // `undefined`, so we fallback to an empty string + if (hasJsonDiff(snapshotValue ?? '', currentValue ?? '')) { + return { + property: key as keyof IFeatureStrategy, + oldValue: currentValue, + newValue: snapshotValue, + }; + } } else if (hasChanged(snapshotValue, currentValue)) { return { property: key as keyof IFeatureStrategy, diff --git a/frontend/src/component/changeRequest/changeRequest.types.ts b/frontend/src/component/changeRequest/changeRequest.types.ts index e003158a57..79472f965c 100644 --- a/frontend/src/component/changeRequest/changeRequest.types.ts +++ b/frontend/src/component/changeRequest/changeRequest.types.ts @@ -228,7 +228,7 @@ export type ChangeRequestAddStrategy = Pick< export type ChangeRequestEditStrategy = ChangeRequestAddStrategy & { id: string; - snapshot?: IFeatureStrategy; + snapshot?: Omit & { title?: string | null }; }; type ChangeRequestDeleteStrategy = {