Files
English/kouyu_english/test/widget_test.dart
T

59 lines
2.0 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:kouyu_english/core/app_state.dart';
import 'package:kouyu_english/core/models.dart';
import 'package:kouyu_english/features/lesson/lesson_flow.dart';
import 'package:kouyu_english/main.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
testWidgets('shows the M1 welcome flow', (tester) async {
SharedPreferences.setMockInitialValues({});
await tester.pumpWidget(const KouyuEnglishApp());
await tester.pumpAndSettle();
expect(find.text('每天 20 分钟,\n说出能用的英语。'), findsOneWidget);
expect(find.text('继续'), findsOneWidget);
await tester.tap(find.text('继续'));
await tester.pumpAndSettle();
expect(find.text('从哪里开始?'), findsOneWidget);
expect(find.text('直接从第一课开始'), findsOneWidget);
});
testWidgets('writing input updates the lesson draft and enables checking', (
tester,
) async {
final state = AppState()..lessonStep = LessonStep.writing;
await tester.pumpWidget(
MaterialApp(
home: LessonFlow(state: state, onOpenDialogue: () {}, onFinish: () {}),
),
);
await tester.enterText(find.byType(TextField), 'Hello. I am Shen.');
await tester.pump();
expect(state.lessonWritingDraft, 'Hello. I am Shen.');
final check = tester.widget<FilledButton>(
find.widgetWithText(FilledButton, '检查句子'),
);
expect(check.onPressed, isNotNull);
});
testWidgets('speaking step displays use mic and play repeat buttons', (
tester,
) async {
final state = AppState()..lessonStep = LessonStep.speaking;
await tester.pumpWidget(
MaterialApp(
home: LessonFlow(state: state, onOpenDialogue: () {}, onFinish: () {}),
),
);
expect(find.text('跟读'), findsOneWidget);
expect(find.text('使用麦克风跟读'), findsOneWidget);
expect(find.text('播放跟读'), findsOneWidget);
});
}