mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: diff no changes (#4480)
This commit is contained in:
parent
81586074d0
commit
c1fe43fe64
@ -27,15 +27,15 @@ export const SegmentDiff: FC<{
|
||||
change: IChangeRequestUpdateSegment | IChangeRequestDeleteSegment;
|
||||
currentSegment?: ISegment;
|
||||
}> = ({ change, currentSegment }) => {
|
||||
const changeRequestStrategy =
|
||||
const changeRequestSegment =
|
||||
change.action === 'deleteSegment' ? undefined : change.payload;
|
||||
|
||||
return (
|
||||
<StyledCodeSection>
|
||||
<EventDiff
|
||||
entry={{
|
||||
preData: omit(currentSegment, 'sortOrder'),
|
||||
data: changeRequestStrategy,
|
||||
preData: omit(currentSegment, ['createdAt', 'createdBy']),
|
||||
data: changeRequestSegment,
|
||||
}}
|
||||
/>
|
||||
</StyledCodeSection>
|
||||
|
49
frontend/src/component/events/EventDiff/EventDiff.test.tsx
Normal file
49
frontend/src/component/events/EventDiff/EventDiff.test.tsx
Normal file
@ -0,0 +1,49 @@
|
||||
import { render } from 'utils/testRenderer';
|
||||
import React from 'react';
|
||||
import { screen } from '@testing-library/react';
|
||||
import EventDiff from './EventDiff';
|
||||
|
||||
test('Show no changes', async () => {
|
||||
render(<EventDiff entry={{ preData: [], data: [] }} />);
|
||||
|
||||
expect(screen.getByText('(no changes)')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Show new data added diff', async () => {
|
||||
render(<EventDiff entry={{ preData: {}, data: { segments: [] } }} />);
|
||||
|
||||
expect(screen.getByText('+ segments: []')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Show new data removed diff', async () => {
|
||||
render(<EventDiff entry={{ preData: { segments: [] }, data: {} }} />);
|
||||
|
||||
expect(screen.getByText('- segments (deleted)')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Show new data changes diff', async () => {
|
||||
render(
|
||||
<EventDiff
|
||||
entry={{ preData: { segments: 'a' }, data: { segments: 'b' } }}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('- segments: "a"')).toBeInTheDocument();
|
||||
expect(screen.getByText('+ segments: "b"')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Show new data only', async () => {
|
||||
render(
|
||||
<EventDiff entry={{ preData: undefined, data: { segments: [] } }} />
|
||||
);
|
||||
|
||||
expect(screen.getByText('{ "segments": [] }')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Show old data only', async () => {
|
||||
render(
|
||||
<EventDiff entry={{ preData: { segments: [] }, data: undefined }} />
|
||||
);
|
||||
|
||||
expect(screen.getByText('{ "segments": [] }')).toBeInTheDocument();
|
||||
});
|
@ -96,14 +96,14 @@ const EventDiff = ({
|
||||
};
|
||||
};
|
||||
|
||||
let changes;
|
||||
let changes: any[] = [];
|
||||
|
||||
if (diffs) {
|
||||
changes = diffs
|
||||
.map(buildDiff)
|
||||
.sort(sort)
|
||||
.map(({ value }) => value);
|
||||
} else {
|
||||
} else if (entry.data == null || entry.preData == null) {
|
||||
// Just show the data if there is no diff yet.
|
||||
const data = entry.data || entry.preData;
|
||||
changes = [
|
||||
|
Loading…
Reference in New Issue
Block a user