-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a dialog when reviving / batch reviving features (#4988)
Adds a confirmation dialog when reviving features Closes # [SR-91](https://linear.app/unleash/issue/SR-91/reviving-a-feature-toggle-should-have-a-confirmation-dialog) https://github.com/Unleash/unleash/assets/104830839/49e71590-fd66-4eb5-bd09-5eb322e3d1c9 --------- Signed-off-by: andreas-unleash <[email protected]>
- Loading branch information
1 parent
19bc519
commit 75fb7a0
Showing
6 changed files
with
303 additions
and
38 deletions.
There are no files selected for viewing
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
157 changes: 157 additions & 0 deletions
157
frontend/src/component/archive/ArchiveTable/ArchiveTable.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,157 @@ | ||
import { ArchiveTable } from './ArchiveTable'; | ||
import { render } from 'utils/testRenderer'; | ||
import { useState } from 'react'; | ||
import { screen, fireEvent } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { | ||
DELETE_FEATURE, | ||
UPDATE_FEATURE, | ||
} from 'component/providers/AccessProvider/permissions'; | ||
import ToastRenderer from '../../common/ToastRenderer/ToastRenderer'; | ||
import { testServerRoute, testServerSetup } from '../../../utils/testServer'; | ||
|
||
const mockedFeatures = [ | ||
{ | ||
name: 'someFeature', | ||
description: '', | ||
type: 'release', | ||
project: 'default', | ||
stale: false, | ||
createdAt: '2023-08-10T09:28:58.928Z', | ||
lastSeenAt: null, | ||
impressionData: false, | ||
archivedAt: '2023-08-11T10:18:03.429Z', | ||
archived: true, | ||
}, | ||
{ | ||
name: 'someOtherFeature', | ||
description: '', | ||
type: 'release', | ||
project: 'default', | ||
stale: false, | ||
createdAt: '2023-08-10T09:28:58.928Z', | ||
lastSeenAt: null, | ||
impressionData: false, | ||
archivedAt: '2023-08-11T10:18:03.429Z', | ||
archived: true, | ||
}, | ||
]; | ||
|
||
const Component = () => { | ||
const [storedParams, setStoredParams] = useState({}); | ||
return ( | ||
<ArchiveTable | ||
title='Archived features' | ||
archivedFeatures={mockedFeatures} | ||
refetch={() => Promise.resolve({})} | ||
loading={false} | ||
setStoredParams={setStoredParams as any} | ||
storedParams={storedParams as any} | ||
projectId='default' | ||
/> | ||
); | ||
}; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = (disableAllEnvsOnRevive = false) => { | ||
testServerRoute( | ||
server, | ||
'/api/admin/projects/default/revive', | ||
{}, | ||
'post', | ||
200, | ||
); | ||
|
||
testServerRoute(server, '/api/admin/ui-config', { | ||
environment: 'Open Source', | ||
flags: { | ||
disableAllEnvsOnRevive, | ||
}, | ||
}); | ||
}; | ||
|
||
test('should load the table', async () => { | ||
render(<Component />, { permissions: [{ permission: UPDATE_FEATURE }] }); | ||
expect(screen.getByRole('table')).toBeInTheDocument(); | ||
|
||
await screen.findByText('someFeature'); | ||
}); | ||
|
||
test('should show confirm dialog when reviving toggle', async () => { | ||
setupApi(false); | ||
render( | ||
<> | ||
<ToastRenderer /> | ||
<Component /> | ||
</>, | ||
{ permissions: [{ permission: UPDATE_FEATURE }] }, | ||
); | ||
await screen.findByText('someFeature'); | ||
|
||
const reviveButton = screen.getAllByTestId( | ||
'revive-feature-toggle-button', | ||
)?.[0]; | ||
fireEvent.click(reviveButton); | ||
|
||
await screen.findByText('Revive feature toggle?'); | ||
const reviveTogglesButton = screen.getByRole('button', { | ||
name: /Revive feature toggle/i, | ||
}); | ||
fireEvent.click(reviveTogglesButton); | ||
|
||
await screen.findByText("And we're back!"); | ||
}); | ||
|
||
test('should show confirm dialog when batch reviving toggle', async () => { | ||
setupApi(false); | ||
render( | ||
<> | ||
<ToastRenderer /> | ||
<Component /> | ||
</>, | ||
{ | ||
permissions: [ | ||
{ permission: UPDATE_FEATURE, project: 'default' }, | ||
{ permission: DELETE_FEATURE, project: 'default' }, | ||
], | ||
}, | ||
); | ||
await screen.findByText('someFeature'); | ||
|
||
const selectAll = await screen.findByTestId('select_all_rows'); | ||
fireEvent.click(selectAll.firstChild!); | ||
const batchReviveButton = await screen.findByText(/Revive/i); | ||
await userEvent.click(batchReviveButton!); | ||
|
||
await screen.findByText('Revive feature toggles?'); | ||
|
||
const reviveTogglesButton = screen.getByRole('button', { | ||
name: /Revive feature toggles/i, | ||
}); | ||
fireEvent.click(reviveTogglesButton); | ||
|
||
await screen.findByText("And we're back!"); | ||
}); | ||
|
||
test('should show info box when disableAllEnvsOnRevive flag is on', async () => { | ||
setupApi(true); | ||
render( | ||
<> | ||
<ToastRenderer /> | ||
<Component /> | ||
</>, | ||
{ permissions: [{ permission: UPDATE_FEATURE }] }, | ||
); | ||
await screen.findByText('someFeature'); | ||
|
||
const reviveButton = screen.getAllByTestId( | ||
'revive-feature-toggle-button', | ||
)?.[0]; | ||
fireEvent.click(reviveButton); | ||
|
||
await screen.findByText('Revive feature toggle?'); | ||
await screen.findByText( | ||
'Revived feature toggles will be automatically disabled in all environments', | ||
); | ||
}); |
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
Oops, something went wrong.