mirror of
https://github.com/flutter/samples.git
synced 2026-04-25 08:22:16 +00:00
Compass app (#2446)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 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/activity/activity_repository_local.dart';
|
||||
import 'package:compass_app/data/services/local/local_data_service.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ActivityRepositoryLocal tests', () {
|
||||
// To load assets
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final repository = ActivityRepositoryLocal(
|
||||
localDataService: LocalDataService(),
|
||||
);
|
||||
|
||||
test('should get by destination ref', () async {
|
||||
final result = await repository.getByDestination('alaska');
|
||||
expect(result, isA<Ok>());
|
||||
|
||||
final list = result.asOk.value;
|
||||
expect(list.length, 20);
|
||||
|
||||
final activity = list.first;
|
||||
expect(activity.name, 'Glacier Trekking and Ice Climbing');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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/activity/activity_repository.dart';
|
||||
import 'package:compass_app/data/repositories/activity/activity_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('ActivityRepositoryRemote tests', () {
|
||||
late FakeApiClient apiClient;
|
||||
late ActivityRepository repository;
|
||||
|
||||
setUp(() {
|
||||
apiClient = FakeApiClient();
|
||||
repository = ActivityRepositoryRemote(apiClient: apiClient);
|
||||
});
|
||||
|
||||
test('should get activities for destination', () async {
|
||||
final result = await repository.getByDestination('alaska');
|
||||
expect(result, isA<Ok>());
|
||||
|
||||
final list = result.asOk.value;
|
||||
expect(list.length, 1);
|
||||
|
||||
final destination = list.first;
|
||||
expect(destination.name, 'Glacier Trekking and Ice Climbing');
|
||||
|
||||
// Only one request happened
|
||||
expect(apiClient.requestCount, 1);
|
||||
});
|
||||
|
||||
test('should get destinations from cache', () async {
|
||||
// Request destination once
|
||||
var result = await repository.getByDestination('alaska');
|
||||
expect(result, isA<Ok>());
|
||||
|
||||
// Request destination another time
|
||||
result = await repository.getByDestination('alaska');
|
||||
expect(result, isA<Ok>());
|
||||
|
||||
// Only one request happened
|
||||
expect(apiClient.requestCount, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user