1
0
mirror of https://github.com/flutter/samples.git synced 2026-05-17 12:28:16 +00:00

Compass app (#2446)

This commit is contained in:
Eric Windmill
2024-09-27 18:49:27 -04:00
committed by GitHub
parent fcf2552cda
commit 46b5a26b26
326 changed files with 53272 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
// Copyright 2024 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/data/services/local/local_data_service.dart';
import 'package:compass_app/utils/result.dart';
import 'package:compass_app/data/repositories/destination/destination_repository_local.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('DestinationRepositoryLocal tests', () {
// To load assets
TestWidgetsFlutterBinding.ensureInitialized();
final repository = DestinationRepositoryLocal(
localDataService: LocalDataService(),
);
test('should load and parse', () async {
// Should load the json and parse it
final result = await repository.getDestinations();
expect(result, isA<Ok>());
// Check that the list is complete
final list = result.asOk.value;
expect(list.length, 137);
// Check first item
final destination = list.first;
expect(destination.name, 'Alaska');
});
});
}

View File

@@ -0,0 +1,49 @@
// Copyright 2024 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/data/repositories/destination/destination_repository.dart';
import 'package:compass_app/data/repositories/destination/destination_repository_remote.dart';
import 'package:compass_app/utils/result.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/fakes/services/fake_api_client.dart';
void main() {
group('DestinationRepositoryRemote tests', () {
late FakeApiClient apiClient;
late DestinationRepository repository;
setUp(() {
apiClient = FakeApiClient();
repository = DestinationRepositoryRemote(apiClient: apiClient);
});
test('should get destinations', () async {
final result = await repository.getDestinations();
expect(result, isA<Ok>());
final list = result.asOk.value;
expect(list.length, 2);
final destination = list.first;
expect(destination.name, 'name1');
// Only one request happened
expect(apiClient.requestCount, 1);
});
test('should get destinations from cache', () async {
// Request destination once
var result = await repository.getDestinations();
expect(result, isA<Ok>());
// Request destination another time
result = await repository.getDestinations();
expect(result, isA<Ok>());
// Only one request happened
expect(apiClient.requestCount, 1);
});
});
}