tests: fix date test
parent
549f1ac827
commit
ff12d0a0c4
|
@ -4,19 +4,24 @@ import 'package:release_schedule/model/movie.dart';
|
||||||
void main() {
|
void main() {
|
||||||
group('MovieData', () {
|
group('MovieData', () {
|
||||||
test('updateWithNew() updates all fields', () {
|
test('updateWithNew() updates all fields', () {
|
||||||
final movie1 = MovieData('Title 1',
|
final movie1 = MovieData(
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US'));
|
'Title 1',
|
||||||
final movie2 = MovieData('Title 2',
|
DateWithPrecisionAndCountry(
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'UK'));
|
DateTime(2023, 1, 1), DatePrecision.day, 'US'));
|
||||||
|
final movie2 = MovieData(
|
||||||
|
'Title 2',
|
||||||
|
DateWithPrecisionAndCountry(
|
||||||
|
DateTime(2023, 1, 1), DatePrecision.day, 'UK'));
|
||||||
movie2.setDetails(releaseDates: [
|
movie2.setDetails(releaseDates: [
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US')
|
DateWithPrecisionAndCountry(
|
||||||
|
DateTime(2023, 1, 1), DatePrecision.day, 'US')
|
||||||
], genres: [
|
], genres: [
|
||||||
'Action',
|
'Action',
|
||||||
'Adventure'
|
'Adventure'
|
||||||
], titles: [
|
], titles: [
|
||||||
(title: 'Title 2', language: 'en')
|
(title: 'Title 2', language: 'en')
|
||||||
], reviews: [
|
], reviews: [
|
||||||
Review('8.5', 'John Doe', DateTime.now(), 100)
|
Review('8.5', 'John Doe', DateTime(2023, 1, 1), 100)
|
||||||
]);
|
]);
|
||||||
movie1.updateWithNew(movie2);
|
movie1.updateWithNew(movie2);
|
||||||
expect(movie1.title, equals('Title 2'));
|
expect(movie1.title, equals('Title 2'));
|
||||||
|
@ -71,17 +76,20 @@ void main() {
|
||||||
expect(movie1.same(movie2), isFalse);
|
expect(movie1.same(movie2), isFalse);
|
||||||
});
|
});
|
||||||
test('can be encoded to JSON and back', () {
|
test('can be encoded to JSON and back', () {
|
||||||
final movie = MovieData('Title 1',
|
final movie = MovieData(
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US'));
|
'Title 1',
|
||||||
|
DateWithPrecisionAndCountry(
|
||||||
|
DateTime(2023, 1, 1), DatePrecision.day, 'US'));
|
||||||
movie.setDetails(releaseDates: [
|
movie.setDetails(releaseDates: [
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US')
|
DateWithPrecisionAndCountry(
|
||||||
|
DateTime(2023, 1, 1), DatePrecision.day, 'US')
|
||||||
], genres: [
|
], genres: [
|
||||||
'Action',
|
'Action',
|
||||||
'Adventure'
|
'Adventure'
|
||||||
], titles: [
|
], titles: [
|
||||||
(title: 'Title 2', language: 'en')
|
(title: 'Title 2', language: 'en')
|
||||||
], reviews: [
|
], reviews: [
|
||||||
Review('8.5', 'John Doe', DateTime.now(), 100)
|
Review('8.5', 'John Doe', DateTime(2023, 1, 1), 100)
|
||||||
]);
|
]);
|
||||||
final json = movie.toJsonEncodable();
|
final json = movie.toJsonEncodable();
|
||||||
final movie2 = MovieData.fromJsonEncodable(json);
|
final movie2 = MovieData.fromJsonEncodable(json);
|
||||||
|
@ -102,27 +110,30 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('toString()', () {
|
test('toString()', () {
|
||||||
final movie = MovieData('Title 1',
|
final movie = MovieData(
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US'));
|
'Title 1',
|
||||||
|
DateWithPrecisionAndCountry(
|
||||||
|
DateTime(2023, 1, 1), DatePrecision.day, 'US'));
|
||||||
movie.setDetails(releaseDates: [
|
movie.setDetails(releaseDates: [
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US')
|
DateWithPrecisionAndCountry(
|
||||||
|
DateTime(2023, 1, 1), DatePrecision.day, 'US')
|
||||||
], genres: [
|
], genres: [
|
||||||
'Action',
|
'Action',
|
||||||
'Adventure'
|
'Adventure'
|
||||||
], titles: [
|
], titles: [
|
||||||
(title: 'Title 2', language: 'en')
|
(title: 'Title 2', language: 'en')
|
||||||
], reviews: [
|
], reviews: [
|
||||||
Review('8.5', 'John Doe', DateTime.now(), 100)
|
Review('8.5', 'John Doe', DateTime(2023, 1, 1), 100)
|
||||||
]);
|
]);
|
||||||
expect(movie.toString(),
|
expect(movie.toString(),
|
||||||
equals('Title 1 (November 16, 2023 (US); Action, Adventure)'));
|
equals('Title 1 (January 1, 2023 (US); Action, Adventure)'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('DateWithPrecisionAndCountry', () {
|
group('DateWithPrecisionAndCountry', () {
|
||||||
test('can be encoded to JSON and back', () {
|
test('can be encoded to JSON and back', () {
|
||||||
final date =
|
final date = DateWithPrecisionAndCountry(
|
||||||
DateWithPrecisionAndCountry(DateTime.now(), DatePrecision.day, 'US');
|
DateTime(2023, 1, 1), DatePrecision.day, 'US');
|
||||||
final json = date.toJsonEncodable();
|
final json = date.toJsonEncodable();
|
||||||
final date2 = DateWithPrecisionAndCountry.fromJsonEncodable(json);
|
final date2 = DateWithPrecisionAndCountry.fromJsonEncodable(json);
|
||||||
expect(date2.date, equals(date.date));
|
expect(date2.date, equals(date.date));
|
||||||
|
|
|
@ -16,11 +16,11 @@ void main() {
|
||||||
MovieData(
|
MovieData(
|
||||||
'Movie 1',
|
'Movie 1',
|
||||||
DateWithPrecisionAndCountry(
|
DateWithPrecisionAndCountry(
|
||||||
DateTime.now(), DatePrecision.day, 'US')),
|
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
|
||||||
MovieData(
|
MovieData(
|
||||||
'Movie 2',
|
'Movie 2',
|
||||||
DateWithPrecisionAndCountry(
|
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
|
// 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));
|
await tester.pump(const Duration(seconds: 5));
|
||||||
|
@ -38,11 +38,11 @@ void main() {
|
||||||
MovieData(
|
MovieData(
|
||||||
'Movie 1',
|
'Movie 1',
|
||||||
DateWithPrecisionAndCountry(
|
DateWithPrecisionAndCountry(
|
||||||
DateTime.now(), DatePrecision.day, 'US')),
|
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
|
||||||
MovieData(
|
MovieData(
|
||||||
'Movie 2',
|
'Movie 2',
|
||||||
DateWithPrecisionAndCountry(
|
DateWithPrecisionAndCountry(
|
||||||
DateTime.now(), DatePrecision.day, 'US')),
|
DateTime(2023, 1, 1), DatePrecision.day, 'US')),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
|
@ -52,7 +52,7 @@ void main() {
|
||||||
MovieData(
|
MovieData(
|
||||||
'Movie 3',
|
'Movie 3',
|
||||||
DateWithPrecisionAndCountry(
|
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
|
// 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));
|
await tester.pump(const Duration(seconds: 5));
|
||||||
|
|
Loading…
Reference in New Issue