137 lines
4.2 KiB
Dart
137 lines
4.2 KiB
Dart
import 'package:cyberhybridhub/models/app_user.dart';
|
||
import 'package:cyberhybridhub/models/guess_score_summary.dart';
|
||
import 'package:cyberhybridhub/screens/home_screen.dart';
|
||
import 'package:cyberhybridhub/services/questions_hub_service.dart';
|
||
import 'package:cyberhybridhub/theme/app_theme.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
testWidgets('top bar score chip opens statistics dialog', (
|
||
WidgetTester tester,
|
||
) async {
|
||
final QuestionsHubService hub = QuestionsHubService.instance;
|
||
hub.hasPendingQuestion.value = false;
|
||
hub.pendingQuestionCount.value = 0;
|
||
hub.guessScoreSummary.value = GuessScoreSummary(
|
||
total: 3.5,
|
||
answersTotal: 4,
|
||
answersCorrect: 3,
|
||
percentCorrect: 75,
|
||
slotStart: DateTime.utc(2026, 5, 26, 13, 30),
|
||
newerSlotStart: DateTime.utc(2026, 5, 26, 16, 45),
|
||
);
|
||
|
||
addTearDown(() {
|
||
hub.hasPendingQuestion.value = false;
|
||
hub.pendingQuestionCount.value = 0;
|
||
hub.guessScoreSummary.value = GuessScoreSummary.empty;
|
||
hub.scoreResetBusy.value = false;
|
||
});
|
||
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
theme: buildAppTheme(),
|
||
home: const HomeScreen(
|
||
user: AppUser(uid: 'u1', displayName: 'Test User'),
|
||
),
|
||
),
|
||
);
|
||
|
||
expect(find.byKey(const Key('topbar-cumulative-score')), findsOneWidget);
|
||
expect(find.text('Score: 3.50'), findsOneWidget);
|
||
|
||
await tester.tap(find.byKey(const Key('topbar-cumulative-score')));
|
||
await tester.pumpAndSettle();
|
||
|
||
expect(find.byKey(const Key('guess-score-stats-dialog')), findsOneWidget);
|
||
expect(find.text('Score statistics'), findsOneWidget);
|
||
expect(find.byKey(const Key('guess-score-slot-row')), findsOneWidget);
|
||
expect(find.text('Time slot'), findsOneWidget);
|
||
expect(find.text('05/26 13:30 – 05/26 16:45 UTC'), findsOneWidget);
|
||
expect(find.text('Questions answered'), findsOneWidget);
|
||
expect(find.text('4'), findsOneWidget);
|
||
expect(find.text('Percent correct'), findsOneWidget);
|
||
expect(find.text('75%'), findsOneWidget);
|
||
});
|
||
|
||
testWidgets('score statistics reset shows confirmation dialog', (
|
||
WidgetTester tester,
|
||
) async {
|
||
final QuestionsHubService hub = QuestionsHubService.instance;
|
||
hub.guessScoreSummary.value = const GuessScoreSummary(
|
||
total: 5,
|
||
answersTotal: 2,
|
||
answersCorrect: 1,
|
||
percentCorrect: 50,
|
||
);
|
||
|
||
addTearDown(() {
|
||
hub.guessScoreSummary.value = GuessScoreSummary.empty;
|
||
hub.scoreResetBusy.value = false;
|
||
});
|
||
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
theme: buildAppTheme(),
|
||
home: const HomeScreen(
|
||
user: AppUser(uid: 'u1', displayName: 'Test User'),
|
||
),
|
||
),
|
||
);
|
||
|
||
await tester.tap(find.byKey(const Key('topbar-cumulative-score')));
|
||
await tester.pumpAndSettle();
|
||
|
||
await tester.tap(find.byKey(const Key('guess-score-reset-button')));
|
||
await tester.pumpAndSettle();
|
||
|
||
expect(
|
||
find.byKey(const Key('guess-score-reset-confirm-dialog')),
|
||
findsOneWidget,
|
||
);
|
||
|
||
await tester.tap(find.text('Cancel'));
|
||
await tester.pumpAndSettle();
|
||
|
||
expect(
|
||
find.byKey(const Key('guess-score-reset-confirm-dialog')),
|
||
findsNothing,
|
||
);
|
||
expect(find.byKey(const Key('guess-score-stats-dialog')), findsOneWidget);
|
||
});
|
||
|
||
testWidgets('score reset shows blocking overlay while processing', (
|
||
WidgetTester tester,
|
||
) async {
|
||
final QuestionsHubService hub = QuestionsHubService.instance;
|
||
hub.guessScoreSummary.value = const GuessScoreSummary(
|
||
total: 5,
|
||
answersTotal: 2,
|
||
answersCorrect: 1,
|
||
percentCorrect: 50,
|
||
);
|
||
hub.scoreResetBusy.value = true;
|
||
|
||
addTearDown(() {
|
||
hub.guessScoreSummary.value = GuessScoreSummary.empty;
|
||
hub.scoreResetBusy.value = false;
|
||
});
|
||
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
theme: buildAppTheme(),
|
||
home: const HomeScreen(
|
||
user: AppUser(uid: 'u1', displayName: 'Test User'),
|
||
),
|
||
),
|
||
);
|
||
|
||
expect(
|
||
find.byKey(const Key('guess-score-reset-blocking-overlay')),
|
||
findsOneWidget,
|
||
);
|
||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||
});
|
||
}
|