-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.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,130 @@ | ||
import { render } from 'utils/testRenderer'; | ||
import { StrategyChange } from './StrategyChange'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const feature = 'my_feature'; | ||
const projectId = 'default'; | ||
const environmentName = 'production'; | ||
const snapshotRollout = '70'; | ||
const currentRollout = '80'; | ||
const changeRequestRollout = '90'; | ||
const strategy = { | ||
name: 'flexibleRollout', | ||
constraints: [], | ||
variants: [], | ||
parameters: { | ||
groupId: 'child_1', | ||
stickiness: 'default', | ||
}, | ||
segments: [], | ||
id: '8e25e369-6424-4dad-b17f-5d32cceb2fbe', | ||
disabled: false, | ||
}; | ||
|
||
testServerRoute( | ||
server, | ||
`/api/admin/projects/${projectId}/features/${feature}`, | ||
{ | ||
environments: [ | ||
{ | ||
name: environmentName, | ||
strategies: [ | ||
{ | ||
...strategy, | ||
title: 'current_title', | ||
parameters: { | ||
...strategy.parameters, | ||
rollout: currentRollout, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
); | ||
|
||
test('Editing strategy before change request is applied', async () => { | ||
render( | ||
<StrategyChange | ||
featureName={feature} | ||
environmentName={environmentName} | ||
projectId={projectId} | ||
changeRequestState='Approved' | ||
change={{ | ||
action: 'updateStrategy', | ||
id: 1, | ||
payload: { | ||
...strategy, | ||
title: 'change_request_title', | ||
parameters: { | ||
...strategy.parameters, | ||
rollout: changeRequestRollout, | ||
}, | ||
snapshot: { | ||
...strategy, | ||
title: 'snapshot_title', | ||
parameters: { | ||
...strategy.parameters, | ||
rollout: snapshotRollout, | ||
}, | ||
}, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
await screen.findByText('Editing strategy:'); | ||
await screen.findByText('change_request_title'); | ||
await screen.findByText('current_title'); | ||
expect(screen.queryByText('snapshot_title')).not.toBeInTheDocument(); | ||
|
||
const viewDiff = await screen.findByText('View Diff'); | ||
userEvent.hover(viewDiff); | ||
await screen.findByText(`- parameters.rollout: "${currentRollout}"`); | ||
await screen.findByText(`+ parameters.rollout: "${changeRequestRollout}"`); | ||
}); | ||
|
||
test('Editing strategy after change request is applied', async () => { | ||
render( | ||
<StrategyChange | ||
featureName='my_feature' | ||
environmentName='production' | ||
projectId='default' | ||
changeRequestState='Applied' | ||
change={{ | ||
action: 'updateStrategy', | ||
id: 1, | ||
payload: { | ||
...strategy, | ||
title: 'change_request_title', | ||
parameters: { | ||
...strategy.parameters, | ||
rollout: changeRequestRollout, | ||
}, | ||
snapshot: { | ||
...strategy, | ||
title: 'snapshot_title', | ||
parameters: { | ||
...strategy.parameters, | ||
rollout: snapshotRollout, | ||
}, | ||
}, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
await screen.findByText('Editing strategy:'); | ||
await screen.findByText('change_request_title'); | ||
await screen.findByText('snapshot_title'); | ||
expect(screen.queryByText('current_title')).not.toBeInTheDocument(); | ||
|
||
const viewDiff = await screen.findByText('View Diff'); | ||
userEvent.hover(viewDiff); | ||
await screen.findByText(`- parameters.rollout: "${snapshotRollout}"`); | ||
await screen.findByText(`+ parameters.rollout: "${changeRequestRollout}"`); | ||
}); |
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