update
This commit is contained in:
1 parent
97c10c8d12
commit
212410f716
10 files changed
+1061
-32
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/data/repositories/match_repository.dart';
|
||||
import 'package:mobile_app/ui/features/dashboard/view_models/match_results_view_model.dart';
|
||||
@@ -6,18 +8,58 @@ void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('loads match results and their events from bundled JSON', () async {
|
||||
final viewModel = MatchResultsViewModel(repository: MatchRepository());
|
||||
final matches = await MatchRepository().loadSourceMatches();
|
||||
|
||||
expect(matches, hasLength(21));
|
||||
expect(matches.first.homeScore, 1);
|
||||
expect(matches.first.goals, hasLength(2));
|
||||
expect(matches.first.goals.first.seconds, 88);
|
||||
expect(matches.first.goals.first.team.name, 'away');
|
||||
expect(matches.first.cards.first.cardType.name, 'red');
|
||||
});
|
||||
|
||||
test('simulates periodic receipt and persists received matches', () async {
|
||||
final directory = await Directory.systemTemp.createTemp('match-results-');
|
||||
addTearDown(() => directory.delete(recursive: true));
|
||||
final repository = MatchRepository(
|
||||
documentsDirectoryProvider: () async => directory,
|
||||
);
|
||||
final viewModel = MatchResultsViewModel(
|
||||
repository: repository,
|
||||
updateInterval: const Duration(milliseconds: 10),
|
||||
);
|
||||
addTearDown(viewModel.dispose);
|
||||
|
||||
await viewModel.loadMatches();
|
||||
expect(viewModel.matches, hasLength(1));
|
||||
|
||||
await Future<void>.delayed(const Duration(milliseconds: 30));
|
||||
|
||||
expect(viewModel.matches.length, greaterThan(1));
|
||||
final storedData = await repository.loadStoredData();
|
||||
expect(storedData.matches, hasLength(viewModel.matches.length));
|
||||
expect(storedData.sourceCursor, viewModel.matches.length);
|
||||
});
|
||||
|
||||
test('resumes simulation from the persisted source cursor', () async {
|
||||
final directory = await Directory.systemTemp.createTemp('match-results-');
|
||||
addTearDown(() => directory.delete(recursive: true));
|
||||
final repository = MatchRepository(
|
||||
documentsDirectoryProvider: () async => directory,
|
||||
);
|
||||
final sourceMatches = await repository.loadSourceMatches();
|
||||
await repository.saveStoredData([sourceMatches.first], 1);
|
||||
final viewModel = MatchResultsViewModel(
|
||||
repository: repository,
|
||||
updateInterval: const Duration(hours: 1),
|
||||
);
|
||||
addTearDown(viewModel.dispose);
|
||||
|
||||
await viewModel.loadMatches();
|
||||
|
||||
expect(viewModel.isLoading, isFalse);
|
||||
expect(viewModel.errorMessage, isNull);
|
||||
expect(viewModel.matches, hasLength(3));
|
||||
expect(viewModel.matches.first.homeScore, 1);
|
||||
expect(viewModel.matches.first.goals, hasLength(2));
|
||||
expect(viewModel.matches.first.goals.first.seconds, 88);
|
||||
expect(viewModel.matches.first.goals.first.team.name, 'away');
|
||||
expect(viewModel.matches.first.cards.first.cardType.name, 'red');
|
||||
expect(viewModel.matches, hasLength(2));
|
||||
expect(viewModel.matches.first.datetime, sourceMatches.first.datetime);
|
||||
expect(viewModel.matches.last.datetime, sourceMatches[1].datetime);
|
||||
expect((await repository.loadStoredData()).sourceCursor, 2);
|
||||
});
|
||||
}
|
||||
@@ -1,30 +1,41 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/app.dart';
|
||||
import 'package:mobile_app/data/repositories/match_repository.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('App smoke test - renders match results, navigates to settings', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(const MobileApp());
|
||||
final directory = await Directory.systemTemp.createTemp('match-results-');
|
||||
addTearDown(() => directory.delete(recursive: true));
|
||||
await tester.pumpWidget(
|
||||
MobileApp(
|
||||
matchRepository: MatchRepository(
|
||||
documentsDirectoryProvider: () async => directory,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Match Results'), findsOneWidget);
|
||||
expect(find.text('Home'), findsWidgets);
|
||||
expect(find.text('Away'), findsWidgets);
|
||||
expect(
|
||||
find.textContaining(RegExp(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}')),
|
||||
find.textContaining(RegExp(r'[A-Z][a-z]{2} \d{2}-\d{2}-\d{2} \d{2}:\d{2}')),
|
||||
findsWidgets,
|
||||
);
|
||||
expect(find.text('Field goal · Away · #32'), findsNothing);
|
||||
expect(find.byType(ExpansionTile), findsWidgets);
|
||||
|
||||
await tester.tap(
|
||||
find.textContaining(RegExp(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}')).first,
|
||||
find.textContaining(RegExp(r'[A-Z][a-z]{2} \d{2}-\d{2}-\d{2} \d{2}:\d{2}')).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Field goal · Away · #32'), findsWidgets);
|
||||
expect(find.textContaining('card · Away · #5 · 120s'), findsWidgets);
|
||||
expect(find.text('Field goal'), findsWidgets);
|
||||
expect(find.text('Away'), findsWidgets);
|
||||
expect(find.byType(Divider), findsNothing);
|
||||
final matchTile = tester.widget<ExpansionTile>(
|
||||
find.byType(ExpansionTile).first,
|
||||
@@ -49,5 +60,14 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Match Results'), findsOneWidget);
|
||||
|
||||
final firstMatchFinder = find.byType(Dismissible).first;
|
||||
final firstMatch = tester.widget<Dismissible>(firstMatchFinder);
|
||||
final firstMatchKey = firstMatch.key;
|
||||
|
||||
await tester.fling(firstMatchFinder, const Offset(-600, 0), 1000);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(firstMatchKey!), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user