diff --git a/app/products/playbooks/screens/playbook_run/playbook_run.test.tsx b/app/products/playbooks/screens/playbook_run/playbook_run.test.tsx index c46908d20..998493a60 100644 --- a/app/products/playbooks/screens/playbook_run/playbook_run.test.tsx +++ b/app/products/playbooks/screens/playbook_run/playbook_run.test.tsx @@ -354,6 +354,29 @@ describe('PlaybookRun', () => { expect(finishRun).toHaveBeenCalledWith(serverUrl, props.playbookRun!.id); }); + it('handles finish run button press with no pending tasks', () => { + const props = getBaseProps(); + props.participants.push(TestHelper.fakeUserModel({id: props.currentUserId})); + props.pendingCount = 0; + jest.mocked(Alert.alert).mockClear(); + const {getByText} = renderWithEverything(, {database}); + + const finishRunButton = getByText('Finish'); + fireEvent.press(finishRunButton); + + expect(Alert.alert).toHaveBeenCalledWith( + 'Finish', + 'Are you sure you want to finish the checklist for all participants?', + [ + {text: 'Cancel', style: 'cancel'}, + {text: 'Finish', style: 'destructive', onPress: expect.any(Function)}, + ], + ); + const finishAction = jest.mocked(Alert.alert).mock.calls[0][2]![1]; + finishAction.onPress?.(); + expect(finishRun).toHaveBeenCalledWith(serverUrl, props.playbookRun!.id); + }); + it('does not render finish run button when read only', () => { const props = getBaseProps(); const {queryByText} = renderWithEverything(, {database}); diff --git a/app/products/playbooks/screens/playbook_run/playbook_run.tsx b/app/products/playbooks/screens/playbook_run/playbook_run.tsx index 16ae9e763..992fd387e 100644 --- a/app/products/playbooks/screens/playbook_run/playbook_run.tsx +++ b/app/products/playbooks/screens/playbook_run/playbook_run.tsx @@ -71,9 +71,13 @@ const messages = defineMessages({ id: 'playbooks.playbook_run.finish_run_dialog_title', defaultMessage: 'Finish', }, - finishRunDialogDescription: { - id: 'playbooks.playbook_run.finish_run_dialog_description', - defaultMessage: 'There are {pendingCount} {pendingCount, plural, =1 {task} other {tasks}} pending.\n\nAre you sure you want to finish the checklist for all participants?', + finishRunDialogPendingTasks: { + id: 'playbooks.playbook_run.finish_run_dialog_pending_tasks', + defaultMessage: 'There are {pendingCount} {pendingCount, plural, =1 {task} other {tasks}} pending.', + }, + finishRunDialogConfirmation: { + id: 'playbooks.playbook_run.finish_run_dialog_confirmation', + defaultMessage: 'Are you sure you want to finish the checklist for all participants?', }, finishRunDialogCancel: { id: 'playbooks.playbook_run.finish_run_dialog_cancel', @@ -270,9 +274,14 @@ export default function PlaybookRun({ return; } + let message = intl.formatMessage(messages.finishRunDialogConfirmation); + if (pendingCount > 0) { + message = `${intl.formatMessage(messages.finishRunDialogPendingTasks, {pendingCount})}\n\n${message}`; + } + Alert.alert( intl.formatMessage(messages.finishRunDialogTitle), - intl.formatMessage(messages.finishRunDialogDescription, {pendingCount}), + message, [ { text: intl.formatMessage(messages.finishRunDialogCancel), diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index 60c40c9b7..8a3620d65 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -1040,8 +1040,9 @@ "playbooks.playbook_run.error.title": "Unable to fetch details", "playbooks.playbook_run.finish_run_button": "Finish", "playbooks.playbook_run.finish_run_dialog_cancel": "Cancel", - "playbooks.playbook_run.finish_run_dialog_description": "There are {pendingCount} {pendingCount, plural, =1 {task} other {tasks}} pending.\n\nAre you sure you want to finish the checklist for all participants?", + "playbooks.playbook_run.finish_run_dialog_confirmation": "Are you sure you want to finish the checklist for all participants?", "playbooks.playbook_run.finish_run_dialog_finish": "Finish", + "playbooks.playbook_run.finish_run_dialog_pending_tasks": "There are {pendingCount} {pendingCount, plural, =1 {task} other {tasks}} pending.", "playbooks.playbook_run.finish_run_dialog_title": "Finish", "playbooks.playbook_run.finished": "Finished", "playbooks.playbook_run.overdue": "{num} {num, plural, =1 {task} other {tasks}} overdue",