mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
fix: Prevent invalid map bounds #123
This commit is contained in:
37
test/models/custom_map_config_test.dart
Normal file
37
test/models/custom_map_config_test.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:meshcore_sar_app/models/custom_map_config.dart';
|
||||
|
||||
void main() {
|
||||
test('displayBounds stays within valid LatLng limits for tall images', () {
|
||||
const config = CustomMapConfig(
|
||||
filePath: '/tmp/map.png',
|
||||
displayName: 'Tall Map',
|
||||
mapId: 'map-id',
|
||||
imageWidth: 2400,
|
||||
imageHeight: 3213,
|
||||
);
|
||||
|
||||
expect(config.displayBounds.north, lessThanOrEqualTo(90));
|
||||
expect(config.displayBounds.south, greaterThanOrEqualTo(-90));
|
||||
expect(config.displayBounds.east, lessThanOrEqualTo(180));
|
||||
expect(config.displayBounds.west, greaterThanOrEqualTo(-180));
|
||||
});
|
||||
|
||||
test('display point conversion preserves stored coordinates', () {
|
||||
const config = CustomMapConfig(
|
||||
filePath: '/tmp/map.png',
|
||||
displayName: 'Tall Map',
|
||||
mapId: 'map-id',
|
||||
imageWidth: 2400,
|
||||
imageHeight: 3213,
|
||||
);
|
||||
const storedPoint = LatLng(1600, 1200);
|
||||
|
||||
final displayPoint = config.toDisplayPoint(storedPoint);
|
||||
final roundTrip = config.fromDisplayPoint(displayPoint);
|
||||
|
||||
expect(roundTrip.latitude, closeTo(storedPoint.latitude, 0.001));
|
||||
expect(roundTrip.longitude, closeTo(storedPoint.longitude, 0.001));
|
||||
});
|
||||
}
|
||||
@@ -94,4 +94,37 @@ void main() {
|
||||
expect(await MeshMapNodesService.loadCachedNodes(), isEmpty);
|
||||
expect(await MeshMapNodesService.cachedAt(), isNull);
|
||||
});
|
||||
|
||||
test('fetchNodes ignores nodes with invalid coordinates', () async {
|
||||
final client = MockClient(
|
||||
(_) async => http.Response(
|
||||
jsonEncode({
|
||||
'nodes': [
|
||||
{
|
||||
'type': 1,
|
||||
'name': 'Broken',
|
||||
'public_key': 'bad123',
|
||||
'latitude': 3213.0,
|
||||
'longitude': 14.50,
|
||||
'updated_at': 123456,
|
||||
},
|
||||
{
|
||||
'type': 1,
|
||||
'name': 'Alpha',
|
||||
'public_key': 'aa11bb22',
|
||||
'latitude': 46.05,
|
||||
'longitude': 14.50,
|
||||
'updated_at': 123456,
|
||||
},
|
||||
],
|
||||
}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
|
||||
final nodes = await MeshMapNodesService.fetchNodes(client: client);
|
||||
|
||||
expect(nodes, hasLength(1));
|
||||
expect(nodes.first.name, 'Alpha');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user