release_schedule/test/view/movie_manager_list_test.dart

74 lines
2.6 KiB
Dart
Raw Permalink 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', () {
late List<MovieData> movies;
setUp(() {
movies = [
MovieData()
..setNewDetails(
labels: [(text: 'Movie 1', language: 'en')],
releaseDates: [
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US')
],
),
MovieData()
..setNewDetails(
labels: [(text: 'Movie 2', language: 'en')],
releaseDates: [
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US')
],
)
];
});
2023-11-16 15:07:33 +01:00
testWidgets('displays movie list', (tester) async {
final manager = MovieManager(MovieApi(), InMemoryMovieStorage());
manager.addMovies(movies);
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(), InMemoryMovieStorage());
manager.addMovies(movies);
2023-11-16 15:07:33 +01:00
await tester.pumpWidget(
MaterialApp(home: Scaffold(body: MovieManagerList(manager))));
manager.addMovies([
MovieData()
..setNewDetails(
labels: [(text: 'Movie 3', language: 'en')],
releaseDates: [
DateWithPrecisionAndCountry(
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));
});
});
}