feat: 主页账号备份,并修好 B50 预览缩不小
账号备份(AccountBackupCard + AccountBackupService): - 并发读 GetUserData/Extend/Option/Rating/Charge/Activity/MissionData + Character + Map(分页)+ KaleidxScope + 各 itemKind 的 GetUserItemApi, 汇成一个 JSON 字符串可复制到剪贴板。舞里程与总游玩数据本就在 userData 的 point/totalPoint/playCount 里。 - itemKind 15(KaleidxScopeKey)不列进回读清单:客户端 ExportUserItems 从不输出它,下行也没有读它的路径,钥匙实际是 userKaleidxScopeList[].isKeyFound。 - 全程只发 GetUser*Api,不碰 UpsertUserAllApi。 - 逐段容错:私服没实现某个接口时其余照样备出,失败段单独列出—— 「读到但是空的」和「没读到」在 userItemList 里按 kind 分开存,可区分。 - 取数与拼装分开,buildBackupDocument/encode 部分是纯函数,单测覆盖。 B50 预览:原因是 InteractiveViewer(constrained:false) 给孩子无界约束, FittedBox(fit: fitWidth) 在无界下根本不缩放,海报按 1762x1850 原尺寸铺开; 而 minScale 又算成 1.0,于是既巨大又缩不动。改为给一个 contain 尺寸的 有限盒子让 FittedBox 真正缩放,minScale 固定 1.0(这个版本没有 initialScale 可用)。RepaintBoundary 留在 FittedBox 内侧,绘制尺寸仍是 1762x1850,导出分辨率不受影响,并加了断言守住这点。
This commit is contained in:
1 parent
a5fb2c97cd
commit
0cb5320290
8 files changed
+524
-36
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:ichino/services/account_backup_service.dart';
|
||||
|
||||
void main() {
|
||||
group('账号备份文档', () {
|
||||
final sections = <String, Object?>{
|
||||
'userData': {
|
||||
'userData': {'point': 123456, 'totalPoint': 999999, 'playCount': 1234},
|
||||
},
|
||||
'userCharacterList': [
|
||||
{'characterId': 101, 'level': 999999, 'awakening': 0, 'useCount': 7},
|
||||
],
|
||||
'userMapList': [
|
||||
{'mapId': 550002, 'distance': 999999999, 'isComplete': true},
|
||||
],
|
||||
'userItemList': {
|
||||
'5': [
|
||||
{'itemKind': 5, 'itemId': 11820, 'stock': 1, 'isValid': true},
|
||||
],
|
||||
'6': const <Object?>[],
|
||||
},
|
||||
};
|
||||
|
||||
test('带格式版本、userId 与 exportedAt,各段挂在 data 下', () {
|
||||
final doc = buildBackupDocument(
|
||||
userId: 42,
|
||||
sections: sections,
|
||||
exportedAt: DateTime.utc(2026, 10, 2, 3, 4, 5),
|
||||
);
|
||||
|
||||
expect(doc['backupFormat'], AccountBackup.formatVersion);
|
||||
expect(doc['userId'], 42);
|
||||
expect(doc['exportedAt'], '2026-10-02T03:04:05.000Z');
|
||||
expect(doc['data'], sections);
|
||||
});
|
||||
|
||||
test('encode 出来的是能原样解回来的 JSON 字符串', () {
|
||||
final backup = AccountBackup(
|
||||
document: buildBackupDocument(userId: 42, sections: sections),
|
||||
failedSections: const [],
|
||||
);
|
||||
|
||||
final text = backup.encode();
|
||||
expect(text, isA<String>());
|
||||
expect(text.contains('11820'), isTrue);
|
||||
|
||||
final back = jsonDecode(text) as Map<String, dynamic>;
|
||||
final data = back['data'] as Map<String, dynamic>;
|
||||
final userData =
|
||||
(data['userData'] as Map<String, dynamic>)['userData']
|
||||
as Map<String, dynamic>;
|
||||
expect(userData['point'], 123456);
|
||||
|
||||
final items = data['userItemList'] as Map<String, dynamic>;
|
||||
expect(items['5'], hasLength(1));
|
||||
// 空的那一类要留着:「读到但是空的」和「没读到」不是一回事。
|
||||
expect(items.containsKey('6'), isTrue);
|
||||
expect(items['6'], isEmpty);
|
||||
});
|
||||
|
||||
test('单段失败不算整体失败,但会记下来并让 isComplete 变 false', () {
|
||||
final backup = AccountBackup(
|
||||
document: buildBackupDocument(userId: 7, sections: sections),
|
||||
failedSections: const ['userMaps: HTTP 500', 'userItemList/12: 超时'],
|
||||
);
|
||||
|
||||
expect(backup.isComplete, isFalse);
|
||||
expect(backup.failedSections, hasLength(2));
|
||||
// 失败信息不进 data,备份正文仍然可用。
|
||||
expect(
|
||||
(jsonDecode(backup.encode()) as Map)['data'].containsKey('userMaps'),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('byteLength 与实际编码长度一致', () {
|
||||
final backup = AccountBackup(
|
||||
document: buildBackupDocument(userId: 7, sections: sections),
|
||||
failedSections: const [],
|
||||
);
|
||||
|
||||
expect(backup.byteLength, utf8.encode(backup.encode()).length);
|
||||
});
|
||||
|
||||
test('备份要覆盖用户点名的那几类数据', () {
|
||||
expect(kBackupItemKinds, containsAll([1, 2, 3, 5, 6, 7, 10, 11, 12]));
|
||||
// 15 = KaleidxScopeKey,客户端从不读它,不该出现在回读清单里。
|
||||
expect(kBackupItemKinds, isNot(contains(15)));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -16,8 +16,20 @@ List<Best50CardData> _cards(int count, {String tag = 'a'}) => [
|
||||
syncStatus: i % 5,
|
||||
ra: 50 + i,
|
||||
rate: const [
|
||||
'D', 'C', 'B', 'BB', 'BBB', 'A', 'AA',
|
||||
'AAA', 'S', 'Sp', 'SS', 'SSp', 'SSS', 'SSSp',
|
||||
'D',
|
||||
'C',
|
||||
'B',
|
||||
'BB',
|
||||
'BBB',
|
||||
'A',
|
||||
'AA',
|
||||
'AAA',
|
||||
'S',
|
||||
'Sp',
|
||||
'SS',
|
||||
'SSp',
|
||||
'SSS',
|
||||
'SSSp',
|
||||
][i % 14],
|
||||
),
|
||||
];
|
||||
@@ -71,10 +83,10 @@ void main() {
|
||||
test('满 50 张时最后一张不越出底图', () {
|
||||
final right =
|
||||
Best50Poster.cardLeft(Best50Poster.columnsPerRow - 1) +
|
||||
Best50Poster.cardWidth;
|
||||
Best50Poster.cardWidth;
|
||||
final bottom =
|
||||
Best50Poster.cardTopBest15(Best50Poster.maxBest15 - 1) +
|
||||
Best50Poster.cardHeight;
|
||||
Best50Poster.cardHeight;
|
||||
expect(right, lessThanOrEqualTo(Best50Poster.canvasWidth));
|
||||
expect(bottom, lessThanOrEqualTo(Best50Poster.canvasHeight));
|
||||
});
|
||||
@@ -99,7 +111,11 @@ void main() {
|
||||
testWidgets('BEST35 未打满时 BEST15 仍固定在第二区块', (tester) async {
|
||||
// 回归用例:以前按 35+15 拼接后的全局序号算行,BEST35 不满 35 条时
|
||||
// BEST15 会整体上移、混进上半区。
|
||||
await _pumpPoster(tester, best35: _cards(3), best15: _cards(5, tag: 'b'));
|
||||
await _pumpPoster(
|
||||
tester,
|
||||
best35: _cards(3),
|
||||
best15: _cards(5, tag: 'b'),
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
final firstOf35 = tester.getTopLeft(find.text('a#0')).dy;
|
||||
@@ -113,10 +129,9 @@ void main() {
|
||||
expect(lastOf15, greaterThanOrEqualTo(Best50Poster.gridTopSecondBlock));
|
||||
});
|
||||
|
||||
testWidgets('窄视口里海报仍保持底图尺寸(FittedBox 预览)', (tester) async {
|
||||
// 回归用例:InteractiveViewer 的 constrained 默认为 true,直接把固定尺寸的
|
||||
// 海报当子节点会被压成视口大小——底图压扁、Positioned 的卡片掉出画布被裁掉。
|
||||
// 中间垫一层 FittedBox 才是对的:视口拿到的是缩放后的显示,边界录到的仍是原尺寸。
|
||||
testWidgets('constrained:false 下海报仍保持底图原尺寸', (tester) async {
|
||||
// InteractiveViewer(constrained:false) 会给孩子无界约束。不加限定的话
|
||||
// 海报会按 1762x1850 的逻辑尺寸直接铺开,视口里只看得到左上角。
|
||||
tester.view.physicalSize = const Size(400, 900);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
@@ -151,15 +166,62 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
tester.getSize(find.byType(Best50Poster)),
|
||||
const Size(
|
||||
Best50Poster.canvasWidth,
|
||||
Best50Poster.canvasHeight,
|
||||
),
|
||||
const Size(Best50Poster.canvasWidth, Best50Poster.canvasHeight),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('缩放到 contain 盒子后海报仍是原尺寸(导出分辨率不受影响)', (tester) async {
|
||||
// 页面现在用「有限大小的盒子 + FittedBox」把海报整体缩到视口内,
|
||||
// RepaintBoundary 在 FittedBox 内侧,所以 toImage 出来的还是
|
||||
// 1762x1850 * pixelRatio。这条守的是:别把 RepaintBoundary 挪到盒子外面。
|
||||
tester.view.physicalSize = const Size(400, 900);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
// 视口 400x900,宽度是限制边,所以 contain 按宽算——和页面里的取法一致。
|
||||
const contain = 400 / Best50Poster.canvasWidth;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: Best50Poster.canvasWidth * contain,
|
||||
height: Best50Poster.canvasHeight * contain,
|
||||
child: const FittedBox(
|
||||
fit: BoxFit.fill,
|
||||
child: Best50Poster(
|
||||
userName: 'Test Player',
|
||||
iconId: 0,
|
||||
playerRating: 12345,
|
||||
best35: [],
|
||||
best15: [],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
tester.getSize(find.byType(Best50Poster)),
|
||||
const Size(Best50Poster.canvasWidth, Best50Poster.canvasHeight),
|
||||
);
|
||||
// 显示盒子确实缩到视口内,所以一进来能看到完整一张。
|
||||
final boxSize = tester.getSize(find.byType(FittedBox).first);
|
||||
expect(boxSize.width, closeTo(400, 0.5));
|
||||
expect(boxSize.height, closeTo(Best50Poster.canvasHeight * contain, 0.5));
|
||||
expect(boxSize.height, lessThan(900));
|
||||
});
|
||||
|
||||
testWidgets('超出上限的条目被裁剪到 35+15', (tester) async {
|
||||
await _pumpPoster(tester, best35: _cards(60), best15: _cards(40, tag: 'b'));
|
||||
await _pumpPoster(
|
||||
tester,
|
||||
best35: _cards(60),
|
||||
best15: _cards(40, tag: 'b'),
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
// BEST35 只保留前 35 条,BEST15 只保留前 15 条。
|
||||
|
||||
Reference in new issue
Block a user