-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: archive toggles in change request UI (#4563)
- Loading branch information
Showing
6 changed files
with
287 additions
and
43 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
frontend/src/component/changeRequest/ChangeRequest/Changes/Change/ArchiveFeatureChange.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,22 @@ | ||
import { FC, ReactNode } from 'react'; | ||
import { Box, styled } from '@mui/material'; | ||
import { ChangeItemWrapper } from './StrategyChange'; | ||
|
||
const ArchiveBox = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
color: theme.palette.error.main, | ||
})); | ||
|
||
interface IArchiveFeatureChange { | ||
actions?: ReactNode; | ||
} | ||
|
||
export const ArchiveFeatureChange: FC<IArchiveFeatureChange> = ({ | ||
actions, | ||
}) => ( | ||
<ChangeItemWrapper> | ||
<ArchiveBox>Archiving feature</ArchiveBox> | ||
{actions} | ||
</ChangeItemWrapper> | ||
); |
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
119 changes: 119 additions & 0 deletions
119
frontend/src/component/common/FeatureArchiveDialog/FeatureArchiveDialog.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,119 @@ | ||
import { vi } from 'vitest'; | ||
import React from 'react'; | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { FeatureArchiveDialog } from './FeatureArchiveDialog'; | ||
import { UIProviderContainer } from 'component/providers/UIProvider/UIProviderContainer'; | ||
|
||
const server = testServerSetup(); | ||
const setupHappyPathForChangeRequest = () => { | ||
testServerRoute( | ||
server, | ||
'/api/admin/projects/projectId/environments/development/change-requests', | ||
{}, | ||
'post' | ||
); | ||
testServerRoute( | ||
server, | ||
'/api/admin/projects/projectId/change-requests/config', | ||
[ | ||
{ | ||
environment: 'development', | ||
type: 'development', | ||
requiredApprovals: 1, | ||
changeRequestEnabled: true, | ||
}, | ||
] | ||
); | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
versionInfo: { | ||
current: { oss: 'version', enterprise: 'version' }, | ||
}, | ||
}); | ||
}; | ||
|
||
test('Add single archive feature change to change request', async () => { | ||
const onClose = vi.fn(); | ||
const onConfirm = vi.fn(); | ||
setupHappyPathForChangeRequest(); | ||
render( | ||
<UIProviderContainer> | ||
<FeatureArchiveDialog | ||
featureIds={['featureA']} | ||
projectId={'projectId'} | ||
isOpen={true} | ||
onClose={onClose} | ||
onConfirm={onConfirm} | ||
featuresWithUsage={[]} | ||
/> | ||
</UIProviderContainer> | ||
); | ||
|
||
expect(screen.getByText('Archive feature toggle')).toBeInTheDocument(); | ||
const button = await screen.findByText('Add change to draft'); | ||
|
||
button.click(); | ||
|
||
await waitFor(() => { | ||
expect(onConfirm).toBeCalledTimes(1); | ||
}); | ||
expect(onClose).toBeCalledTimes(1); | ||
}); | ||
|
||
test('Add multiple archive feature changes to change request', async () => { | ||
const onClose = vi.fn(); | ||
const onConfirm = vi.fn(); | ||
setupHappyPathForChangeRequest(); | ||
render( | ||
<UIProviderContainer> | ||
<FeatureArchiveDialog | ||
featureIds={['featureA', 'featureB']} | ||
projectId={'projectId'} | ||
isOpen={true} | ||
onClose={onClose} | ||
onConfirm={onConfirm} | ||
featuresWithUsage={[]} | ||
/> | ||
</UIProviderContainer> | ||
); | ||
|
||
await screen.findByText('Archive feature toggles'); | ||
const button = await screen.findByText('Add to change request'); | ||
|
||
button.click(); | ||
|
||
await waitFor(() => { | ||
expect(onConfirm).toBeCalledTimes(1); | ||
}); | ||
expect(onClose).toBeCalledTimes(1); | ||
}); | ||
|
||
test('Skip change request', async () => { | ||
const onClose = vi.fn(); | ||
const onConfirm = vi.fn(); | ||
setupHappyPathForChangeRequest(); | ||
render( | ||
<UIProviderContainer> | ||
<FeatureArchiveDialog | ||
featureIds={['featureA', 'featureB']} | ||
projectId={'projectId'} | ||
isOpen={true} | ||
onClose={onClose} | ||
onConfirm={onConfirm} | ||
featuresWithUsage={[]} | ||
/> | ||
</UIProviderContainer>, | ||
{ permissions: [{ permission: 'SKIP_CHANGE_REQUEST' }] } | ||
); | ||
|
||
await screen.findByText('Archive feature toggles'); | ||
const button = await screen.findByText('Archive toggles'); | ||
|
||
button.click(); | ||
|
||
await waitFor(() => { | ||
expect(onClose).toBeCalledTimes(1); | ||
}); | ||
expect(onConfirm).toBeCalledTimes(0); // we didn't setup non Change Request flow so failure | ||
}); |
Oops, something went wrong.