2024-01-09 21:52:32 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:release_schedule/model/dates.dart';
|
|
|
|
import 'package:release_schedule/model/movie.dart';
|
|
|
|
import 'package:release_schedule/view/movie_page.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
group('MoviePage', () {
|
2024-01-10 23:50:43 +01:00
|
|
|
late MovieData movie;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
movie = MovieData()
|
|
|
|
..setNewDetails(
|
|
|
|
labels: [(text: 'The Shawshank Redemption', language: 'en')],
|
|
|
|
releaseDates: [
|
|
|
|
DateWithPrecisionAndCountry(
|
|
|
|
DateTime(1994, 9, 22), DatePrecision.day, 'US')
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
testWidgets('should render the movie details', (WidgetTester tester) async {
|
2024-01-09 21:52:32 +01:00
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: MoviePage(movie),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
expect(find.text(movie.title!), findsAtLeastNWidgets(1));
|
2024-01-09 21:52:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('should bookmark the movie', (WidgetTester tester) async {
|
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: MoviePage(movie),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
expect(movie.bookmarked, isFalse);
|
|
|
|
|
|
|
|
await tester.tap(find.byIcon(Icons.bookmark_outline));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
expect(movie.bookmarked, isTrue);
|
|
|
|
});
|
2024-01-10 23:50:43 +01:00
|
|
|
testWidgets("should display the movie's genres",
|
|
|
|
(WidgetTester tester) async {
|
|
|
|
movie.setNewDetails(genres: ['Drama']);
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: MoviePage(movie),
|
|
|
|
),
|
2024-01-09 21:52:32 +01:00
|
|
|
),
|
2024-01-10 23:50:43 +01:00
|
|
|
);
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
await tester.pumpAndSettle();
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
expect(find.text('Drama'), findsOneWidget);
|
|
|
|
});
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
testWidgets("should display the movie's titles and release dates",
|
|
|
|
(WidgetTester tester) async {
|
|
|
|
movie.setNewDetails(
|
|
|
|
titles: [(text: 'The Shawshank Redemption', language: 'en')],
|
2024-01-09 21:52:32 +01:00
|
|
|
releaseDates: [
|
|
|
|
DateWithPrecisionAndCountry(
|
|
|
|
DateTime(1994, 9, 22), DatePrecision.day, 'US')
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: MoviePage(movie),
|
|
|
|
),
|
2024-01-09 21:52:32 +01:00
|
|
|
),
|
2024-01-10 23:50:43 +01:00
|
|
|
);
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
await tester.pumpAndSettle();
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
expect(find.text('en'), findsOneWidget);
|
|
|
|
expect(find.text('The Shawshank Redemption'), findsNWidgets(2));
|
2024-01-09 21:52:32 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
expect(find.text('US'), findsOneWidget);
|
|
|
|
expect(find.textContaining('1994'), findsOneWidget);
|
|
|
|
});
|
2024-01-09 21:52:32 +01:00
|
|
|
});
|
|
|
|
}
|