release_schedule/test/view/home_page_test.dart

64 lines
2.2 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/main.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';
2023-11-16 15:07:33 +01:00
import 'package:release_schedule/model/movie_manager.dart';
import 'package:release_schedule/view/movie_manager_list.dart';
void main() {
group('HomePage', () {
late LocalMovieStorage storage;
setUp(() {
storage = InMemoryMovieStorage();
storage.update([
MovieData(
'The Shawshank Redemption',
DateWithPrecisionAndCountry(
DateTime(1994, 9, 22), DatePrecision.day, 'US'),
),
MovieData(
'The Godfather',
DateWithPrecisionAndCountry(
DateTime(1972, 3, 24), DatePrecision.day, 'US'),
),
MovieData(
'The Dark Knight',
DateWithPrecisionAndCountry(
DateTime(2008, 7, 18), DatePrecision.day, 'US'),
),
]);
});
2023-11-16 15:07:33 +01:00
testWidgets('displays search bar', (WidgetTester tester) async {
MovieManager movieManager = MovieManager(MovieApi(), storage);
await tester.pumpWidget(MaterialApp(home: HomePage(movieManager)));
await tester.pump(const Duration(seconds: 3));
expect(find.text('Search'), findsOneWidget);
2023-11-16 15:07:33 +01:00
});
testWidgets('displays list of releases', (WidgetTester tester) async {
MovieManager movieManager = MovieManager(MovieApi(), storage);
2023-11-16 15:07:33 +01:00
await tester.pumpWidget(MaterialApp(home: HomePage(movieManager)));
await tester.pump(const Duration(seconds: 3));
2023-11-16 15:07:33 +01:00
expect(find.byType(MovieManagerList), findsOneWidget);
});
testWidgets('displays search results', (WidgetTester tester) async {
MovieManager movieManager = MovieManager(MovieApi(), storage);
await tester.pumpWidget(MaterialApp(home: HomePage(movieManager)));
await tester.enterText(
find.byType(TextField), 'The Shawshank Redemption');
await tester.pump(const Duration(seconds: 3));
await tester.pumpAndSettle();
expect(find.text('The Shawshank Redemption'), findsNWidgets(2));
});
2023-11-16 15:07:33 +01:00
});
}