All checks were successful
Release / meta (push) Successful in 3s
Release / linux-build (push) Successful in 1m1s
Release / web-build (push) Successful in 1m22s
Release / android-build (push) Successful in 6m49s
Release / release-master (push) Successful in 5s
Release / release-dev (push) Successful in 8s
266 lines
6.5 KiB
Dart
266 lines
6.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:mileograph_flutter/objects/objects.dart';
|
|
import 'package:mileograph_flutter/services/api_service.dart';
|
|
import 'package:mileograph_flutter/services/authservice.dart';
|
|
import 'package:mileograph_flutter/services/data_service.dart';
|
|
import 'package:mileograph_flutter/services/distance_unit_service.dart';
|
|
|
|
import 'test_data.dart';
|
|
|
|
class FakeApiService extends ApiService {
|
|
FakeApiService({String baseUrl = 'https://example.com'})
|
|
: super(baseUrl: baseUrl);
|
|
|
|
final Map<String, dynamic> getResponses = {};
|
|
final Map<String, dynamic> postResponses = {};
|
|
|
|
@override
|
|
Future<dynamic> get(String endpoint, {Map<String, String>? headers}) async {
|
|
return getResponses[endpoint];
|
|
}
|
|
|
|
@override
|
|
Future<dynamic> post(
|
|
String endpoint,
|
|
dynamic data, {
|
|
Map<String, String>? headers,
|
|
}) async {
|
|
return postResponses[endpoint] ?? {};
|
|
}
|
|
}
|
|
|
|
class FakeAuthService extends AuthService {
|
|
FakeAuthService({
|
|
required super.api,
|
|
this.userIdValue = 'user-123',
|
|
this.usernameValue = 'railfan',
|
|
this.fullNameValue = 'Alex Rider',
|
|
this.isElevatedValue = true,
|
|
this.isLoggedInValue = true,
|
|
});
|
|
|
|
final String? userIdValue;
|
|
final String? usernameValue;
|
|
final String? fullNameValue;
|
|
final bool isElevatedValue;
|
|
final bool isLoggedInValue;
|
|
|
|
@override
|
|
bool get isLoggedIn => isLoggedInValue;
|
|
|
|
@override
|
|
String? get userId => userIdValue;
|
|
|
|
@override
|
|
String? get username => usernameValue;
|
|
|
|
@override
|
|
String? get fullName => fullNameValue;
|
|
|
|
@override
|
|
bool get isElevated => isElevatedValue;
|
|
}
|
|
|
|
class FakeDataService extends DataService {
|
|
FakeDataService({ApiService? api})
|
|
: super(api: api ?? FakeApiService());
|
|
|
|
HomepageStats? homepageStatsValue;
|
|
bool isHomepageLoadingValue = false;
|
|
List<TripSummary> tripsValue = [];
|
|
List<Leg> onThisDayValue = [];
|
|
bool isOnThisDayLoadingValue = false;
|
|
List<ClassClearanceProgress> classClearanceProgressValue = [];
|
|
bool isClassClearanceProgressLoadingValue = false;
|
|
List<LocoSummary> tractionValue = [];
|
|
bool isTractionLoadingValue = false;
|
|
bool tractionHasMoreValue = false;
|
|
List<LocoChange> latestLocoChangesValue = [];
|
|
bool isLatestLocoChangesLoadingValue = false;
|
|
bool latestLocoChangesHasMoreValue = false;
|
|
List<Leg> legsValue = [];
|
|
bool isLegsLoadingValue = false;
|
|
bool legsHasMoreValue = false;
|
|
List<TripDetail> tripDetailsValue = [];
|
|
List<TripSummary> tripListValue = [];
|
|
bool isTripDetailsLoadingValue = false;
|
|
List<String> locoClassesValue = [];
|
|
List<EventField> eventFieldsValue = [];
|
|
bool isEventFieldsLoadingValue = false;
|
|
int pendingLocoCountValue = 0;
|
|
double currentYearMileageValue = 0;
|
|
|
|
@override
|
|
HomepageStats? get homepageStats => homepageStatsValue;
|
|
|
|
@override
|
|
bool get isHomepageLoading => isHomepageLoadingValue;
|
|
|
|
@override
|
|
List<TripSummary> get trips => tripsValue;
|
|
|
|
@override
|
|
List<Leg> get onThisDay => onThisDayValue;
|
|
|
|
@override
|
|
bool get isOnThisDayLoading => isOnThisDayLoadingValue;
|
|
|
|
@override
|
|
List<ClassClearanceProgress> get classClearanceProgress =>
|
|
classClearanceProgressValue;
|
|
|
|
@override
|
|
bool get isClassClearanceProgressLoading =>
|
|
isClassClearanceProgressLoadingValue;
|
|
|
|
@override
|
|
List<LocoSummary> get traction => tractionValue;
|
|
|
|
@override
|
|
bool get isTractionLoading => isTractionLoadingValue;
|
|
|
|
@override
|
|
bool get tractionHasMore => tractionHasMoreValue;
|
|
|
|
@override
|
|
List<LocoChange> get latestLocoChanges => latestLocoChangesValue;
|
|
|
|
@override
|
|
bool get isLatestLocoChangesLoading => isLatestLocoChangesLoadingValue;
|
|
|
|
@override
|
|
bool get latestLocoChangesHasMore => latestLocoChangesHasMoreValue;
|
|
|
|
@override
|
|
List<Leg> get legs => legsValue;
|
|
|
|
@override
|
|
bool get isLegsLoading => isLegsLoadingValue;
|
|
|
|
@override
|
|
bool get legsHasMore => legsHasMoreValue;
|
|
|
|
@override
|
|
List<TripDetail> get tripDetails => tripDetailsValue;
|
|
|
|
@override
|
|
List<TripSummary> get tripList => tripListValue;
|
|
|
|
@override
|
|
bool get isTripDetailsLoading => isTripDetailsLoadingValue;
|
|
|
|
@override
|
|
List<String> get locoClasses => locoClassesValue;
|
|
|
|
@override
|
|
List<EventField> get eventFields => eventFieldsValue;
|
|
|
|
@override
|
|
bool get isEventFieldsLoading => isEventFieldsLoadingValue;
|
|
|
|
@override
|
|
int get pendingLocoCount => pendingLocoCountValue;
|
|
|
|
@override
|
|
double getMileageForCurrentYear() => currentYearMileageValue;
|
|
|
|
@override
|
|
Future<void> fetchHomepageStats() async {}
|
|
|
|
@override
|
|
Future<void> fetchOnThisDay({DateTime? date}) async {}
|
|
|
|
@override
|
|
Future<void> fetchTripDetails() async {}
|
|
|
|
@override
|
|
Future<void> fetchHadTraction({int offset = 0, int limit = 100}) async {}
|
|
|
|
@override
|
|
Future<void> fetchLatestLocoChanges({
|
|
int limit = 100,
|
|
int offset = 0,
|
|
bool append = false,
|
|
}) async {}
|
|
|
|
@override
|
|
Future<void> fetchClassClearanceProgress({
|
|
int offset = 0,
|
|
int limit = 20,
|
|
bool append = false,
|
|
bool onlyIncomplete = false,
|
|
}) async {}
|
|
|
|
@override
|
|
Future<void> fetchLegs({
|
|
int offset = 0,
|
|
int limit = 100,
|
|
String sortBy = 'date',
|
|
int sortDirection = 0,
|
|
String? dateRangeStart,
|
|
String? dateRangeEnd,
|
|
bool append = false,
|
|
bool unallocatedOnly = false,
|
|
}) async {}
|
|
|
|
@override
|
|
Future<List<TripLocoStat>> fetchTripLocoStats(int tripId) async {
|
|
return const [];
|
|
}
|
|
|
|
@override
|
|
Future<void> fetchTraction({
|
|
bool hadOnly = false,
|
|
int offset = 0,
|
|
int limit = 100,
|
|
String? locoClass,
|
|
String? locoNumber,
|
|
bool mileageFirst = true,
|
|
bool append = false,
|
|
Map<String, dynamic>? filters,
|
|
}) async {}
|
|
|
|
@override
|
|
Future<List<String>> fetchClassList({bool force = false}) async {
|
|
return locoClassesValue;
|
|
}
|
|
|
|
@override
|
|
Future<void> fetchEventFields({bool force = false}) async {}
|
|
|
|
@override
|
|
Future<void> fetchPendingLocoCount() async {}
|
|
|
|
@override
|
|
Future<Map<String, dynamic>?> fetchClassStats(String locoClass) async {
|
|
return TestData.classStats;
|
|
}
|
|
|
|
@override
|
|
Future<List<LeaderboardEntry>> fetchClassLeaderboard(
|
|
String locoClass, {
|
|
bool friends = false,
|
|
}) async {
|
|
return TestData.classLeaderboard;
|
|
}
|
|
}
|
|
|
|
class FakeDistanceUnitService extends DistanceUnitService {
|
|
FakeDistanceUnitService({this.unitOverride});
|
|
|
|
final DistanceUnit? unitOverride;
|
|
|
|
@override
|
|
DistanceUnit get unit => unitOverride ?? super.unit;
|
|
|
|
@override
|
|
String format(
|
|
double miles, {
|
|
int decimals = 1,
|
|
bool includeUnit = true,
|
|
}) {
|
|
final formatter = DistanceFormatter(unitOverride ?? super.unit);
|
|
return formatter.format(miles, decimals: decimals, includeUnit: includeUnit);
|
|
}
|
|
}
|