import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:kouyu_english/core/app_state.dart'; import 'package:kouyu_english/core/courses/courses.dart'; import 'package:kouyu_english/features/shell/learning_shell.dart'; import 'package:shared_preferences/shared_preferences.dart'; /// The word bank is reachable from its own tab, but nothing on the 学习 tab /// mentioned it, so a learner who opens the app to today's task never saw /// that words were waiting. These cover the entry point, not the quiz. void main() { setUp(() async { SharedPreferences.setMockInitialValues({}); clearCoreItems(); WordBank.instance.resetForTest(); await WordBank.instance.load(); }); tearDown(() { clearCoreItems(); WordBank.instance.resetForTest(); }); testWidgets('the 学习 tab offers a round of words and opens the word tab', ( tester, ) async { final state = AppState()..finishOnboarding(); await tester.pumpWidget(MaterialApp(home: LearningShell(state: state))); await tester.pumpAndSettle(); expect(find.text('认词'), findsOneWidget); expect(find.text('今天还能学 15 个新词'), findsOneWidget); expect(find.text('15 个题,听到、看到能认出来就行,不用会说。'), findsOneWidget); await tester.tap(find.text('开始认词')); await tester.pumpAndSettle(); expect(find.text('学过的词'), findsOneWidget); }); testWidgets('the entry stays once the day is done, as a line not a task', ( tester, ) async { final state = AppState()..finishOnboarding(); for (final question in state.wordSession()) { state.recordWordRecognition(question.id, correct: true); } await tester.pumpWidget(MaterialApp(home: LearningShell(state: state))); await tester.pumpAndSettle(); expect(state.wordSessionPreviewSize, 0); expect(find.text('开始认词'), findsNothing); expect(find.text('今天的新词学满 15 个了,明天继续'), findsOneWidget); expect(find.text('认识 15 · 熟悉 0'), findsOneWidget); await tester.tap(find.text('今天的新词学满 15 个了,明天继续')); await tester.pumpAndSettle(); expect(find.text('学过的词'), findsOneWidget); }); }