From 44cc4d6caf2033b60fc0b9b2dcf1f41aa759dcc5 Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 28 Oct 2026 17:05:22 +0700 Subject: [PATCH] TF-5022 Check the shown account again when Open is tapped on the restored messages toast of MailboxDashBoardController --- .../mailbox_dashboard_controller.dart | 6 +++- ...shboard_controller_shown_account_test.dart | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index cd46ae92a..38acc28f2 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -3269,7 +3269,11 @@ class MailboxDashBoardController extends ReloadableController currentOverlayContext!, AppLocalizations.of(currentContext!).restoreDeletedMessageSuccess, actionName: AppLocalizations.of(currentContext!).open, - onActionClick: () => openMailboxAction(success.recoveredMailbox!.toPresentationMailbox()), + onActionClick: () { + // Open may be tapped once another account is shown, where this folder does not exist. + if (success.accountId != activeAccountId) return; + openMailboxAction(success.recoveredMailbox!.toPresentationMailbox()); + }, leadingSVGIcon: imagePaths.icRecoverDeletedMessages, leadingSVGIconColor: Colors.white, backgroundColor: AppColor.toastSuccessBackgroundColor, diff --git a/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_shown_account_test.dart b/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_shown_account_test.dart index 7334c9731..c186be4f7 100644 --- a/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_shown_account_test.dart +++ b/test/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller_shown_account_test.dart @@ -540,6 +540,42 @@ void main() { }); } + for (final switched in [false, true]) { + testWidgets('Open on a restore finished on bob ${switched ? 'does nothing once carol is shown' : 'opens its folder'}', + (tester) async { + await pumpLocalizedApp(tester); + clearInteractions(appToast); + final source = ActiveAccountSourceFixtures.putShowing(DelegationFixtures.bobAccountId); + mailboxDashboardController.mailboxUIAction.value = null; + mailboxDashboardController.handleSuccessViewState(GetRestoredDeletedMessageCompleted( + EmailRecoveryAction(id: EmailRecoveryActionId(Id('recovery-1'))), + DelegationFixtures.bobAccountId, + recoveredMailbox: Mailbox(id: MailboxId(Id('bob-restored'))), + )); + final open = verify(appToast.showToastMessage( + any, + any, + actionName: anyNamed('actionName'), + onActionClick: captureAnyNamed('onActionClick'), + actionIcon: anyNamed('actionIcon'), + leadingSVGIcon: anyNamed('leadingSVGIcon'), + leadingSVGIconColor: anyNamed('leadingSVGIconColor'), + backgroundColor: anyNamed('backgroundColor'), + textColor: anyNamed('textColor'), + )).captured.single as Function; + + if (switched) source.show(DelegationFixtures.carolAccountId); + open(); + + final action = mailboxDashboardController.mailboxUIAction.value; + if (switched) { + expect(action, isNull); + } else { + expect((action as OpenMailboxAction).presentationMailbox.id, MailboxId(Id('bob-restored'))); + } + }); + } + test('keeps polling the account the restore started on while it is in progress', () { ActiveAccountSourceFixtures.putShowing(DelegationFixtures.carolAccountId); final recoveryAction = EmailRecoveryAction(id: EmailRecoveryActionId(Id('recovery-1')));