Files
English/kouyu_english/test/dialogue_translation_test.dart

89 lines
2.8 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:kouyu_english/core/app_state.dart';
import 'package:kouyu_english/core/courses/courses.dart';
import 'package:kouyu_english/features/dialogue/dialogue_flow.dart';
void main() {
testWidgets(
'Dialogue bottom translation chip displays latest partner translation',
(WidgetTester tester) async {
final state = AppState();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: DialoguePage(
state: state,
onFinished: (_) {},
isLessonDialogue: false,
),
),
),
);
await tester.pumpAndSettle();
// Initial partner prompt is displayed
expect(
find.text('Hi! My name is Mia. Whats your name?'),
findsOneWidget,
);
// Click the bottom "翻译" assist chip
final bottomTranslateChip = find.widgetWithText(ActionChip, '翻译');
expect(bottomTranslateChip, findsOneWidget);
await tester.tap(bottomTranslateChip);
await tester.pumpAndSettle();
// Hint banner displays the latest AI translation
expect(find.text('对方说:嗨!我叫 Mia。你叫什么名字?'), findsOneWidget);
// Message bubble also shows the inline translation
expect(find.text('嗨!我叫 Mia。你叫什么名字?'), findsOneWidget);
expect(find.text('隐藏翻译'), findsOneWidget);
// Tap "隐藏翻译" on the bubble to hide it
await tester.tap(find.text('隐藏翻译'));
await tester.pumpAndSettle();
expect(
find.text('翻译'),
findsWidgets,
); // Both the bottom chip and bubble button
},
);
testWidgets(
'Course lesson dialogue resolves translations correctly for lesson prompts',
(WidgetTester tester) async {
final state = AppState()..activeLessonId = 'a0-02';
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: DialoguePage(
state: state,
onFinished: (_) {},
isLessonDialogue: true,
),
),
),
);
await tester.pumpAndSettle();
// Lesson a0-02 initial prompt
final expectedPrompt = segmentDialogues['a0-02-a']!.prompts.first;
expect(find.text(expectedPrompt), findsOneWidget);
// Tap bubble's "翻译" button
final bubbleTranslateBtn = find.text('翻译').first;
await tester.tap(bubbleTranslateBtn);
await tester.pumpAndSettle();
// Check translation is shown
final expectedTranslation =
segmentDialogues['a0-02-a']!.translations.first;
expect(find.text(expectedTranslation), findsOneWidget);
expect(find.text('隐藏翻译'), findsOneWidget);
},
);
}