mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-05 16:08:46 +00:00
TF-5022 T-07 Add account switcher helpers toast sections and Viewing chrome capability
This commit is contained in:
1 parent
9fcb89269a
commit
0df36d11a9
17 files changed
+675
-4
No files matched your search
@@ -41,6 +41,12 @@ class UiKeys {
|
||||
static const String userAvatar = 'userAvatar';
|
||||
// Settings button that replaces the avatar inside Twake Workplace.
|
||||
static const String workplaceSettingsButton = 'workplace_settings_button';
|
||||
static const String viewingOwnerBanner = 'viewingOwnerBanner';
|
||||
static const String viewingOwnerBannerDismiss = 'viewingOwnerBannerDismiss';
|
||||
static const String accountSwitcherMenu = 'accountSwitcherMenu';
|
||||
static const String accountSwitchLoadingDialog = 'accountSwitchLoadingDialog';
|
||||
static const String accountSwitchLoadingCancel =
|
||||
'accountSwitchLoadingCancel';
|
||||
|
||||
// Advanced search
|
||||
static const String openAdvancedSearchButton = 'open_advanced_search_button';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/account/account.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
|
||||
@@ -10,4 +11,10 @@ extension SessionDelegationExtension on Session {
|
||||
accounts[accountId]?.isPersonal == false;
|
||||
|
||||
bool get supportsDelegation => capabilities.containsKey(delegationCapability);
|
||||
|
||||
/// Owner mailboxes listed on this session (`isPersonal: false`).
|
||||
Iterable<MapEntry<AccountId, Account>> get delegatedAccounts =>
|
||||
accounts.entries.where((entry) => entry.value.isPersonal == false);
|
||||
|
||||
bool get hasDelegatedAccounts => delegatedAccounts.isNotEmpty;
|
||||
}
|
||||
@@ -23,12 +23,16 @@ class ShownAccountCapabilities with EquatableMixin {
|
||||
/// account is shown, so mail sent from it never picks up my setting.
|
||||
final bool canApplyMyComposerSettings;
|
||||
|
||||
/// Viewing chrome (banner, stacked avatar, Delegated badge) while a delegated account is shown.
|
||||
final bool showsViewingOwnerChrome;
|
||||
|
||||
const ShownAccountCapabilities._({
|
||||
required this.canOpenSettings,
|
||||
required this.canCreateFilter,
|
||||
required this.canCreateDefaultFolders,
|
||||
required this.canUseNotificationKeychain,
|
||||
required this.canApplyMyComposerSettings,
|
||||
required this.showsViewingOwnerChrome,
|
||||
});
|
||||
|
||||
factory ShownAccountCapabilities.of(ActiveAccount? shownAccount) {
|
||||
@@ -40,6 +44,7 @@ class ShownAccountCapabilities with EquatableMixin {
|
||||
canCreateDefaultFolders: personalShown,
|
||||
canUseNotificationKeychain: personalShown,
|
||||
canApplyMyComposerSettings: !delegatedShown,
|
||||
showsViewingOwnerChrome: delegatedShown,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,5 +55,6 @@ class ShownAccountCapabilities with EquatableMixin {
|
||||
canCreateDefaultFolders,
|
||||
canUseNotificationKeychain,
|
||||
canApplyMyComposerSettings,
|
||||
showsViewingOwnerChrome,
|
||||
];
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/model/account_switch_view.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/view/dashboard_account_switch_view.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/delegates/getx_account_switch_dashboard.dart';
|
||||
|
||||
typedef AccountSwitchViewFactory = AccountSwitchView Function(BuildContext context);
|
||||
|
||||
/// Builds the dashboard switch view for avatar menu / Viewing banner entry points.
|
||||
final accountSwitchViewFactoryProvider =
|
||||
Provider<AccountSwitchViewFactory>((ref) {
|
||||
return (context) => DashboardAccountSwitchView(
|
||||
ProviderScope.containerOf(context, listen: false),
|
||||
GetXAccountSwitchDashboard(Get.find<MailboxDashBoardController>()),
|
||||
Get.key,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'package:core/presentation/utils/app_toast.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/model/account_switch_result.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
/// Inputs for [showAccountSwitchFailureToast] (keeps the helper arity low).
|
||||
class AccountSwitchFailureToastArgs {
|
||||
final AccountSwitchResult result;
|
||||
final String ownerDisplayName;
|
||||
final bool returningToMine;
|
||||
|
||||
const AccountSwitchFailureToastArgs({
|
||||
required this.result,
|
||||
required this.ownerDisplayName,
|
||||
this.returningToMine = false,
|
||||
});
|
||||
}
|
||||
|
||||
/// Error toast after a refused, failed, cancelled, or timed-out switch.
|
||||
void showAccountSwitchFailureToast({
|
||||
required BuildContext context,
|
||||
required AppToast appToast,
|
||||
required AccountSwitchFailureToastArgs args,
|
||||
}) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final result = args.result;
|
||||
|
||||
if (result is AccountSwitchRefused &&
|
||||
result.reason == AccountSwitchRefusal.composerOpen) {
|
||||
appToast.showToastErrorMessage(
|
||||
context,
|
||||
l10n.closeComposerBeforeSwitchingAccounts,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final shouldToast = result is AccountSwitchFailed ||
|
||||
result is AccountSwitchCancelled ||
|
||||
result is AccountSwitchTimedOut;
|
||||
if (!shouldToast) return;
|
||||
|
||||
final message = args.returningToMine
|
||||
? l10n.couldNotReturnToYourMailbox
|
||||
: l10n.couldNotOpenOwnerMailbox(args.ownerDisplayName);
|
||||
appToast.showToastErrorMessage(context, message);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:linagora_design_flutter/linagora_design_flutter.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/domain/extensions/session_delegation_extension.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
typedef AccountSwitcherAvatarBuilder = Widget Function(String emailAddress);
|
||||
|
||||
/// Account menu sections from the session (address-only in v1).
|
||||
List<LinagoraAccountSection<AccountId>> buildAccountSwitcherSections({
|
||||
required Session session,
|
||||
required AppLocalizations l10n,
|
||||
required AccountSwitcherAvatarBuilder avatarFor,
|
||||
}) {
|
||||
final ownAddress = session.getOwnEmailAddressOrEmpty();
|
||||
return [
|
||||
LinagoraAccountSection(
|
||||
title: l10n.yourMailbox,
|
||||
items: [
|
||||
LinagoraAccountItem(
|
||||
id: session.accountId,
|
||||
name: ownAddress,
|
||||
// v1 is address-only. Omit email to avoid a duplicate line.
|
||||
avatar: avatarFor(ownAddress),
|
||||
),
|
||||
],
|
||||
),
|
||||
LinagoraAccountSection(
|
||||
title: l10n.delegatedToYou,
|
||||
items: [
|
||||
for (final entry in session.delegatedAccounts)
|
||||
LinagoraAccountItem(
|
||||
id: entry.key,
|
||||
name: entry.value.name.value,
|
||||
avatar: avatarFor(entry.value.name.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/domain/extensions/session_delegation_extension.dart';
|
||||
|
||||
/// True when delegation is on and the session lists a delegated mailbox.
|
||||
bool canShowAccountSwitcher({
|
||||
required bool delegationEnabled,
|
||||
required Session? session,
|
||||
}) =>
|
||||
delegationEnabled && session != null && session.hasDelegatedAccounts;
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:core/presentation/extensions/string_extension.dart';
|
||||
import 'package:core/presentation/views/image/avatar_builder.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Round initials avatar sized for the account switcher chip or menu tile.
|
||||
Widget accountSwitcherAvatar(String emailAddress, double size) {
|
||||
return (AvatarBuilder()
|
||||
..text(emailAddress.firstCharacterToUpperCase)
|
||||
..size(size)
|
||||
..avatarColor(emailAddress.gradientColors)
|
||||
..addTextStyle(TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: size * 0.44,
|
||||
fontWeight: FontWeight.w600,
|
||||
)))
|
||||
.build();
|
||||
}
|
||||
@@ -3378,5 +3378,83 @@
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"openingOwnerMailbox": "Opening {name}'s mailbox…",
|
||||
"@openingOwnerMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"name"
|
||||
],
|
||||
"placeholders": {
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"openingYourMailbox": "Opening your mailbox…",
|
||||
"@openingYourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"viewingOwnerMailbox": "Viewing {name}",
|
||||
"@viewingOwnerMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"name"
|
||||
],
|
||||
"placeholders": {
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"yourMailbox": "Your mailbox",
|
||||
"@yourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"delegatedToYou": "Delegated to you",
|
||||
"@delegatedToYou": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"accountSwitcherMenu": "Account switcher",
|
||||
"@accountSwitcherMenu": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"couldNotOpenOwnerMailbox": "Couldn't open {name}'s mailbox",
|
||||
"@couldNotOpenOwnerMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"name"
|
||||
],
|
||||
"placeholders": {
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"couldNotReturnToYourMailbox": "Couldn't return to your mailbox",
|
||||
"@couldNotReturnToYourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"closeComposerBeforeSwitchingAccounts": "Close the composer before switching accounts",
|
||||
"@closeComposerBeforeSwitchingAccounts": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"delegatedMailbox": "Delegated mailbox",
|
||||
"@delegatedMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"backToYourMailbox": "Back to your mailbox",
|
||||
"@backToYourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"@@last_modified": "2026-11-04T10:09:40.401067",
|
||||
"@@last_modified": "2026-11-10T01:26:08.509231",
|
||||
"initializing_data": "Initializing data...",
|
||||
"@initializing_data": {
|
||||
"type": "text",
|
||||
@@ -5876,6 +5876,34 @@
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"endedDelegationLostItems": "Access ended. {count} unsent or draft messages were removed.",
|
||||
"@endedDelegationLostItems": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"count"
|
||||
],
|
||||
"placeholders": {
|
||||
"count": {}
|
||||
}
|
||||
},
|
||||
"delegation": "Delegation",
|
||||
"@delegation": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"delegationSettingExplanation": "Open the mailboxes other users delegated to you",
|
||||
"@delegationSettingExplanation": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"delegationToggleDescription": "Enable delegation",
|
||||
"@delegationToggleDescription": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"openingOwnerMailbox": "Opening {name}'s mailbox…",
|
||||
"@openingOwnerMailbox": {
|
||||
"type": "text",
|
||||
@@ -5885,5 +5913,73 @@
|
||||
"placeholders": {
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"openingYourMailbox": "Opening your mailbox…",
|
||||
"@openingYourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"viewingOwnerMailbox": "Viewing {name}",
|
||||
"@viewingOwnerMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"name"
|
||||
],
|
||||
"placeholders": {
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"yourMailbox": "Your mailbox",
|
||||
"@yourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"delegatedToYou": "Delegated to you",
|
||||
"@delegatedToYou": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"accountSwitcherMenu": "Account switcher",
|
||||
"@accountSwitcherMenu": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"couldNotOpenOwnerMailbox": "Couldn't open {name}'s mailbox",
|
||||
"@couldNotOpenOwnerMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"name"
|
||||
],
|
||||
"placeholders": {
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"couldNotReturnToYourMailbox": "Couldn't return to your mailbox",
|
||||
"@couldNotReturnToYourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"closeComposerBeforeSwitchingAccounts": "Close the composer before switching accounts",
|
||||
"@closeComposerBeforeSwitchingAccounts": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"delegatedMailbox": "Delegated mailbox",
|
||||
"@delegatedMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"backToYourMailbox": "Back to your mailbox",
|
||||
"@backToYourMailbox": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6253,4 +6253,76 @@ class AppLocalizations {
|
||||
args: [name],
|
||||
);
|
||||
}
|
||||
|
||||
String get openingYourMailbox {
|
||||
return Intl.message(
|
||||
'Opening your mailbox…',
|
||||
name: 'openingYourMailbox',
|
||||
);
|
||||
}
|
||||
|
||||
String viewingOwnerMailbox(String name) {
|
||||
return Intl.message(
|
||||
'Viewing $name',
|
||||
name: 'viewingOwnerMailbox',
|
||||
args: [name],
|
||||
);
|
||||
}
|
||||
|
||||
String get yourMailbox {
|
||||
return Intl.message(
|
||||
'Your mailbox',
|
||||
name: 'yourMailbox',
|
||||
);
|
||||
}
|
||||
|
||||
String get delegatedToYou {
|
||||
return Intl.message(
|
||||
'Delegated to you',
|
||||
name: 'delegatedToYou',
|
||||
);
|
||||
}
|
||||
|
||||
String get accountSwitcherMenu {
|
||||
return Intl.message(
|
||||
'Account switcher',
|
||||
name: 'accountSwitcherMenu',
|
||||
);
|
||||
}
|
||||
|
||||
String couldNotOpenOwnerMailbox(String name) {
|
||||
return Intl.message(
|
||||
"Couldn't open $name's mailbox",
|
||||
name: 'couldNotOpenOwnerMailbox',
|
||||
args: [name],
|
||||
);
|
||||
}
|
||||
|
||||
String get couldNotReturnToYourMailbox {
|
||||
return Intl.message(
|
||||
"Couldn't return to your mailbox",
|
||||
name: 'couldNotReturnToYourMailbox',
|
||||
);
|
||||
}
|
||||
|
||||
String get closeComposerBeforeSwitchingAccounts {
|
||||
return Intl.message(
|
||||
'Close the composer before switching accounts',
|
||||
name: 'closeComposerBeforeSwitchingAccounts',
|
||||
);
|
||||
}
|
||||
|
||||
String get delegatedMailbox {
|
||||
return Intl.message(
|
||||
'Delegated mailbox',
|
||||
name: 'delegatedMailbox',
|
||||
);
|
||||
}
|
||||
|
||||
String get backToYourMailbox {
|
||||
return Intl.message(
|
||||
'Back to your mailbox',
|
||||
name: 'backToYourMailbox',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ void main() {
|
||||
canCreateDefaultFolders,
|
||||
canUseNotificationKeychain,
|
||||
canApplyMyComposerSettings,
|
||||
showsViewingOwnerChrome,
|
||||
) in [
|
||||
(
|
||||
'my own account',
|
||||
@@ -25,6 +26,7 @@ void main() {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
),
|
||||
(
|
||||
'a delegated account',
|
||||
@@ -34,6 +36,7 @@ void main() {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
),
|
||||
(
|
||||
'no account yet',
|
||||
@@ -43,14 +46,16 @@ void main() {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
),
|
||||
]) {
|
||||
test(
|
||||
'${canOpenSettings ? 'opens' : 'does not open'} Settings, '
|
||||
'${canCreateFilter ? 'allows' : 'does not allow'} creating a filter, '
|
||||
'${canCreateDefaultFolders ? 'creates' : 'does not create'} default folders, '
|
||||
'${canUseNotificationKeychain ? 'writes' : 'does not write'} the notification keychain and '
|
||||
'${canApplyMyComposerSettings ? 'applies' : 'does not apply'} my composer settings '
|
||||
'${canUseNotificationKeychain ? 'writes' : 'does not write'} the notification keychain, '
|
||||
'${canApplyMyComposerSettings ? 'applies' : 'does not apply'} my composer settings and '
|
||||
'${showsViewingOwnerChrome ? 'shows' : 'does not show'} Viewing owner chrome '
|
||||
'while $shown is shown',
|
||||
() {
|
||||
final capabilities = ShownAccountCapabilities.of(shownAccount);
|
||||
@@ -60,6 +65,7 @@ void main() {
|
||||
expect(capabilities.canCreateDefaultFolders, canCreateDefaultFolders);
|
||||
expect(capabilities.canUseNotificationKeychain, canUseNotificationKeychain);
|
||||
expect(capabilities.canApplyMyComposerSettings, canApplyMyComposerSettings);
|
||||
expect(capabilities.showsViewingOwnerChrome, showsViewingOwnerChrome);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/model/account_switch_result.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/utils/account_switch_failure_toast.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations_delegate.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/localization_service.dart';
|
||||
|
||||
import '../../../../fixtures/recording_app_toast.dart';
|
||||
|
||||
void main() {
|
||||
late RecordingAppToast appToast;
|
||||
|
||||
setUp(() {
|
||||
appToast = RecordingAppToast();
|
||||
});
|
||||
|
||||
Future<BuildContext> pumpWithContext(WidgetTester tester) async {
|
||||
late BuildContext captured;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: const [AppLocalizationsDelegate()],
|
||||
supportedLocales: LocalizationService.supportedLocales,
|
||||
locale: LocalizationService.defaultLocale,
|
||||
home: Builder(builder: (context) {
|
||||
captured = context;
|
||||
return const SizedBox.shrink();
|
||||
}),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
return captured;
|
||||
}
|
||||
|
||||
group('showAccountSwitchFailureToast', () {
|
||||
for (final result in <AccountSwitchResult>[
|
||||
AccountSwitchFailed(Exception('load'), StackTrace.current),
|
||||
const AccountSwitchCancelled(),
|
||||
const AccountSwitchTimedOut(),
|
||||
]) {
|
||||
testWidgets('toasts Could not open for ${result.runtimeType}',
|
||||
(tester) async {
|
||||
final context = await pumpWithContext(tester);
|
||||
showAccountSwitchFailureToast(
|
||||
context: context,
|
||||
appToast: appToast.toast,
|
||||
args: AccountSwitchFailureToastArgs(
|
||||
result: result,
|
||||
ownerDisplayName: 'bob@domain.tld',
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
appToast.errorMessages,
|
||||
[
|
||||
AppLocalizations.of(context)
|
||||
.couldNotOpenOwnerMailbox('bob@domain.tld'),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'toasts return-to-mine copy for ${result.runtimeType}',
|
||||
(tester) async {
|
||||
final context = await pumpWithContext(tester);
|
||||
showAccountSwitchFailureToast(
|
||||
context: context,
|
||||
appToast: appToast.toast,
|
||||
args: AccountSwitchFailureToastArgs(
|
||||
result: result,
|
||||
ownerDisplayName: 'alice@domain.tld',
|
||||
returningToMine: true,
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
appToast.errorMessages,
|
||||
[AppLocalizations.of(context).couldNotReturnToYourMailbox],
|
||||
);
|
||||
expect(
|
||||
appToast.errorMessages.single,
|
||||
isNot(contains("alice@domain.tld's mailbox")),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('toasts close-composer copy when composer is open',
|
||||
(tester) async {
|
||||
final context = await pumpWithContext(tester);
|
||||
showAccountSwitchFailureToast(
|
||||
context: context,
|
||||
appToast: appToast.toast,
|
||||
args: const AccountSwitchFailureToastArgs(
|
||||
result: AccountSwitchRefused(AccountSwitchRefusal.composerOpen),
|
||||
ownerDisplayName: 'bob@domain.tld',
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
appToast.errorMessages,
|
||||
[AppLocalizations.of(context).closeComposerBeforeSwitchingAccounts],
|
||||
);
|
||||
});
|
||||
|
||||
for (final result in <AccountSwitchResult>[
|
||||
const AccountSwitched(),
|
||||
const AccountSwitchRefused(AccountSwitchRefusal.accountAlreadyShown),
|
||||
const AccountSwitchRefused(AccountSwitchRefusal.switchInProgress),
|
||||
const AccountSwitchRefused(AccountSwitchRefusal.accountNotListed),
|
||||
]) {
|
||||
testWidgets('stays silent for $result', (tester) async {
|
||||
final context = await pumpWithContext(tester);
|
||||
showAccountSwitchFailureToast(
|
||||
context: context,
|
||||
appToast: appToast.toast,
|
||||
args: AccountSwitchFailureToastArgs(
|
||||
result: result,
|
||||
ownerDisplayName: 'bob@domain.tld',
|
||||
),
|
||||
);
|
||||
|
||||
expect(appToast.errorMessages, isEmpty);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/utils/account_switcher_sections.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
import '../../../../fixtures/delegation_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
late AppLocalizations l10n;
|
||||
|
||||
setUpAll(() {
|
||||
l10n = AppLocalizations();
|
||||
});
|
||||
|
||||
Widget avatar(String email) => Text(email);
|
||||
|
||||
group('buildAccountSwitcherSections', () {
|
||||
test('puts my mailbox first and every delegated account under Delegated to you', () {
|
||||
final sections = buildAccountSwitcherSections(
|
||||
session: DelegationFixtures.session(),
|
||||
l10n: l10n,
|
||||
avatarFor: avatar,
|
||||
);
|
||||
|
||||
expect(sections, hasLength(2));
|
||||
expect(sections[0].title, l10n.yourMailbox);
|
||||
expect(sections[0].items.single.id, DelegationFixtures.aliceAccountId);
|
||||
expect(sections[0].items.single.name, DelegationFixtures.aliceAddress);
|
||||
|
||||
expect(sections[1].title, l10n.delegatedToYou);
|
||||
expect(
|
||||
sections[1].items.map((item) => item.id),
|
||||
[DelegationFixtures.bobAccountId, DelegationFixtures.carolAccountId],
|
||||
);
|
||||
expect(
|
||||
sections[1].items.map((item) => item.name),
|
||||
[DelegationFixtures.bobAddress, DelegationFixtures.carolAddress],
|
||||
);
|
||||
});
|
||||
|
||||
test('omits the delegated section items when the session lists none', () {
|
||||
final sections = buildAccountSwitcherSections(
|
||||
session: DelegationFixtures.session(listsBob: false, listsCarol: false),
|
||||
l10n: l10n,
|
||||
avatarFor: avatar,
|
||||
);
|
||||
|
||||
expect(sections[1].items, isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/utils/account_switcher_visibility.dart';
|
||||
|
||||
import '../../../../fixtures/delegation_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
group('canShowAccountSwitcher', () {
|
||||
test('is false when delegation is off even with delegated accounts', () {
|
||||
expect(
|
||||
canShowAccountSwitcher(
|
||||
delegationEnabled: false,
|
||||
session: DelegationFixtures.session(),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('is false when the session is null', () {
|
||||
expect(
|
||||
canShowAccountSwitcher(delegationEnabled: true, session: null),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('is false when delegation is on but no delegated account is listed', () {
|
||||
expect(
|
||||
canShowAccountSwitcher(
|
||||
delegationEnabled: true,
|
||||
session: DelegationFixtures.session(listsBob: false, listsCarol: false),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('is true when delegation is on and a delegated account is listed', () {
|
||||
expect(
|
||||
canShowAccountSwitcher(
|
||||
delegationEnabled: true,
|
||||
session: DelegationFixtures.session(listsBob: true, listsCarol: false),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tmail_ui_user/features/delegation/presentation/widgets/account_switcher_avatar.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('sizes the avatar and initials to the given diameter',
|
||||
(tester) async {
|
||||
const size = 40.0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: accountSwitcherAvatar('bob@example.com', size),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('B'), findsOneWidget);
|
||||
|
||||
final avatarFinder =
|
||||
find.ancestor(of: find.text('B'), matching: find.byType(Container)).first;
|
||||
expect(tester.getSize(avatarFinder), const Size(size, size));
|
||||
|
||||
final initials = tester.widget<Text>(find.text('B'));
|
||||
expect(initials.style?.fontSize, size * 0.44);
|
||||
});
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import 'package:core/presentation/utils/app_toast.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../features/delegation/presentation/session_from_cache_to_dashboard_test.mocks.dart';
|
||||
|
||||
/// Captures [AppToast.showToastErrorMessage] text via a generated mock so test
|
||||
/// files do not hand-write a 5-arg override (CodeScene).
|
||||
class RecordingAppToast {
|
||||
final List<String> errorMessages = [];
|
||||
final MockAppToast _toast = MockAppToast();
|
||||
|
||||
RecordingAppToast() {
|
||||
when(_toast.showToastErrorMessage(any, any)).thenAnswer((invocation) {
|
||||
errorMessages.add(invocation.positionalArguments[1] as String);
|
||||
});
|
||||
}
|
||||
|
||||
AppToast get toast => _toast;
|
||||
}
|
||||
Reference in new issue
Block a user