diff --git a/pubspec.lock b/pubspec.lock index fc8ae22..d59fe69 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,30 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7" + url: "https://pub.dev" + source: hosted + version: "67.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d" + url: "https://pub.dev" + source: hosted + version: "6.4.1" + args: + dependency: transitive + description: + name: args + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + url: "https://pub.dev" + source: hosted + version: "2.5.0" async: dependency: transitive description: @@ -17,6 +41,14 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.4" + bloc_test: + dependency: "direct dev" + description: + name: bloc_test + sha256: "165a6ec950d9252ebe36dc5335f2e6eb13055f33d56db0eeb7642768849b43d2" + url: "https://pub.dev" + source: hosted + version: "9.1.7" boolean_selector: dependency: transitive description: @@ -73,6 +105,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + sha256: "3945034e86ea203af7a056d98e98e42a5518fff200d6e8e6647e1886b07e936e" + url: "https://pub.dev" + source: hosted + version: "1.8.0" crypto: dependency: transitive description: @@ -81,6 +129,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" + diff_match_patch: + dependency: transitive + description: + name: diff_match_patch + sha256: "2efc9e6e8f449d0abe15be240e2c2a3bcd977c8d126cfd70598aee60af35c0a4" + url: "https://pub.dev" + source: hosted + version: "0.4.1" equatable: dependency: "direct main" description: @@ -155,6 +211,22 @@ packages: description: flutter source: sdk version: "0.0.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" http: dependency: "direct main" description: @@ -163,6 +235,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" http_parser: dependency: transitive description: @@ -179,6 +259,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" leak_tracker: dependency: transitive description: @@ -211,6 +307,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" matcher: dependency: transitive description: @@ -235,6 +339,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.0" + mime: + dependency: transitive + description: + name: mime + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" + url: "https://pub.dev" + source: hosted + version: "1.0.5" + mocktail: + dependency: "direct dev" + description: + name: mocktail + sha256: c4b5007d91ca4f67256e720cb1b6d704e79a510183a12fa551021f652577dce6 + url: "https://pub.dev" + source: hosted + version: "1.0.3" nested: dependency: transitive description: @@ -243,6 +363,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" octo_image: dependency: transitive description: @@ -251,6 +379,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" path: dependency: transitive description: @@ -323,6 +459,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.8" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" provider: dependency: transitive description: @@ -331,6 +475,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.2" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" rxdart: dependency: transitive description: @@ -339,11 +491,59 @@ packages: url: "https://pub.dev" source: hosted version: "0.27.7" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" source_span: dependency: transitive description: @@ -416,6 +616,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" + test: + dependency: transitive + description: + name: test + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + url: "https://pub.dev" + source: hosted + version: "1.24.9" test_api: dependency: transitive description: @@ -424,6 +632,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.1" + test_core: + dependency: transitive + description: + name: test_core + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + url: "https://pub.dev" + source: hosted + version: "0.5.9" typed_data: dependency: transitive description: @@ -456,6 +672,14 @@ packages: url: "https://pub.dev" source: hosted version: "13.0.0" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" web: dependency: transitive description: @@ -464,6 +688,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: "58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42" + url: "https://pub.dev" + source: hosted + version: "2.4.5" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" win32: dependency: transitive description: @@ -480,6 +720,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" sdks: dart: ">=3.3.2 <4.0.0" flutter: ">=3.16.0" diff --git a/pubspec.yaml b/pubspec.yaml index 0a0c5c3..d7ab85d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,6 +20,8 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^3.0.0 + bloc_test: ^9.1.7 + mocktail: ^1.0.3 flutter: uses-material-design: true diff --git a/test/features/picture_of_the_day/presentation/cubits/picture_of_the_day/picture_of_the_day_cubit_test.dart b/test/features/picture_of_the_day/presentation/cubits/picture_of_the_day/picture_of_the_day_cubit_test.dart new file mode 100644 index 0000000..6b217a8 --- /dev/null +++ b/test/features/picture_of_the_day/presentation/cubits/picture_of_the_day/picture_of_the_day_cubit_test.dart @@ -0,0 +1,111 @@ +import 'package:bloc_test/bloc_test.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:nasa_potday/features/picture_of_the_day/domain/entities/picture_entity.dart'; +import 'package:nasa_potday/features/picture_of_the_day/domain/entities/pictures_page_entity.dart'; +import 'package:nasa_potday/features/picture_of_the_day/domain/repositories/nasa_repository.dart'; +import 'package:nasa_potday/features/picture_of_the_day/presentation/cubits/picture_of_the_day/picture_of_the_day_cubit.dart'; + +class NasaRepositoryMock extends Mock implements NasaRepository {} + +void main() { + late NasaRepository nasaRepository; + late PictureOfTheDayCubit cubit; + + setUp(() { + nasaRepository = NasaRepositoryMock(); + cubit = PictureOfTheDayCubit(nasaRepository: nasaRepository); + }); + + final currentStartDate = DateTime(2024, 5, 7); + final pageWithoutPictures = PicturesPageEntity( + pictures: [], + startDate: currentStartDate, + ); + final firstPageWithPictures = PicturesPageEntity( + pictures: [ + PictureEntity( + url: Uri.parse( + 'https://apod.nasa.gov/apod/image/2405/BlackHole_Simonnet_960.jpg'), + explanation: 'some explanation', + title: 'Black Hole Accreting with Jet', + date: DateTime(2024, 5, 7), + isVideo: false, + ), + ], + startDate: currentStartDate, + ); + final secondPageWithPictures = PicturesPageEntity( + pictures: [ + PictureEntity( + url: Uri.parse( + 'https://apod.nasa.gov/apod/image/2405/BlackHole_Simonnet_960.jpg'), + explanation: 'some explanation', + title: 'Black Hole Accreting with Jet', + date: DateTime(2024, 5, 6), + isVideo: false, + ), + ], + startDate: DateTime(2024, 5, 6), + ); + + blocTest( + 'emits [PictureOfTheDayLoading, PictureOfTheDayFailed] when no pictures are loaded', + build: () => cubit, + setUp: () { + when(() => nasaRepository.loadInitialPage()).thenAnswer( + (_) async => pageWithoutPictures, + ); + }, + act: (cubit) => cubit.loadPictureOfTheDay(), + expect: () => const [ + PictureOfTheDayLoading(), + PictureOfTheDayFailed(), + ], + ); + + blocTest( + 'emits [PictureOfTheDayLoading, PictureOfTheDayLoaded] when there are pictures loaded', + build: () => cubit, + setUp: () { + when(() => nasaRepository.loadInitialPage()).thenAnswer( + (_) async => firstPageWithPictures, + ); + }, + act: (cubit) => cubit.loadPictureOfTheDay(), + expect: () => [ + const PictureOfTheDayLoading(), + PictureOfTheDayLoaded( + page: firstPageWithPictures, + isLoadingMore: false, + ), + ], + ); + + blocTest( + 'emits [PictureOfTheDayLoaded, PictureOfTheDayLoaded] when it loads more pictures', + build: () => cubit, + seed: () => PictureOfTheDayLoaded( + isLoadingMore: false, + page: firstPageWithPictures, + ), + setUp: () { + when(() => + nasaRepository.loadNextPage(currentStartDate: currentStartDate)) + .thenAnswer( + (_) async => secondPageWithPictures, + ); + }, + act: (cubit) => cubit.loadNextPage(), + expect: () => [ + PictureOfTheDayLoaded( + page: firstPageWithPictures, + isLoadingMore: true, + ), + PictureOfTheDayLoaded( + page: firstPageWithPictures.merge(secondPageWithPictures), + isLoadingMore: false, + ), + ], + ); +}