From 713342794efe69b9cb50fd179019085d272dcba6 Mon Sep 17 00:00:00 2001 From: Jaime <52668514+jsgalarraga@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:07:14 +0200 Subject: [PATCH] feat: different zoom limit by platform (#554) * feat: fetch different zoom limits based on platform * feat: fetch different zoom limits based on platform --- .../lib/src/board_info_repository.dart | 11 +++++- .../test/src/board_info_repository_test.dart | 37 +++++++++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) 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 6bd102f89..6113e56a7 100644 --- a/packages/board_info_repository/lib/src/board_info_repository.dart +++ b/packages/board_info_repository/lib/src/board_info_repository.dart @@ -1,6 +1,7 @@ import 'dart:math'; import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter/foundation.dart'; import 'package:rxdart/rxdart.dart'; /// {@template game_status} @@ -50,12 +51,14 @@ class BoardInfoRepository { /// {@macro board_info_repository} BoardInfoRepository({ required this.firestore, - }) { + TargetPlatform? targetPlatform, + }) : _targetPlatform = targetPlatform ?? defaultTargetPlatform { boardInfoCollection = firestore.collection('boardInfo'); } /// The [FirebaseFirestore] instance. final FirebaseFirestore firestore; + final TargetPlatform _targetPlatform; /// The [CollectionReference] for the config. late final CollectionReference> boardInfoCollection; @@ -108,7 +111,11 @@ class BoardInfoRepository { .get(); final data = results.docs.first.data(); - return (data['value'] as num).toDouble(); + + final isMobile = _targetPlatform == TargetPlatform.android || + _targetPlatform == TargetPlatform.iOS; + final key = isMobile ? 'mobile' : 'desktop'; + return (data[key] as num).toDouble(); } 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 92ea7442e..a4072e5dd 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 @@ -4,6 +4,7 @@ import 'dart:math'; import 'package:board_info_repository/board_info_repository.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; @@ -57,6 +58,18 @@ void main() { when(doc.data).thenReturn({'value': value}); } + void mockZoomLimit({dynamic mobile, dynamic desktop}) { + final doc = _MockQueryDocumentSnapshot>(); + final query = _MockQuerySnapshot>(); + when( + () => collection.where('type', isEqualTo: 'zoom_limit'), + ).thenReturn(collection); + + when(collection.get).thenAnswer((_) async => query); + when(() => query.docs).thenReturn([doc]); + when(doc.data).thenReturn({'mobile': mobile, 'desktop': desktop}); + } + test('can be instantiated', () { expect( BoardInfoRepository(firestore: firestore), @@ -119,9 +132,27 @@ void main() { }); group('getZoomLimit', () { - test('returns render mode limit from firebase', () async { - mockQueryResult(0.6); - final result = await boardInfoRepository.getZoomLimit(); + test('returns render limit for desktop from firebase', () async { + final repository = BoardInfoRepository( + firestore: firestore, + targetPlatform: TargetPlatform.windows, + ); + mockZoomLimit(mobile: 0.6, desktop: 0.2); + + final result = await repository.getZoomLimit(); + + expect(result, equals(0.2)); + }); + + test('returns render limit for mobile from firebase', () async { + final repository = BoardInfoRepository( + firestore: firestore, + targetPlatform: TargetPlatform.iOS, + ); + mockZoomLimit(mobile: 0.6, desktop: 0.2); + + final result = await repository.getZoomLimit(); + expect(result, equals(0.6)); });