Default debug builds to the test server on a fresh install

This commit is contained in:
Roland Geider
2026-10-25 14:23:35 +01:00
parent 0ecc92cdac
commit e1ad69afb1
2 changed files with 25 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ import 'dart:async';
import 'dart:convert';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/foundation.dart' show visibleForTesting;
import 'package:flutter/foundation.dart' show kDebugMode, visibleForTesting;
import 'package:flutter/widgets.dart' show AppLifecycleListener;
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
@@ -874,11 +874,12 @@ class AuthNotifier extends _$AuthNotifier {
state = AsyncData(current.copyWith(serverVersion: v));
}
/// Loads the last server URL the user successfully logged in with.
/// Loads the last server URL the user successfully logged in with, or the
/// default server of this build (the test server in debug builds).
static Future<String> getServerUrlFromPrefs() async {
final prefs = PreferenceHelper.asyncPref;
if (!(await prefs.containsKey(PREFS_LAST_SERVER))) {
return DEFAULT_SERVER_PROD;
return kDebugMode ? DEFAULT_SERVER_TEST : DEFAULT_SERVER_PROD;
}
final userData = json.decode((await prefs.getString(PREFS_LAST_SERVER))!);

View File

@@ -121,6 +121,11 @@ void main() {
}
setUp(() async {
// wger.de was used last; a fresh debug install defaults to the test server
await PreferenceHelper.asyncPref.setString(
PREFS_LAST_SERVER,
json.encode({'serverUrl': DEFAULT_SERVER_PROD}),
);
mockClient = MockClient();
mockSecureStorage = MockSecureTokenStorage();
when(mockSecureStorage.deleteRefreshToken()).thenAnswer((_) async {});
@@ -685,6 +690,22 @@ void main() {
expect(find.text('http://localhost:8000'), findsOneWidget);
});
testWidgets('A fresh debug install points at the test server', (
WidgetTester tester,
) async {
await tester.binding.setSurfaceSize(const Size(1080, 1920));
addTearDown(() => tester.binding.setSurfaceSize(null));
await PreferenceHelper.asyncPref.remove(PREFS_LAST_SERVER);
await tester.pumpWidget(getWidget());
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('advancedButton')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('inputServer')), findsOneWidget);
expect(find.text(DEFAULT_SERVER_TEST), findsOneWidget);
});
testWidgets('Sheet round-trip: Refresh token → Username & password', (
WidgetTester tester,
) async {