tests: fix date test

main
daniel-michel 2023-11-17 15:37:08 +01:00
parent 549f1ac827
commit ff12d0a0c4
2 changed files with 33 additions and 22 deletions

View File

@ -4,19 +4,24 @@ import 'package:release_schedule/model/movie.dart';
void main() {
group('MovieData', () {
test('updateWithNew() updates all fields', () {
final movie1 = MovieData('Title 1',
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US'));
final movie2 = MovieData('Title 2',
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'UK'));
final movie1 = MovieData(
'Title 1',
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US'));
final movie2 = MovieData(
'Title 2',
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'UK'));
movie2.setDetails(releaseDates: [
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US')
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US')
], genres: [
'Action',
'Adventure'
], titles: [
(title: 'Title 2', language: 'en')
], reviews: [
Review('8.5', 'John Doe', DateTime.now(), 100)
Review('8.5', 'John Doe', DateTime(2023, 1, 1), 100)
]);
movie1.updateWithNew(movie2);
expect(movie1.title, equals('Title 2'));
@ -71,17 +76,20 @@ void main() {
expect(movie1.same(movie2), isFalse);
});
test('can be encoded to JSON and back', () {
final movie = MovieData('Title 1',
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US'));
final movie = MovieData(
'Title 1',
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US'));
movie.setDetails(releaseDates: [
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US')
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US')
], genres: [
'Action',
'Adventure'
], titles: [
(title: 'Title 2', language: 'en')
], reviews: [
Review('8.5', 'John Doe', DateTime.now(), 100)
Review('8.5', 'John Doe', DateTime(2023, 1, 1), 100)
]);
final json = movie.toJsonEncodable();
final movie2 = MovieData.fromJsonEncodable(json);
@ -102,27 +110,30 @@ void main() {
});
test('toString()', () {
final movie = MovieData('Title 1',
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US'));
final movie = MovieData(
'Title 1',
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US'));
movie.setDetails(releaseDates: [
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US')
DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US')
], genres: [
'Action',
'Adventure'
], titles: [
(title: 'Title 2', language: 'en')
], reviews: [
Review('8.5', 'John Doe', DateTime.now(), 100)
Review('8.5', 'John Doe', DateTime(2023, 1, 1), 100)
]);
expect(movie.toString(),
equals('Title 1 (November 16, 2023 (US); Action, Adventure)'));
equals('Title 1 (January 1, 2023 (US); Action, Adventure)'));
});
});
group('DateWithPrecisionAndCountry', () {
test('can be encoded to JSON and back', () {
final date =
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US');
final date = DateWithPrecisionAndCountry(
DateTime(2023, 1, 1), DatePrecision.day, 'US');
final json = date.toJsonEncodable();
final date2 = DateWithPrecisionAndCountry.fromJsonEncodable(json);
expect(date2.date, equals(date.date));

View File

@ -16,11 +16,11 @@ void main() {
MovieData(
'Movie 1',
DateWithPrecisionAndCountry(
DateTime.now(), DatePrecision.day, 'US')),
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
MovieData(
'Movie 2',
DateWithPrecisionAndCountry(
DateTime.now(), DatePrecision.day, 'US')),
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
]);
// 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));
@ -38,11 +38,11 @@ void main() {
MovieData(
'Movie 1',
DateWithPrecisionAndCountry(
DateTime.now(), DatePrecision.day, 'US')),
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
MovieData(
'Movie 2',
DateWithPrecisionAndCountry(
DateTime.now(), DatePrecision.day, 'US')),
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
]);
await tester.pumpWidget(
@ -52,7 +52,7 @@ void main() {
MovieData(
'Movie 3',
DateWithPrecisionAndCountry(
DateTime.now(), DatePrecision.day, 'US')),
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
]);
// 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));