cyberhybridhub/test/widgets/spelling_question_tile_test.dart
2026-06-06 19:23:18 +00:00

76 lines
2.2 KiB
Dart

import 'package:cyberhybridhub/theme/app_theme.dart';
import 'package:cyberhybridhub/widgets/spelling_question_tile.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('shows green canonical word then submits after one second', (tester) async {
var submitCount = 0;
await tester.pumpWidget(
MaterialApp(
theme: buildAppTheme(),
home: Scaffold(
body: SpellingQuestionTile(
questionId: 'spell-1',
questionText: 'Spell the word you hear.',
spokenWord: 'colour',
canonicalWord: 'colour',
onSubmitAnswer: (_) async {
submitCount++;
},
onDefer: () async {},
),
),
),
);
await tester.enterText(find.byKey(const Key('spelling-answer-field')), 'colour');
await tester.tap(find.byKey(const Key('spelling-submit-answer')));
await tester.pump();
expect(submitCount, 1);
final Text feedback = tester.widget<Text>(
find.byKey(const Key('spelling-feedback-word')),
);
expect(feedback.data, 'colour');
expect(feedback.style?.color, AppColors.success);
await tester.pump(const Duration(seconds: 1));
await tester.pump();
expect(submitCount, 1);
});
testWidgets('shows red canonical word when answer is wrong', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: buildAppTheme(),
home: Scaffold(
body: SpellingQuestionTile(
questionId: 'spell-2',
questionText: 'Spell the word you hear.',
spokenWord: 'colour',
canonicalWord: 'colour',
onSubmitAnswer: (_) async {},
onDefer: () async {},
),
),
),
);
await tester.enterText(find.byKey(const Key('spelling-answer-field')), 'color');
await tester.tap(find.byKey(const Key('spelling-submit-answer')));
await tester.pump();
final Text feedback = tester.widget<Text>(
find.byKey(const Key('spelling-feedback-word')),
);
expect(feedback.data, 'colour');
expect(feedback.style?.color, AppColors.error);
await tester.pump(const Duration(seconds: 1));
await tester.pump();
});
}