release_schedule/test/view/movie_item_test.dart

115 lines
2.7 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/model/dates.dart';
2023-11-16 15:07:33 +01:00
import 'package:release_schedule/model/movie.dart';
import 'package:release_schedule/view/movie_item.dart';
import 'package:release_schedule/view/movie_page.dart';
2023-11-16 15:07:33 +01:00
void main() {
late MovieData testMovie;
setUp(() {
testMovie = MovieData()
..setNewDetails(
labels: [(text: 'Test Movie', language: 'en')],
releaseDates: [
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US')
],
);
});
2023-11-16 15:07:33 +01:00
testWidgets('MovieItem displays movie data', (WidgetTester tester) async {
testMovie.setNewDetails(
2023-11-16 15:07:33 +01:00
genres: ['Action', 'Adventure'],
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MovieItem(testMovie),
2023-11-16 15:07:33 +01:00
),
),
);
expect(find.text('Test Movie'), findsOneWidget);
expect(find.textContaining('Action, Adventure'), findsOneWidget);
});
testWidgets('should update when the movie is modified', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MovieItem(testMovie),
2023-11-16 15:07:33 +01:00
),
),
);
expect(find.text('Test Movie'), findsOneWidget);
testMovie.setNewDetails(
2023-11-16 15:07:33 +01:00
genres: ['Action', 'Adventure', 'Comedy'],
);
await tester.pump();
expect(find.textContaining('Action, Adventure, Comedy'), findsOneWidget);
});
testWidgets('should update when the movie is bookmarked', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MovieItem(testMovie),
),
),
);
expect(find.byIcon(Icons.bookmark_border), findsOneWidget);
testMovie.setDetails(
bookmarked: true,
);
await tester.pump();
expect(find.byIcon(Icons.bookmark_added), findsOneWidget);
});
testWidgets("should update the bookmark state when the icon is tapped",
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MovieItem(testMovie),
),
),
);
expect(find.byIcon(Icons.bookmark_border), findsOneWidget);
await tester.tap(find.byIcon(Icons.bookmark_outline));
await tester.pump();
expect(find.byIcon(Icons.bookmark_added), findsOneWidget);
});
testWidgets("should navigate to MoviePage when tapped", (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MovieItem(testMovie),
),
),
);
expect(find.byIcon(Icons.bookmark_border), findsOneWidget);
await tester.tap(find.byType(ListTile));
await tester.pumpAndSettle();
expect(find.byType(MoviePage), findsOneWidget);
});
2023-11-16 15:07:33 +01:00
}