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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user