mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-08-10 21:20:18 +02:00
offline options globally toggleable
This commit is contained in:
@@ -41,8 +41,11 @@ void main() {
|
||||
mockAppState = MockAppState();
|
||||
AppState.instance = mockAppState;
|
||||
|
||||
// Default stubs: online, no offline areas
|
||||
// Default stubs: online, no offline areas, offline features enabled
|
||||
// (so tests exercise the same behavior as before this setting existed)
|
||||
when(() => mockAppState.offlineMode).thenReturn(false);
|
||||
when(() => mockAppState.offlineFeaturesEnabled).thenReturn(true);
|
||||
|
||||
|
||||
provider = DeflockTileProvider(
|
||||
providerId: 'openstreetmap',
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:flutter_map/flutter_map.dart' show LatLngBounds;
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import 'package:deflockapp/app_state.dart';
|
||||
import 'package:deflockapp/services/offline_area_service.dart';
|
||||
import 'package:deflockapp/services/offline_areas/offline_area_models.dart';
|
||||
|
||||
class MockAppState extends Mock implements AppState {}
|
||||
|
||||
|
||||
OfflineArea _makeArea({
|
||||
String providerId = 'osm',
|
||||
String tileTypeId = 'standard',
|
||||
@@ -26,11 +31,19 @@ OfflineArea _makeArea({
|
||||
|
||||
void main() {
|
||||
final service = OfflineAreaService();
|
||||
late MockAppState mockAppState;
|
||||
|
||||
setUp(() {
|
||||
service.setAreasForTesting([]);
|
||||
mockAppState = MockAppState();
|
||||
AppState.instance = mockAppState;
|
||||
// These tests exercise the underlying zoom/provider matching logic, so
|
||||
// offline features are enabled by default here — the "disabled" gating
|
||||
// itself is covered separately below.
|
||||
when(() => mockAppState.offlineFeaturesEnabled).thenReturn(true);
|
||||
});
|
||||
|
||||
|
||||
group('hasOfflineAreasForProviderAtZoom', () {
|
||||
test('returns true for zoom within range', () {
|
||||
service.setAreasForTesting([_makeArea(minZoom: 5, maxZoom: 12)]);
|
||||
@@ -90,4 +103,30 @@ void main() {
|
||||
expect(service.hasOfflineAreasForProviderAtZoom('osm', 'standard', 15), isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('offlineFeaturesEnabled gating', () {
|
||||
test('hasOfflineAreasForProvider returns false when feature disabled, even with matching areas', () {
|
||||
service.setAreasForTesting([_makeArea(providerId: 'osm', tileTypeId: 'standard')]);
|
||||
when(() => mockAppState.offlineFeaturesEnabled).thenReturn(false);
|
||||
|
||||
expect(service.hasOfflineAreasForProvider('osm', 'standard'), isFalse);
|
||||
});
|
||||
|
||||
test('hasOfflineAreasForProviderAtZoom returns false when feature disabled, even within zoom range', () {
|
||||
service.setAreasForTesting([_makeArea(minZoom: 5, maxZoom: 12)]);
|
||||
when(() => mockAppState.offlineFeaturesEnabled).thenReturn(false);
|
||||
|
||||
expect(service.hasOfflineAreasForProviderAtZoom('osm', 'standard', 8), isFalse);
|
||||
});
|
||||
|
||||
test('re-enabling offlineFeaturesEnabled restores normal matching', () {
|
||||
service.setAreasForTesting([_makeArea(minZoom: 5, maxZoom: 12)]);
|
||||
when(() => mockAppState.offlineFeaturesEnabled).thenReturn(false);
|
||||
expect(service.hasOfflineAreasForProviderAtZoom('osm', 'standard', 8), isFalse);
|
||||
|
||||
when(() => mockAppState.offlineFeaturesEnabled).thenReturn(true);
|
||||
expect(service.hasOfflineAreasForProviderAtZoom('osm', 'standard', 8), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user