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

feat: get render mode info from firestore #100

Merged
merged 5 commits into from
Mar 21, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BoardInfoRepository {
/// The [CollectionReference] for the config.
late final CollectionReference<Map<String, dynamic>> boardInfoCollection;

/// Return the total words count available in the crossword.
/// Returns the total words count available in the crossword.
Future<int> getTotalWordsCount() async {
try {
final results = await boardInfoCollection
Expand All @@ -48,7 +48,7 @@ class BoardInfoRepository {
}
}

/// Return the solved words count in the crossword.
/// Returns the solved words count in the crossword.
Future<int> getSolvedWordsCount() async {
try {
final results = await boardInfoCollection
Expand All @@ -61,4 +61,17 @@ class BoardInfoRepository {
throw BoardInfoException(error, stackStrace);
}
}

/// Returns the limit at which the render mode should switch
Future<List<double>> getRenderModeZoomLimits() async {
try {
final results = await boardInfoCollection
.where('type', isEqualTo: 'render_mode_limit')
.get();

return results.docs.map((e) => e.data()['value'] as double).toList();
} catch (error, stackStrace) {
throw BoardInfoException(error, stackStrace);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void main() {
when(
() => collection.where('type', isEqualTo: 'solved_words_count'),
).thenReturn(collection);
when(
() => collection.where('type', isEqualTo: 'render_mode_limit'),
).thenReturn(collection);

when(collection.get).thenAnswer((_) async => query);
when(() => query.docs).thenReturn([doc]);
Expand Down Expand Up @@ -87,6 +90,24 @@ void main() {
);
});
});

group('getRenderModeZoomLimit', () {
test('returns render mode limit from firebase', () async {
mockQueryResult(0.6);
final result = await boardInfoRepository.getRenderModeZoomLimits();
expect(result, equals([0.6]));
});

test('throws BoardInfoException when fetching the info fails', () {
when(
() => collection.where('type', isEqualTo: 'render_mode_limit'),
).thenThrow(Exception('oops'));
expect(
() => boardInfoRepository.getRenderModeZoomLimits(),
throwsA(isA<BoardInfoException>()),
);
});
});
});

group('BoardInfoException', () {
Expand Down
Loading