diff --git a/packages/board_info_repository/lib/src/board_info_repository.dart b/packages/board_info_repository/lib/src/board_info_repository.dart index d1bfc3a90..aa57b3ea9 100644 --- a/packages/board_info_repository/lib/src/board_info_repository.dart +++ b/packages/board_info_repository/lib/src/board_info_repository.dart @@ -34,7 +34,7 @@ class BoardInfoRepository { /// The [CollectionReference] for the config. late final CollectionReference> boardInfoCollection; - /// Return the total words count available in the crossword. + /// Returns the total words count available in the crossword. Future getTotalWordsCount() async { try { final results = await boardInfoCollection @@ -48,7 +48,7 @@ class BoardInfoRepository { } } - /// Return the solved words count in the crossword. + /// Returns the solved words count in the crossword. Future getSolvedWordsCount() async { try { final results = await boardInfoCollection @@ -61,4 +61,17 @@ class BoardInfoRepository { throw BoardInfoException(error, stackStrace); } } + + /// Returns the limit at which the render mode should switch + Future> 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); + } + } } diff --git a/packages/board_info_repository/test/src/board_info_repository_test.dart b/packages/board_info_repository/test/src/board_info_repository_test.dart index ae1439e63..6ff33377a 100644 --- a/packages/board_info_repository/test/src/board_info_repository_test.dart +++ b/packages/board_info_repository/test/src/board_info_repository_test.dart @@ -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]); @@ -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()), + ); + }); + }); }); group('BoardInfoException', () {