feat(account): 增加账号中心页面逻辑
This commit is contained in:
1 parent
ef7f4ce3b6
commit
c68f02449f
6 files changed
+503
No files matched your search
@@ -0,0 +1,101 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/account_device.dart';
|
||||
import 'package:fruitshorts/core/data/models/account_profile.dart';
|
||||
import 'package:fruitshorts/pages/account/account_deactivate_logic.dart';
|
||||
import 'package:fruitshorts/pages/account/account_devices_logic.dart';
|
||||
import 'package:fruitshorts/pages/account/account_export_logic.dart';
|
||||
import 'package:fruitshorts/pages/account/account_profile_logic.dart';
|
||||
|
||||
import '../support/fake_account_repository.dart';
|
||||
|
||||
void main() {
|
||||
test('should_update_profile_and_notify_auth_when_saved', () async {
|
||||
final repository = FakeAccountRepository();
|
||||
AccountProfile? applied;
|
||||
final logic = AccountProfileLogic(
|
||||
repository,
|
||||
onProfileUpdated: (profile) async => applied = profile,
|
||||
);
|
||||
await logic.load();
|
||||
|
||||
final ok = await logic.save(
|
||||
nickname: ' Nadia Baru ',
|
||||
gender: 'unknown',
|
||||
birthday: '1999-01-02',
|
||||
);
|
||||
|
||||
expect(ok, isTrue);
|
||||
expect(repository.lastUpdate?.nickname, 'Nadia Baru');
|
||||
expect(repository.lastUpdate?.gender, 'unknown');
|
||||
expect(repository.lastUpdate?.birthday, '1999-01-02');
|
||||
expect(applied?.nickname, 'Nadia Baru');
|
||||
});
|
||||
|
||||
test('should_load_devices_and_keep_the_page_read_only', () async {
|
||||
final repository = FakeAccountRepository(
|
||||
devices: const [
|
||||
AccountDevice(
|
||||
id: '1',
|
||||
deviceId: 'd-device-1234',
|
||||
platform: 'IOS',
|
||||
deviceModel: 'iPhone 15',
|
||||
status: 'active',
|
||||
),
|
||||
],
|
||||
);
|
||||
final logic = AccountDevicesLogic(repository);
|
||||
|
||||
await logic.load();
|
||||
|
||||
expect(logic.devices.single.deviceModel, 'iPhone 15');
|
||||
expect(logic.loading, isFalse);
|
||||
expect(logic.error, isNull);
|
||||
});
|
||||
|
||||
test('should_copy_complete_export_json_when_requested', () async {
|
||||
final repository = FakeAccountRepository();
|
||||
String copied = '';
|
||||
final logic = AccountExportLogic(
|
||||
repository,
|
||||
copyText: (value) async => copied = value,
|
||||
);
|
||||
await logic.load();
|
||||
|
||||
final ok = await logic.copy();
|
||||
|
||||
expect(ok, isTrue);
|
||||
expect(copied, contains('"credentials"'));
|
||||
expect(copied, contains('n***@example.com'));
|
||||
});
|
||||
|
||||
test('should_clear_session_and_keep_schedule_when_deactivation_succeeds', () async {
|
||||
final repository = FakeAccountRepository();
|
||||
var cleared = false;
|
||||
final logic = AccountDeactivateLogic(
|
||||
repository,
|
||||
clearSession: () async => cleared = true,
|
||||
);
|
||||
|
||||
final ok = await logic.request('不再使用');
|
||||
|
||||
expect(ok, isTrue);
|
||||
expect(repository.lastDeactivateReason, '不再使用');
|
||||
expect(logic.scheduledAt, DateTime(2026, 11, 3, 9, 30));
|
||||
expect(cleared, isTrue);
|
||||
});
|
||||
|
||||
test('should_show_backend_message_when_cancel_deactivation_fails', () async {
|
||||
final repository = FakeAccountRepository()..failCancel = true;
|
||||
final logic = AccountDeactivateLogic(
|
||||
repository,
|
||||
clearSession: () async {},
|
||||
);
|
||||
|
||||
final ok = await logic.cancel();
|
||||
|
||||
expect(ok, isFalse);
|
||||
expect(logic.actionMessage, '没有待处理的注销申请');
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user