135 lines
4.1 KiB
Dart
135 lines
4.1 KiB
Dart
import 'package:cyberhybridhub/models/incoming_question.dart';
|
|
import 'package:cyberhybridhub/widgets/question_presentation_router.dart';
|
|
import 'package:cyberhybridhub/widgets/spelling_question_tile.dart';
|
|
import 'package:cyberhybridhub/widgets/swipe_question_tile.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
Future<IncomingQuestion?> _mockPrepare(String questionId) async {
|
|
return IncomingQuestion(
|
|
id: questionId,
|
|
text: 'Spell the word you hear.',
|
|
sentAt: DateTime.utc(2026, 1, 1),
|
|
sourceId: 'spelling',
|
|
presentation: 'spelling_word',
|
|
spokenWord: 'colour',
|
|
audioTitle: questionId,
|
|
canonicalWord: 'colour',
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('renders SwipeQuestionTile for market_history', (tester) async {
|
|
final IncomingQuestion question = IncomingQuestion(
|
|
id: 'market-1',
|
|
text: 'Will price move up?',
|
|
sentAt: DateTime.utc(2026, 1, 1),
|
|
sourceId: 'market_history',
|
|
presentation: 'market_glyph_slider',
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: QuestionPresentationRouter(
|
|
question: question,
|
|
onAnswer: (_) async {},
|
|
onDefer: () async {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byType(SwipeQuestionTile), findsOneWidget);
|
|
expect(find.byType(SpellingQuestionTile), findsNothing);
|
|
});
|
|
|
|
testWidgets('renders SwipeQuestionTile for spelling follow-up', (tester) async {
|
|
final IncomingQuestion question = IncomingQuestion(
|
|
id: 'spell-follow-1',
|
|
text: "Correct — 'colour' is the proper spelling. Enter +1 for another word.",
|
|
sentAt: DateTime.utc(2026, 1, 1),
|
|
sourceId: 'spelling',
|
|
presentation: 'market_glyph_slider',
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: QuestionPresentationRouter(
|
|
question: question,
|
|
onAnswer: (_) async {},
|
|
onDefer: () async {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byType(SwipeQuestionTile), findsOneWidget);
|
|
expect(find.byType(SpellingQuestionTile), findsNothing);
|
|
});
|
|
|
|
testWidgets('renders SpellingQuestionTile for spelling', (tester) async {
|
|
final IncomingQuestion question = IncomingQuestion(
|
|
id: 'spell-1',
|
|
text: 'Spell the word you hear.',
|
|
sentAt: DateTime.utc(2026, 1, 1),
|
|
sourceId: 'spelling',
|
|
presentation: 'spelling_word',
|
|
spokenWord: 'colour',
|
|
audioTitle: 'spell-1',
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: QuestionPresentationRouter(
|
|
question: question,
|
|
onAnswer: (_) async {},
|
|
onAnswerText: (_) async {},
|
|
onDefer: () async {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byType(SpellingQuestionTile), findsOneWidget);
|
|
expect(find.byType(SwipeQuestionTile), findsNothing);
|
|
expect(find.byKey(const Key('spelling-speak-word')), findsOneWidget);
|
|
expect(find.byKey(const Key('spelling-answer-field')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('spelling tile shows speaker and text field after prepare',
|
|
(tester) async {
|
|
final IncomingQuestion question = IncomingQuestion(
|
|
id: 'spell-1',
|
|
text: 'Spelling question loading…',
|
|
sentAt: DateTime.utc(2026, 1, 1),
|
|
sourceId: 'spelling',
|
|
presentation: 'spelling_word',
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SpellingQuestionTile(
|
|
questionId: question.id,
|
|
questionText: question.text,
|
|
needsPrepare: true,
|
|
prepareQuestion: _mockPrepare,
|
|
onSubmitAnswer: (_) async {},
|
|
onDefer: () async {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
|
|
expect(find.byKey(const Key('spelling-speak-word')), findsOneWidget);
|
|
expect(find.byKey(const Key('spelling-answer-field')), findsOneWidget);
|
|
expect(find.byKey(const Key('spelling-submit-answer')), findsOneWidget);
|
|
});
|
|
}
|