fix(account): 本地化网络异常文案

This commit is contained in:
Zhou Weidong committed 2026-10-19 09:59:45 +08:00
1 parent 9b3ab9d5de
commit 27ab7cebfb
5 files changed
+90 -11

No files matched your search

+79 -1
View File
@@ -101,6 +101,83 @@ void main() {
expect(find.byKey(const Key('account-export-content')), findsOneWidget);
});
testWidgets('should_show_localized_network_copy_when_profile_load_fails', (
tester,
) async {
final repository = FakeAccountRepository()..throwUnexpected = true;
final auth = await _signedInAuth();
await _pumpPage(
tester,
AccountProfilePage(),
repository: repository,
auth: auth,
locale: const Locale('zh'),
);
final l10n = await AppLocalizations.delegate.load(const Locale('zh'));
expect(find.text(l10n.networkError), findsOneWidget);
expect(find.text('accountProfileLoadFailed'), findsNothing);
});
testWidgets('should_show_localized_network_copy_when_profile_save_fails', (
tester,
) async {
final repository = FakeAccountRepository();
final auth = await _signedInAuth();
await _pumpPage(
tester,
AccountProfilePage(),
repository: repository,
auth: auth,
);
repository.throwUnexpected = true;
await tester.enterText(
find.byKey(const Key('account-nickname')),
'Nadia Baru',
);
await tester.tap(find.byKey(const Key('account-profile-save')));
await tester.pumpAndSettle();
final l10n = await AppLocalizations.delegate.load(const Locale('en'));
expect(find.text(l10n.networkError), findsOneWidget);
expect(find.text('accountProfileSaveFailed'), findsNothing);
});
testWidgets('should_show_localized_network_copy_when_devices_fail', (
tester,
) async {
final repository = FakeAccountRepository()..throwUnexpected = true;
final auth = await _signedInAuth();
await _pumpPage(
tester,
AccountDevicesPage(),
repository: repository,
auth: auth,
locale: const Locale('id'),
);
final l10n = await AppLocalizations.delegate.load(const Locale('id'));
expect(find.text(l10n.networkError), findsOneWidget);
expect(find.text('accountDevicesLoadFailed'), findsNothing);
});
testWidgets('should_show_localized_network_copy_when_export_fails', (
tester,
) async {
final repository = FakeAccountRepository()..throwUnexpected = true;
final auth = await _signedInAuth();
await _pumpPage(
tester,
AccountExportPage(),
repository: repository,
auth: auth,
);
final l10n = await AppLocalizations.delegate.load(const Locale('en'));
expect(find.text(l10n.networkError), findsOneWidget);
expect(find.text('accountExportLoadFailed'), findsNothing);
});
}
Future<AuthController> _signedInAuth() async {
@@ -124,6 +201,7 @@ Future<void> _pumpPage(
Widget page, {
required FakeAccountRepository repository,
required AuthController auth,
Locale locale = const Locale('en'),
}) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
@@ -136,7 +214,7 @@ Future<void> _pumpPage(
ChangeNotifierProvider<AuthController>.value(value: auth),
],
child: MaterialApp(
locale: const Locale('en'),
locale: locale,
supportedLocales: AppLocalizations.supportedLocales,
localizationsDelegates: AppLocalizations.localizationsDelegates,
home: Theme(data: ThemeData.dark(), child: page),
@@ -68,10 +68,12 @@ class FakeAccountRepository implements AccountRepository {
bool failUpdate = false;
bool failDeactivate = false;
bool failCancel = false;
bool throwUnexpected = false;
@override
Future<AccountProfile> profile() async {
profileCalls++;
if (throwUnexpected) throw StateError('offline');
if (failProfile) throw const ApiException(500, '资料加载失败');
return _profile;
}
@@ -79,6 +81,7 @@ class FakeAccountRepository implements AccountRepository {
@override
Future<AccountProfile> updateProfile(AccountProfileUpdate update) async {
lastUpdate = update;
if (throwUnexpected) throw StateError('offline');
if (failUpdate) throw const ApiException(400, '昵称不可用');
_profile = AccountProfile(
uid: _profile.uid,
@@ -100,6 +103,7 @@ class FakeAccountRepository implements AccountRepository {
@override
Future<List<AccountDevice>> devices() async {
deviceCalls++;
if (throwUnexpected) throw StateError('offline');
if (failDevices) throw const ApiException(500, '设备加载失败');
return [..._devices];
}
@@ -107,6 +111,7 @@ class FakeAccountRepository implements AccountRepository {
@override
Future<AccountExport> export() async {
exportCalls++;
if (throwUnexpected) throw StateError('offline');
if (failExport) throw const ApiException(500, '导出失败');
return _export;
}