Skip to content

Commit

Permalink
feat: different zoom limit by platform (#554)
Browse files Browse the repository at this point in the history
* feat: fetch different zoom limits based on platform

* feat: fetch different zoom limits based on platform
  • Loading branch information
jsgalarraga authored Jun 5, 2024
1 parent d0b0b25 commit 7133427
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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<Map<String, dynamic>> boardInfoCollection;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -57,6 +58,18 @@ void main() {
when(doc.data).thenReturn({'value': value});
}

void mockZoomLimit({dynamic mobile, dynamic desktop}) {
final doc = _MockQueryDocumentSnapshot<Map<String, dynamic>>();
final query = _MockQuerySnapshot<Map<String, dynamic>>();
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),
Expand Down Expand Up @@ -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));
});

Expand Down

0 comments on commit 7133427

Please sign in to comment.