mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-09 01:17:06 +02:00
fix: ignore segment order in diff calculation (#8880)
This commit is contained in:
parent
302af67a29
commit
8d1ebf6527
@ -333,3 +333,38 @@ test('Adding strategy always diffs against undefined strategy', async () => {
|
|||||||
await screen.findByText('Setting strategy variants to:');
|
await screen.findByText('Setting strategy variants to:');
|
||||||
await screen.findByText('change_variant');
|
await screen.findByText('change_variant');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Segments order does not matter for diff calculation', async () => {
|
||||||
|
render(
|
||||||
|
<Routes>
|
||||||
|
<Route
|
||||||
|
path='/projects/:projectId'
|
||||||
|
element={
|
||||||
|
<StrategyChange
|
||||||
|
featureName={feature}
|
||||||
|
environmentName={environmentName}
|
||||||
|
projectId={projectId}
|
||||||
|
changeRequestState='Applied'
|
||||||
|
change={{
|
||||||
|
action: 'updateStrategy',
|
||||||
|
id: 1,
|
||||||
|
payload: {
|
||||||
|
...strategy,
|
||||||
|
segments: [3, 2, 1],
|
||||||
|
snapshot: {
|
||||||
|
...strategy,
|
||||||
|
segments: [1, 2, 3],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Routes>,
|
||||||
|
{ route: `/projects/${projectId}` },
|
||||||
|
);
|
||||||
|
|
||||||
|
const viewDiff = await screen.findByText('View Diff');
|
||||||
|
await userEvent.hover(viewDiff);
|
||||||
|
await screen.findByText('(no changes)');
|
||||||
|
});
|
||||||
|
@ -28,6 +28,18 @@ const StyledCodeSection = styled('div')(({ theme }) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const sortSegments = <T extends { segments?: number[] }>(
|
||||||
|
item?: T,
|
||||||
|
): T | undefined => {
|
||||||
|
if (!item || !item.segments) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
segments: [...item.segments].sort((a, b) => a - b),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const StrategyDiff: FC<{
|
export const StrategyDiff: FC<{
|
||||||
change:
|
change:
|
||||||
| IChangeRequestAddStrategy
|
| IChangeRequestAddStrategy
|
||||||
@ -38,12 +50,15 @@ export const StrategyDiff: FC<{
|
|||||||
const changeRequestStrategy =
|
const changeRequestStrategy =
|
||||||
change.action === 'deleteStrategy' ? undefined : change.payload;
|
change.action === 'deleteStrategy' ? undefined : change.payload;
|
||||||
|
|
||||||
|
const sortedCurrentStrategy = sortSegments(currentStrategy);
|
||||||
|
const sortedChangeRequestStrategy = sortSegments(changeRequestStrategy);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledCodeSection>
|
<StyledCodeSection>
|
||||||
<EventDiff
|
<EventDiff
|
||||||
entry={{
|
entry={{
|
||||||
preData: omit(currentStrategy, 'sortOrder'),
|
preData: omit(sortedCurrentStrategy, 'sortOrder'),
|
||||||
data: omit(changeRequestStrategy, 'snapshot'),
|
data: omit(sortedChangeRequestStrategy, 'snapshot'),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</StyledCodeSection>
|
</StyledCodeSection>
|
||||||
|
Loading…
Reference in New Issue
Block a user