yx_app_upgrade_flutter/test/app_upgrade_simple_dialog_t...

229 lines
7.1 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:yx_app_upgrade_flutter/app_upgrade_simple.dart';
import 'package:yx_app_upgrade_flutter/models/upgrade_info.dart';
void main() {
group('showPreparedUpgrade', () {
testWidgets('renders header block and body content without crashing',
(WidgetTester tester) async {
var updateLaterCalled = false;
await tester.pumpWidget(
_DialogTestHost(
info: _buildUpgradeInfo(
updateContent: '''
/{
本次 **V2.2.0** 版本聚焦[使用体验]优化。
__支持嵌套__例如 **[特别注意]** 与 `version 2.0`
/}
1. **第一条说明**
普通补充说明
''',
),
onUpdateLater: () {
updateLaterCalled = true;
},
),
);
await tester.tap(find.text('open-upgrade-dialog'));
await tester.pumpAndSettle();
expect(find.text('发现新版本'), findsOneWidget);
expect(find.text('更新内容'), findsOneWidget);
expect(_richTextPlainTexts(tester),
contains(contains('本次 V2.2.0 版本聚焦使用体验优化。')));
expect(_richTextPlainTexts(tester),
contains(contains('支持嵌套,例如 特别注意 与 version 2.0')));
expect(_richTextPlainTexts(tester), contains(contains('1. 第一条说明')));
expect(_richTextPlainTexts(tester), contains(contains('普通补充说明')));
await tester.tap(find.text('稍后更新'));
await tester.pumpAndSettle();
expect(updateLaterCalled, isTrue);
expect(find.text('发现新版本'), findsNothing);
});
testWidgets('skips dialog when hasUpdate is false',
(WidgetTester tester) async {
await tester.pumpWidget(
_DialogTestHost(
info: _buildUpgradeInfo(
hasUpdate: false,
updateContent: '当前已经是最新版本',
),
),
);
await tester.tap(find.text('open-upgrade-dialog'));
await tester.pumpAndSettle();
expect(find.text('发现新版本'), findsNothing);
expect(find.text('更新内容'), findsNothing);
});
testWidgets('handles explicit but empty header block in dialog',
(WidgetTester tester) async {
await tester.pumpWidget(
_DialogTestHost(
info: _buildUpgradeInfo(
updateContent: '''
/{ /}
- 第一条说明
第二条说明
''',
),
),
);
await tester.tap(find.text('open-upgrade-dialog'));
await tester.pumpAndSettle();
expect(find.text('发现新版本'), findsOneWidget);
expect(_richTextPlainTexts(tester), contains(contains('- 第一条说明')));
expect(_richTextPlainTexts(tester), contains(contains('第二条说明')));
});
testWidgets('renders the final growth-center line as update content',
(WidgetTester tester) async {
await tester.pumpWidget(
_DialogTestHost(
info: _buildUpgradeInfo(
updateContent: '''
/{本次 **V2.2.0** 版本围绕[使用体验]、[账号安全]、[家校联动]、[学习管理]等方面进行多项优化与功能新增,具体更新内容如下:/}
工作录入新增**草稿箱功能**,录入内容自动暂存,录入途中临时退出、意外关闭页面,都不会丢失填写数据,有效避免重复录入,提升使用效率;
优化**多账号登录机制**,若同一手机号绑定多个账号,登录时需手动选择本次要登录的对应账号,区分账号使用,保障使用精准性;
全新上线**家校互动板块**,新增家长会、社群运营、线上家访特色功能,搭建高效家校沟通渠道,助力家校协同共育;
**成长中心**全面调整优化:成长中心入口迁移至工作台页面,升级全局搜索能力,章节内容改为结构化排版展示;优化视频播放逻辑与播放限制规则,同时新增学习过程监管功能,强化学习管控。
''',
),
),
);
await tester.tap(find.text('open-upgrade-dialog'));
await tester.pumpAndSettle();
expect(find.text('发现新版本'), findsOneWidget);
expect(
_richTextPlainTexts(tester),
contains(
contains(
'成长中心全面调整优化:成长中心入口迁移至工作台页面,升级全局搜索能力,章节内容改为结构化排版展示;优化视频播放逻辑与播放限制规则,同时新增学习过程监管功能,强化学习管控。',
),
),
);
});
testWidgets('renders supported rich text markers correctly on first lines',
(WidgetTester tester) async {
await tester.pumpWidget(
_DialogTestHost(
info: _buildUpgradeInfo(
updateContent: '''
/{**头部粗体** /}
**粗体首行**
__斜体第二行__
`代码第三行`
[高亮第四行]
**[组合重点]**
''',
),
),
);
await tester.tap(find.text('open-upgrade-dialog'));
await tester.pumpAndSettle();
final plainTexts = _richTextPlainTexts(tester).toList();
expect(find.text('发现新版本'), findsOneWidget);
expect(
plainTexts,
contains(contains('头部粗体')),
);
expect(
plainTexts,
contains(contains('粗体首行')),
);
expect(
plainTexts,
contains(contains('斜体第二行')),
);
expect(
plainTexts,
contains(contains('代码第三行')),
);
expect(
plainTexts,
contains(contains('高亮第四行')),
);
expect(
plainTexts,
contains(contains('组合重点')),
);
});
});
}
class _DialogTestHost extends StatelessWidget {
const _DialogTestHost({
required this.info,
this.onUpdateLater,
});
final UpgradeInfo info;
final VoidCallback? onUpdateLater;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
return Center(
child: ElevatedButton(
onPressed: () {
AppUpgradeSimple.instance.showPreparedUpgrade(
context: context,
info: info,
onUpdateLater: onUpdateLater,
config: const UpgradeConfig(
showNoUpdateToast: false,
autoInstall: false,
enableDebugLog: false,
),
);
},
child: const Text('open-upgrade-dialog'),
),
);
},
),
),
);
}
}
UpgradeInfo _buildUpgradeInfo({
bool hasUpdate = true,
String updateContent = '默认更新说明',
}) {
return UpgradeInfo(
hasUpdate: hasUpdate,
isForceUpdate: false,
versionBuildNumber: 200,
versionName: '2.0.0',
updateContent: updateContent,
currentBuildNumber: 100,
currentVersionName: '1.0.0',
);
}
Iterable<String> _richTextPlainTexts(WidgetTester tester) {
return tester
.widgetList<RichText>(find.byType(RichText))
.map((widget) => widget.text.toPlainText());
}