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';
|
2024-01-09 21:52:32 +01:00
|
|
|
import 'package:release_schedule/model/dates.dart';
|
2023-11-16 15:07:33 +01:00
|
|
|
import 'package:release_schedule/model/local_movie_storage.dart';
|
2024-01-09 21:52:32 +01:00
|
|
|
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', () {
|
2024-01-09 21:52:32 +01:00
|
|
|
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
|
|
|
|
2024-01-09 21:52:32 +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));
|
2024-01-08 21:48:13 +01:00
|
|
|
expect(find.text('Search'), findsOneWidget);
|
2023-11-16 15:07:33 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('displays list of releases', (WidgetTester tester) async {
|
2024-01-09 21:52:32 +01:00
|
|
|
MovieManager movieManager = MovieManager(MovieApi(), storage);
|
2023-11-16 15:07:33 +01:00
|
|
|
await tester.pumpWidget(MaterialApp(home: HomePage(movieManager)));
|
2024-01-09 21:52:32 +01:00
|
|
|
await tester.pump(const Duration(seconds: 3));
|
2023-11-16 15:07:33 +01:00
|
|
|
|
|
|
|
expect(find.byType(MovieManagerList), findsOneWidget);
|
|
|
|
});
|
2024-01-09 21:52:32 +01:00
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|