74 lines
2.7 KiB
Dart
74 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:mobile/main.dart';
|
|
|
|
/// 在导航栏内按标签定位,避免和页面标题的相同文字混淆。
|
|
Finder navLabel(String label) {
|
|
return find.descendant(
|
|
of: find.byType(NavigationBar),
|
|
matching: find.text(label),
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('底部导航提供学习 / 管理 / 统计 / 账户四个入口', (WidgetTester tester) async {
|
|
await tester.pumpWidget(const KiriMemoApp());
|
|
|
|
expect(find.byType(NavigationBar), findsOneWidget);
|
|
expect(find.byType(NavigationDestination), findsNWidgets(4));
|
|
|
|
for (final String label in <String>['学习', '管理', '统计', '账户']) {
|
|
expect(navLabel(label), findsOneWidget);
|
|
}
|
|
});
|
|
|
|
testWidgets('默认停留在学习页,点击其它入口会切换', (WidgetTester tester) async {
|
|
await tester.pumpWidget(const KiriMemoApp());
|
|
|
|
NavigationBar bar = tester.widget<NavigationBar>(find.byType(NavigationBar));
|
|
expect(bar.selectedIndex, 0);
|
|
|
|
await tester.tap(navLabel('统计'));
|
|
await tester.pumpAndSettle();
|
|
|
|
bar = tester.widget<NavigationBar>(find.byType(NavigationBar));
|
|
expect(bar.selectedIndex, 2);
|
|
|
|
await tester.tap(navLabel('账户'));
|
|
await tester.pumpAndSettle();
|
|
|
|
bar = tester.widget<NavigationBar>(find.byType(NavigationBar));
|
|
expect(bar.selectedIndex, 3);
|
|
});
|
|
|
|
testWidgets('学习首页展示今日任务与唯一主行动', (WidgetTester tester) async {
|
|
await tester.pumpWidget(const KiriMemoApp());
|
|
|
|
expect(find.text('今日计划'), findsOneWidget);
|
|
expect(find.text('待复习'), findsOneWidget);
|
|
expect(find.text('待新识'), findsOneWidget);
|
|
expect(find.text('开始学习'), findsOneWidget);
|
|
|
|
// 顶部状态标识:接力用闪电、同步用云图标,不再用文字表达状态。
|
|
expect(find.byIcon(Icons.bolt_rounded), findsOneWidget);
|
|
expect(find.text('今日记忆'), findsOneWidget);
|
|
expect(find.text('59'), findsOneWidget);
|
|
expect(find.byIcon(Icons.cloud_done_rounded), findsOneWidget);
|
|
expect(find.byTooltip('搜索条目'), findsOneWidget);
|
|
expect(find.byTooltip('学习日志'), findsOneWidget);
|
|
|
|
// 学习域的四个快捷入口。
|
|
for (final String label in <String>['收藏夹', '自我测试', '附带资料', '计划设置']) {
|
|
expect(find.text(label), findsOneWidget);
|
|
}
|
|
|
|
// 未接入内核的入口点击后要有反馈,不能静默无响应。
|
|
await tester.tap(find.text('开始学习'));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
|
|
expect(find.text('学习会话 尚未接入内核'), findsOneWidget);
|
|
});
|
|
}
|