diff --git a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.test.ts b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.test.ts index 9cd1b26709..b15400e129 100644 --- a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.test.ts +++ b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.test.ts @@ -99,6 +99,24 @@ describe('Strategy change conflict detection', () => { expect(resultMissing).toBeNull(); }); + test('It sorts segments before comparing (because their order is irrelevant)', () => { + const result = getStrategyChangesThatWouldBeOverwritten( + { + ...existingStrategy, + segments: [25, 26, 1], + }, + { + ...change, + payload: { + ...change.payload, + segments: [26, 1, 25], + }, + }, + ); + + expect(result).toBeNull(); + }); + test('It treats `undefined` or missing strategy variants in old config and change as equal to `[]`', () => { const undefinedVariantsExistingStrategy = { ...existingStrategy, diff --git a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.ts b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.ts index 1e8c2d9b27..3e5472928b 100644 --- a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.ts +++ b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ChangeOverwriteWarning/strategy-change-diff-calculation.ts @@ -142,9 +142,31 @@ export function getStrategyChangesThatWouldBeOverwritten( change: IChangeRequestUpdateStrategy, ): ChangesThatWouldBeOverwritten | null { const fallbacks = { segments: [], variants: [], title: '' }; + + const withSortedSegments = (() => { + if (!(change.payload.segments && currentStrategyConfig?.segments)) { + return { current: currentStrategyConfig, change: change }; + } + + const changeCopy = { + ...change, + payload: { + ...change.payload, + segments: [...change.payload.segments].sort(), + }, + }; + + const currentCopy = { + ...currentStrategyConfig, + segments: [...currentStrategyConfig.segments].sort(), + }; + + return { current: currentCopy, change: changeCopy }; + })(); + return getChangesThatWouldBeOverwritten( - omit(currentStrategyConfig, 'strategyName'), - change, + omit(withSortedSegments.current, 'strategyName'), + withSortedSegments.change, fallbacks, ); }