Skip to content

Commit

Permalink
fix: archive toggle no longer respects change request (#6882)
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre committed Apr 18, 2024
1 parent fd4bcff commit 6b5cdc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ test('Add multiple archive feature changes to change request', async () => {
expect(onClose).toBeCalledTimes(1);
});

test('Skip change request', async () => {
test('Skip change request does not affect archive', async () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
setupHappyPathForChangeRequest();
setupArchiveValidation([]);
render(
<FeatureArchiveDialog
featureIds={['featureA', 'featureB']}
featureIds={['featureA']}
projectId={'projectId'}
isOpen={true}
onClose={onClose}
Expand All @@ -129,16 +129,17 @@ test('Skip change request', async () => {
{ permissions: [{ permission: 'SKIP_CHANGE_REQUEST' }] },
);

await screen.findByText('Archive feature toggles');
const button = await screen.findByText('Archive toggles');
await screen.findByText('Archive feature toggle');
const button = await screen.findByText('Add change to draft');

await waitFor(() => expect(button).toBeEnabled());

button.click();

await waitFor(() => {
expect(onClose).toBeCalledTimes(1);
});
expect(onConfirm).toBeCalledTimes(0); // we didn't setup non Change Request flow so failure
expect(onConfirm).toBeCalledTimes(1);
});

test('Show error message when multiple parents of orphaned children are archived', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,16 @@ const useActionButtonText = (projectId: string, isBulkArchive: boolean) => {
const getHighestEnvironment =
useHighestPermissionChangeRequestEnvironment(projectId);
const environment = getHighestEnvironment();
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
const { isChangeRequestConfiguredForReview } =
useChangeRequestsEnabled(projectId);
if (
environment &&
isChangeRequestConfigured(environment) &&
isChangeRequestConfiguredForReview(environment) &&
isBulkArchive
) {
return 'Add to change request';
}
if (environment && isChangeRequestConfigured(environment)) {
if (environment && isChangeRequestConfiguredForReview(environment)) {
return 'Add change to draft';
}
if (isBulkArchive) {
Expand All @@ -212,7 +213,8 @@ const useArchiveAction = ({
const { setToastData, setToastApiError } = useToast();
const { archiveFeatureToggle } = useFeatureApi();
const { archiveFeatures } = useProjectApi();
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
const { isChangeRequestConfiguredForReview } =
useChangeRequestsEnabled(projectId);
const { addChange } = useChangeRequestApi();
const { refetch: refetchChangeRequests } =
usePendingChangeRequests(projectId);
Expand Down Expand Up @@ -266,7 +268,10 @@ const useArchiveAction = ({

return async () => {
try {
if (environment && isChangeRequestConfigured(environment)) {
if (
environment &&
isChangeRequestConfiguredForReview(environment)
) {
await addArchiveToggleToChangeRequest();
} else if (isBulkArchive) {
await archiveToggles();
Expand Down

0 comments on commit 6b5cdc2

Please sign in to comment.