Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken tests #112

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
distribution: "zulu"
java-version: "11"

- name: Install Flutter
uses: subosito/[email protected]
with:
channel: 'stable'
channel: "stable"
cache: true

- name: Install dependencies
Expand Down Expand Up @@ -46,13 +46,13 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
distribution: "zulu"
java-version: "17"

- name: Install Flutter
uses: subosito/[email protected]
with:
channel: 'stable'
channel: "stable"
cache: true

- name: Install dependencies
Expand Down Expand Up @@ -81,13 +81,13 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
distribution: "zulu"
java-version: "11"

- name: Install Flutter
uses: subosito/[email protected]
with:
channel: 'stable'
channel: "stable"
cache: true

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
5 changes: 5 additions & 0 deletions assets/data/test-repository.json
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,11 @@
"hexColor": "#ffe91e63",
"id": "-1",
"title": "Cosmere"
},
{
"hexColor": "ff7d20ff",
"id": "-NpiIcSZtSUTijwQSriX",
"title": "purple"
}
],
"language": "en",
Expand Down
19 changes: 0 additions & 19 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ PODS:
- AppAuth/Core (1.7.6)
- AppAuth/ExternalUserAgent (1.7.6):
- AppAuth/Core
- cupertino_http (0.0.1):
- Flutter
- FlutterMacOS
- device_info_plus (0.0.1):
- Flutter
- DKImagePickerController/Core (4.3.9):
Expand Down Expand Up @@ -240,8 +237,6 @@ PODS:
- nanopb/encode (= 3.30910.0)
- nanopb/decode (3.30910.0)
- nanopb/encode (3.30910.0)
- objective_c (0.0.1):
- Flutter
- package_info_plus (0.4.5):
- Flutter
- path_provider_foundation (0.0.1):
Expand All @@ -250,8 +245,6 @@ PODS:
- PromisesObjC (2.4.0)
- PromisesSwift (2.4.0):
- PromisesObjC (= 2.4.0)
- realm (20.0.1):
- Flutter
- RecaptchaInterop (100.0.0)
- SDWebImage (5.20.0):
- SDWebImage/Core (= 5.20.0)
Expand All @@ -269,7 +262,6 @@ PODS:
- Flutter

DEPENDENCIES:
- cupertino_http (from `.symlinks/plugins/cupertino_http/darwin`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`)
Expand All @@ -282,10 +274,8 @@ DEPENDENCIES:
- flutter_barcode_scanner (from `.symlinks/plugins/flutter_barcode_scanner/ios`)
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/darwin`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- objective_c (from `.symlinks/plugins/objective_c/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- realm (from `.symlinks/plugins/realm/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
Expand Down Expand Up @@ -326,8 +316,6 @@ SPEC REPOS:
- SwiftyGif

EXTERNAL SOURCES:
cupertino_http:
:path: ".symlinks/plugins/cupertino_http/darwin"
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
file_picker:
Expand All @@ -352,14 +340,10 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/google_sign_in_ios/darwin"
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
objective_c:
:path: ".symlinks/plugins/objective_c/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
realm:
:path: ".symlinks/plugins/realm/ios"
share_plus:
:path: ".symlinks/plugins/share_plus/ios"
shared_preferences_foundation:
Expand All @@ -371,7 +355,6 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
AppAuth: d4f13a8fe0baf391b2108511793e4b479691fb73
cupertino_http: 94ac07f5ff090b8effa6c5e2c47871d48ab7c86c
device_info_plus: 21fcca2080fbcd348be798aa36c3e5ed849eefbe
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
Expand Down Expand Up @@ -409,12 +392,10 @@ SPEC CHECKSUMS:
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a
leveldb-library: cc8b8f8e013647a295ad3f8cd2ddf49a6f19be19
nanopb: fad817b59e0457d11a5dfbde799381cd727c1275
objective_c: 89e720c30d716b036faf9c9684022048eee1eee2
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
PromisesSwift: 9d77319bbe72ebf6d872900551f7eeba9bce2851
realm: 6ccbb161b166bb539c3204f40e58763c293e4802
RecaptchaInterop: 7d1a4a01a6b2cb1610a47ef3f85f0c411434cb21
SDWebImage: 73c6079366fea25fa4bb9640d5fb58f0893facd8
share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
Expand Down
11 changes: 9 additions & 2 deletions lib/providers/book_label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:dantex/models/book.dart';
import 'package:dantex/models/book_label.dart';
import 'package:dantex/providers/book.dart';
import 'package:dantex/providers/repository.dart';
import 'package:dantex/providers/service.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

Expand All @@ -11,11 +12,17 @@ part 'book_label.g.dart';
List<Book> booksWithLabel(Ref ref, String labelId) {
return ref.watch(allBooksProvider).when(
data: (books) {
return books
final thing = books
.where((book) => book.labels.map((e) => e.id).contains(labelId))
.toList();
return thing;
},
error: (e, s) {
ref
.read(loggerProvider)
.e('Failed to get all books', error: e, stackTrace: s);
return [];
},
error: (e, s) => [],
loading: () => [],
);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/providers/statistics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'statistics.g.dart';

typedef BookCount = ({int readLaterCount, int readingCount, int readCount});
const zeroBookCount = (readLaterCount: 0, readingCount: 0, readCount: 0);

@riverpod
({int readLaterCount, int readingCount, int readCount}) bookCounts(Ref ref) {
BookCount bookCounts(Ref ref) {
final books = ref.watch(allBooksProvider);

return books.when(
Expand All @@ -37,10 +38,11 @@ const zeroBookCount = (readLaterCount: 0, readingCount: 0, readCount: 0);
);
}

typedef PageCount = ({int pagesWaiting, int pagesRead});
const zeroPageCount = (pagesWaiting: 0, pagesRead: 0);

@riverpod
({int pagesWaiting, int pagesRead}) pageCounts(Ref ref) {
PageCount pageCounts(Ref ref) {
final books = ref.watch(allBooksProvider);

return books.when(
Expand Down
105 changes: 105 additions & 0 deletions test/providers/book_label_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'package:dantex/providers/auth.dart';
import 'package:dantex/providers/book.dart';
import 'package:dantex/providers/book_label.dart';
import 'package:dantex/providers/firebase.dart';
import 'package:firebase_auth_mocks/firebase_auth_mocks.dart';
import 'package:flutter_test/flutter_test.dart';

import '../test_utilities.dart';

void main() async {
group('Given an allBookLabelsProvider', () {
group('When the repo has book labels', () {
test('Then the provider returns all book labels', () async {
final mockDatabase = await getMockDatabase();

final mockUser = MockUser(
uid: 'userId',
email: '[email protected]',
displayName: 'Bob',
);

final container = createContainer(
overrides: [
authStateChangesProvider.overrideWith(
(ref) => Stream.value(mockUser),
),
firebaseDatabaseProvider.overrideWithValue(mockDatabase),
],
);

final subscription = container.listen(
allBookLabelsProvider.future,
(_, __) {},
);
await container.pump();

final labels = await subscription.read();
expect(labels, hasLength(1));
});
});
});
group('Given a booksWithLabelProvider', () {
group("When the label doesn't exist in the repo", () {
test('Then the provider returns an empty list', () async {
final mockBook = getMockBook().copyWith(
labels: [
getMockBookLabel().copyWith(id: 'book-label-id'),
],
);
final container = createContainer(
overrides: [
allBooksProvider.overrideWith((ref) => Stream.value([mockBook])),
],
);
final subscription = container.listen(
booksWithLabelProvider('non-existent-label-id'),
(_, __) {},
);
await container.pump();

final books = subscription.read();
expect(books, isEmpty);
});
});
group('When the label does exist in the repo', () {
test('Then the provider returns the books with that label', () async {
final mockBook = getMockBook().copyWith(
labels: [
getMockBookLabel().copyWith(id: 'book-label-id'),
],
);
final container = createContainer(
overrides: [
allBooksProvider.overrideWith((ref) => Stream.value([mockBook])),
],
);
final subscription = container.listen(
booksWithLabelProvider('book-label-id'),
(_, __) {},
);
await container.pump();

final books = subscription.read();
expect(books, hasLength(1));
});
});
group('When the allBooksProvider throws and exception', () {
test('Then the provider returns an empty list', () async {
final container = createContainer(
overrides: [
allBooksProvider.overrideWith((ref) => throw Exception()),
],
);
final subscription = container.listen(
booksWithLabelProvider('book-label-id'),
(_, __) {},
);
await container.pump();

final books = subscription.read();
expect(books, isEmpty);
});
});
});
}
57 changes: 57 additions & 0 deletions test/providers/recommendations_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:dantex/models/book_recommendation.dart';
import 'package:dantex/providers/recommendations.dart';
import 'package:dantex/providers/repository.dart';
import 'package:dantex/repositories/recommendations_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';

import '../test_utilities.dart';
import 'recommendations_test.mocks.dart';

@GenerateMocks([RecommendationsRepository])
void main() async {
group('Given a recommendationsProvider', () {
group('When the repo has recommendations', () {
test('Then the provider returns all recommendations', () async {
final mockRepository = MockRecommendationsRepository();
when(mockRepository.loadRecommendations()).thenAnswer(
(_) async => List.generate(
3,
(index) => BookRecommendation(
suggestionId: 'suggestion$index',
suggester: BookRecommender(name: 'Suggester $index'),
suggestion: RecommendedBook(
title: 'Title $index',
subTitle: 'SubTitle $index',
author: 'Author $index',
state: 'State $index',
pageCount: 100 + index,
publishedDate: DateTime.now().toString(),
isbn: 'ISBN $index',
language: 'Language $index',
),
recommendation: 'Recommendation $index',
),
),
);

final container = createContainer(
overrides: [
recommendationsRepositoryProvider
.overrideWith((ref) => mockRepository),
],
);

final subscription = container.listen(
recommendationsProvider.future,
(_, __) {},
);
await container.pump();

final recommendations = await subscription.read();
expect(recommendations, hasLength(3));
});
});
});
}
Loading
Loading