Skip to content

Commit

Permalink
Add some tests with Google IDX ide
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorAguero committed May 1, 2024
1 parent bdda626 commit 3bae9af
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .idx/dev.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
};
}
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
94 changes: 94 additions & 0 deletions test/features/schools/schools_repo_test.dart
Original file line number Diff line number Diff line change
@@ -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<SchoolsRepoImpls>(),
);
},
);

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 => <School>[].lock);

final container = createContainer(
overrides: [schoolsRepoProvider.overrideWith((_) => mock)],
);

expect(
await container.read(schoolsRepoProvider).getSchools(
page: page,
pageSize: pageSize,
sort: 'name',
search: '',
),
isA<ImmutableList<School>>(),
);
});

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<DioException>()),
);
});
});
}

0 comments on commit 3bae9af

Please sign in to comment.