Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display potential conflicts in existing change requests (#5521)
This update displays schedule conflicts in active change requests (any CR that isn't applied, canceled, or rejected). ![image](https://github.com/Unleash/unleash/assets/17786332/181c6c0a-f5de-4eed-9093-ac0109e1e8f3)
- Loading branch information
1 parent
a9363ef
commit a0a1541
Showing
3 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
frontend/src/component/changeRequest/ChangeRequest/Changes/Change/FeatureChange.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import React from 'react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { screen } from '@testing-library/react'; | ||
import { FeatureChange } from './FeatureChange'; | ||
import { | ||
ChangeRequestState, | ||
IChangeRequestFeature, | ||
IFeatureChange, | ||
} from 'component/changeRequest/changeRequest.types'; | ||
|
||
describe('Schedule conflicts', () => { | ||
const change = { | ||
id: 15, | ||
action: 'deleteStrategy' as const, | ||
payload: { | ||
id: 'b3ac8595-8ad3-419e-aa18-4d82f2b6bc4c', | ||
name: 'flexibleRollout', | ||
}, | ||
createdAt: new Date(), | ||
createdBy: { | ||
id: 1, | ||
username: 'admin', | ||
imageUrl: '', | ||
}, | ||
scheduleConflicts: { | ||
changeRequests: [ | ||
{ | ||
id: 73, | ||
}, | ||
{ | ||
id: 80, | ||
title: 'Adjust rollout percentage', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const feature = (change: IFeatureChange): IChangeRequestFeature => ({ | ||
name: 'conflict-test', | ||
changes: [change], | ||
}); | ||
|
||
const changeRequest = | ||
(feature: IChangeRequestFeature) => (state: ChangeRequestState) => ({ | ||
id: 1, | ||
state, | ||
title: '', | ||
project: 'default', | ||
environment: 'default', | ||
minApprovals: 1, | ||
createdBy: { id: 1, username: 'user1', imageUrl: '' }, | ||
createdAt: new Date(), | ||
features: [feature], | ||
segments: [], | ||
approvals: [], | ||
rejections: [], | ||
comments: [], | ||
}); | ||
|
||
it.each(['Draft', 'Scheduled', 'In review', 'Approved'])( | ||
'should show schedule conflicts (when they exist) for change request in the %s state', | ||
async (changeRequestState) => { | ||
const flag = feature(change); | ||
render( | ||
<FeatureChange | ||
actions={null} | ||
index={0} | ||
changeRequest={changeRequest(flag)( | ||
changeRequestState as ChangeRequestState, | ||
)} | ||
change={change} | ||
feature={flag} | ||
/>, | ||
); | ||
|
||
const alert = await screen.findByRole('alert'); | ||
|
||
expect( | ||
alert.textContent!.startsWith('Potential conflict'), | ||
).toBeTruthy(); | ||
|
||
const links = await screen.findAllByRole('link'); | ||
|
||
expect(links).toHaveLength( | ||
change.scheduleConflicts.changeRequests.length, | ||
); | ||
|
||
const [link1, link2] = links; | ||
|
||
expect(link1).toHaveTextContent('#73'); | ||
expect(link1).toHaveAccessibleDescription('Change request 73'); | ||
expect(link1).toHaveAttribute( | ||
'href', | ||
`/projects/default/change-requests/73`, | ||
); | ||
|
||
expect(link2).toHaveTextContent('#80 (Adjust rollout percentage)'); | ||
expect(link2).toHaveAccessibleDescription('Change request 80'); | ||
expect(link2).toHaveAttribute( | ||
'href', | ||
`/projects/default/change-requests/80`, | ||
); | ||
}, | ||
); | ||
|
||
it.each(['Draft', 'Scheduled', 'In review', 'Approved'])( | ||
'should not show schedule conflicts when they do not exist for change request in the %s state', | ||
async (changeRequestState) => { | ||
const { scheduleConflicts, ...changeWithNoScheduleConflicts } = | ||
change; | ||
|
||
const flag = feature(changeWithNoScheduleConflicts); | ||
|
||
render( | ||
<FeatureChange | ||
actions={null} | ||
index={0} | ||
changeRequest={changeRequest(flag)( | ||
changeRequestState as ChangeRequestState, | ||
)} | ||
change={changeWithNoScheduleConflicts} | ||
feature={flag} | ||
/>, | ||
); | ||
|
||
const links = screen.queryByRole('link'); | ||
|
||
expect(links).toBe(null); | ||
|
||
const alert = screen.queryByRole('alert'); | ||
|
||
expect(alert).toBe(null); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters