From 3bae9af3466e3558f6513655d995a84c812aba9d Mon Sep 17 00:00:00 2001 From: "hector.aguero.brisso" Date: Wed, 1 May 2024 06:41:56 +0000 Subject: [PATCH] Add some tests with Google IDX ide --- .idx/dev.nix | 41 +++++++++ pubspec.lock | 4 +- test/features/schools/schools_repo_test.dart | 94 ++++++++++++++++++++ 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 .idx/dev.nix diff --git a/.idx/dev.nix b/.idx/dev.nix new file mode 100644 index 0000000..7051cf9 --- /dev/null +++ b/.idx/dev.nix @@ -0,0 +1,41 @@ +{pkgs}: { + channel = "stable-23.11"; + packages = [ + pkgs.nodePackages.firebase-tools + pkgs.jdk17 + pkgs.unzip + ]; + idx.extensions = [ + + ]; + idx.previews = { + previews = { + web = { + command = [ + "flutter" + "run" + "--machine" + "-d" + "web-server" + "--web-hostname" + "0.0.0.0" + "--web-port" + "$PORT" + ]; + manager = "flutter"; + }; + android = { + command = [ + "flutter" + "run" + "--machine" + "-d" + "android" + "-d" + "emulator-5554" + ]; + manager = "flutter"; + }; + }; + }; +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 69c3c7d..634b16d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1134,10 +1134,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: a75f83f14ad81d5fe4b3319710b90dec37da0e22612326b696c9e1b8f34bbf48 url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.0" watcher: dependency: transitive description: diff --git a/test/features/schools/schools_repo_test.dart b/test/features/schools/schools_repo_test.dart index 8b13789..cacca20 100644 --- a/test/features/schools/schools_repo_test.dart +++ b/test/features/schools/schools_repo_test.dart @@ -1 +1,95 @@ +import 'package:batucadapp/features/schools/school.dart'; +import 'package:batucadapp/features/schools/schools_repo.dart'; +import 'package:batucadapp/utils/immutable_list.dart'; +import 'package:dio/dio.dart'; +import 'package:fast_immutable_collections/fast_immutable_collections.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import '../../create_container.dart'; + +class SchoolsRepoMock with Mock implements SchoolsRepoImpls {} + +void main() { + group('Schools Repository', () { + test( + ''' + When SchoolsRepo is called + Should return a instance of SchoolsRepoImpls + ''', + () { + final mock = SchoolsRepoMock(); + final container = createContainer( + overrides: [schoolsRepoProvider.overrideWith((_) => mock)], + ); + + expect( + container.read(schoolsRepoProvider), + isA(), + ); + }, + ); + + test(''' + When SchoolsRepo.getSchools is called + Should return a list of Schools + ''', () async { + const page = 1; + const pageSize = 10; + final mock = SchoolsRepoMock(); + when( + () => mock.getSchools( + page: any(named: 'page'), + pageSize: any(named: 'pageSize'), + sort: any(named: 'sort'), + search: any(named: 'search'), + ), + ).thenAnswer((_) async => [].lock); + + final container = createContainer( + overrides: [schoolsRepoProvider.overrideWith((_) => mock)], + ); + + expect( + await container.read(schoolsRepoProvider).getSchools( + page: page, + pageSize: pageSize, + sort: 'name', + search: '', + ), + isA>(), + ); + }); + + test(''' + When SchoolsRepo.getSchools is called + Should throw an error + ''', () async { + const page = 1; + const pageSize = 10; + final mock = SchoolsRepoMock(); + when( + () => mock.getSchools( + page: any(named: 'page'), + pageSize: any(named: 'pageSize'), + sort: any(named: 'sort'), + search: any(named: 'search'), + ), + ).thenThrow(DioException(requestOptions: RequestOptions())); + + final container = createContainer( + overrides: [schoolsRepoProvider.overrideWith((_) => mock)], + ); + + expect( + () => container.read(schoolsRepoProvider).getSchools( + page: page, + pageSize: pageSize, + sort: 'name', + search: '', + ), + throwsA(isA()), + ); + }); + }); +}