release_schedule/test/view/movie_manager_list_test.dart

66 lines
2.4 KiB
Dart
Raw Normal View History

2023-11-16 15:07:33 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:release_schedule/api/movie_api.dart';
import 'package:release_schedule/model/dates.dart';
2023-11-16 15:07:33 +01:00
import 'package:release_schedule/model/local_movie_storage.dart';
import 'package:release_schedule/model/movie.dart';
import 'package:release_schedule/model/movie_manager.dart';
import 'package:release_schedule/view/movie_item.dart';
import 'package:release_schedule/view/movie_list.dart';
import 'package:release_schedule/view/movie_manager_list.dart';
void main() {
group('MovieManagerList', () {
testWidgets('displays movie list', (tester) async {
final manager = MovieManager(MovieApi(), LocalMovieStorage());
manager.addMovies([
MovieData(
'Movie 1',
DateWithPrecisionAndCountry(
2023-11-17 15:37:08 +01:00
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
2023-11-16 15:07:33 +01:00
MovieData(
'Movie 2',
DateWithPrecisionAndCountry(
2023-11-17 15:37:08 +01:00
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
2023-11-16 15:07:33 +01:00
]);
// pump the delay until the change is written to the cache, so no timers run when the test finishes
await tester.pump(const Duration(seconds: 5));
await tester.pumpWidget(
MaterialApp(home: Scaffold(body: MovieManagerList(manager))));
expect(find.byType(LinearProgressIndicator), findsNothing);
expect(find.byType(MovieList), findsOneWidget);
});
testWidgets('updates when new movies are added', (tester) async {
final manager = MovieManager(MovieApi(), LocalMovieStorage());
manager.addMovies([
MovieData(
'Movie 1',
DateWithPrecisionAndCountry(
2023-11-17 15:37:08 +01:00
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
2023-11-16 15:07:33 +01:00
MovieData(
'Movie 2',
DateWithPrecisionAndCountry(
2023-11-17 15:37:08 +01:00
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
2023-11-16 15:07:33 +01:00
]);
await tester.pumpWidget(
MaterialApp(home: Scaffold(body: MovieManagerList(manager))));
manager.addMovies([
MovieData(
'Movie 3',
DateWithPrecisionAndCountry(
2023-11-17 15:37:08 +01:00
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
2023-11-16 15:07:33 +01:00
]);
// pump the delay until the change is written to the cache, so no timers run when the test finishes
await tester.pump(const Duration(seconds: 5));
expect(find.byType(MovieList), findsOneWidget);
expect(find.byType(MovieItem), findsNWidgets(3));
});
});
}