mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 23:44:02 +01:00
Add shared test helpers for the app shell and the auth backend
This commit is contained in:
@@ -55,7 +55,7 @@ features/<feature>/
|
||||
```
|
||||
test/
|
||||
├── features/<feature>/..., core/, database/, powersync/ mirror lib/ one file per source file (<name>_test.dart)
|
||||
├── helpers/ in_memory_drift, fake_auth_notifier, fake_auth_environment, ...
|
||||
├── helpers/ pump_app, fake_auth_backend, in_memory_drift, fake_auth_notifier, fake_auth_environment, dst, ...
|
||||
├── fixtures/ raw JSON API responses (fixture_reader.dart)
|
||||
└── screenshots/ store screenshot scene builders
|
||||
test_data/ shared Dart fixtures (getTestRoutine(), ...), structural variants stay in the test
|
||||
@@ -97,7 +97,7 @@ integration_test/ screenshot driver
|
||||
- **Assert instants, never the local wall clock.** `expect(converted, DateTime.parse('...11:15'))` only holds in one zone; use `isAtSameMomentAs` against a `DateTime.utc(...)`, or compare UTC components. CI pins `TZ=Europe/Berlin`, so a local-time assumption stays invisible there and turns the suite red for everyone else.
|
||||
- **Capture the payload on REST writes.** `verify(base.post(any, uri))` only pins the routing; a renamed or dropped field surfaces as a server-side 400. Use `verify(base.post(captureAny, uri)).captured` and assert the wire names.
|
||||
- **Structural fixture variants belong in the test**, not in the shared corpus in `test_data/`: growing `getTestRoutine()` shifts expectations in dozens of files. Build the superset slot, the rest day, the empty plan locally. (This is why supersets had no coverage at all: the shared fixture defined what was testable.)
|
||||
- **Widget tests:** `tester.view.physicalSize`/`devicePixelRatio` always with `addTearDown(tester.view.reset)`, and every test sets the size it needs itself — two log-screen tests were silently living off the one a previous test left behind. `installFakeAuthEnvironment()` registers a `setUp`, so it goes at the top of `main()`; calling it inside another `setUp` throws at runtime.
|
||||
- **Widget tests:** build the app shell with `testApp`/`pumpApp` from `test/helpers/pump_app.dart` (`pumpRoute` for a screen that needs a route below it or route arguments), not a hand-written `ProviderScope` + `MaterialApp`. Set sizes through `pumpApp(size: ...)`/`setTestViewSize`, or `tester.view.physicalSize`/`devicePixelRatio` always with `addTearDown(tester.view.reset)`; never `setSurfaceSize`, which `tester.view.reset` doesn't undo. Every test sets the size it needs itself — two log-screen tests were silently living off the one a previous test left behind. Auth tests stub the backend with `test/helpers/fake_auth_backend.dart` (`stubAuthBackend`, `makeJwt`, `seedSavedLogin`, `FakePathProvider`). `installFakeAuthEnvironment()` registers a `setUp`, so it goes at the top of `main()`; calling it inside another `setUp` throws at runtime.
|
||||
|
||||
## Scope
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -40,6 +38,7 @@ import 'package:wger/features/account/providers/account_notifier.dart';
|
||||
import 'package:wger/features/account/providers/account_repository.dart';
|
||||
import 'package:wger/features/account/providers/timezone_sync.dart';
|
||||
|
||||
import '../../helpers/fake_auth_backend.dart';
|
||||
import '../../helpers/fake_auth_environment.dart';
|
||||
import 'auth_notifier_login_test.mocks.dart';
|
||||
|
||||
@@ -71,16 +70,12 @@ void main() {
|
||||
late MockAccountRepository mockAccountRepo;
|
||||
|
||||
// Backing dir for the on-disk PowerSync wipe path (instance never built in
|
||||
// these tests). When [failDbPathLookup] is set, the path lookup throws so
|
||||
// tests can exercise a failed wipe.
|
||||
late Directory tmpDir;
|
||||
var failDbPathLookup = false;
|
||||
const pathProviderChannel = MethodChannel('plugins.flutter.io/path_provider');
|
||||
// these tests). Set its `failLookup` so tests can exercise a failed wipe.
|
||||
late FakePathProvider pathProvider;
|
||||
|
||||
const serverUrl = 'https://wger.example';
|
||||
const serverUrl = testServerUrl;
|
||||
const username = 'alice';
|
||||
const password = 'hunter2';
|
||||
const powerSyncUrl = 'https://ps.example/';
|
||||
|
||||
const tAccount = Account(
|
||||
username: username,
|
||||
@@ -91,18 +86,7 @@ void main() {
|
||||
|
||||
final tHeadlessLogin = Uri.parse('$serverUrl/allauth/app/v1/auth/login');
|
||||
final tHeadlessSignup = Uri.parse('$serverUrl/allauth/app/v1/auth/signup');
|
||||
final tVersion = Uri.parse('$serverUrl/api/v2/version/');
|
||||
final tMinAppVersion = Uri.parse('$serverUrl/api/v2/min-app-version/');
|
||||
final tPowerSyncToken = Uri.parse('$serverUrl/api/v2/powersync-token');
|
||||
final tLiveness = Uri.parse('${powerSyncUrl}probes/liveness');
|
||||
|
||||
/// Builds a JWT-shaped string with the given payload. Signature is a sham,
|
||||
/// we only decode the middle segment.
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
final tVersion = const AuthBackendUris().version;
|
||||
|
||||
ProviderContainer makeContainer() {
|
||||
final c = ProviderContainer(
|
||||
@@ -127,51 +111,15 @@ void main() {
|
||||
|
||||
// Point the on-disk wipe path at a real temp dir so the user-switch wipe
|
||||
// succeeds (no file present -> no-op), mirroring a device with no DB yet.
|
||||
failDbPathLookup = false;
|
||||
tmpDir = Directory.systemTemp.createTempSync('wger_login_ps');
|
||||
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(pathProviderChannel, (call) async {
|
||||
if (failDbPathLookup) {
|
||||
throw PlatformException(code: 'unavailable', message: 'simulated path lookup failure');
|
||||
}
|
||||
return call.method == 'getApplicationSupportDirectory' ? tmpDir.path : null;
|
||||
});
|
||||
addTearDown(() {
|
||||
messenger.setMockMethodCallHandler(pathProviderChannel, null);
|
||||
if (tmpDir.existsSync()) {
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
pathProvider = FakePathProvider.install(prefix: 'wger_login_ps');
|
||||
|
||||
// Default gating-chain mocks (happy path). Login-flow tests override
|
||||
// only what they care about.
|
||||
when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200));
|
||||
when(mockClient.get(tMinAppVersion)).thenAnswer((_) async => Response('"0.0.1"', 200));
|
||||
when(
|
||||
mockClient.get(tPowerSyncToken, headers: anyNamed('headers')),
|
||||
).thenAnswer(
|
||||
(_) async => Response(
|
||||
jsonEncode({'token': 'ps-jwt', 'powersync_url': powerSyncUrl}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
when(mockClient.get(tLiveness)).thenAnswer((_) async => Response('OK', 200));
|
||||
// _serverConfigSane probe → null `next` means clean.
|
||||
when(
|
||||
mockClient.get(any, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) async => Response(jsonEncode({'next': null}), 200));
|
||||
// Re-stub the explicit ones (any-match above otherwise wins).
|
||||
when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200));
|
||||
when(mockClient.get(tMinAppVersion)).thenAnswer((_) async => Response('"0.0.1"', 200));
|
||||
when(
|
||||
mockClient.get(tPowerSyncToken, headers: anyNamed('headers')),
|
||||
).thenAnswer(
|
||||
(_) async => Response(
|
||||
jsonEncode({'token': 'ps-jwt', 'powersync_url': powerSyncUrl}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
when(mockClient.get(tLiveness)).thenAnswer((_) async => Response('OK', 200));
|
||||
// Default gating-chain mocks (happy path), after the any-match above so
|
||||
// they win. Login-flow tests override only what they care about.
|
||||
stubAuthBackend(mockClient);
|
||||
});
|
||||
|
||||
group('login: headless happy path', () {
|
||||
@@ -499,7 +447,7 @@ void main() {
|
||||
// next start re-detect the switch and retry.
|
||||
await PreferenceHelper.asyncPref.setString(PREFS_DB_OWNER_USER_ID, '5');
|
||||
stubLoginSuccess(makeJwt({'sub': '7', 'exp': 1900000000}));
|
||||
failDbPathLookup = true;
|
||||
pathProvider.failLookup = true;
|
||||
|
||||
final container = makeContainer();
|
||||
await container.read(authProvider.future);
|
||||
|
||||
@@ -40,6 +40,7 @@ import 'package:wger/core/network/powersync_session.dart';
|
||||
import 'package:wger/core/network/secure_token_storage.dart';
|
||||
import 'package:wger/core/shared_preferences.dart';
|
||||
|
||||
import '../../helpers/fake_auth_backend.dart';
|
||||
import '../../helpers/fake_auth_environment.dart';
|
||||
import '../../helpers/fake_connectivity.dart';
|
||||
import 'auth_notifier_powersync_test.mocks.dart';
|
||||
@@ -79,25 +80,20 @@ void main() {
|
||||
late MockSecureTokenStorage mockSecureStorage;
|
||||
|
||||
// Backing dir for the on-disk PowerSync wipe path (instance never built in
|
||||
// these tests). When [failDbPathLookup] is set, the path lookup throws so
|
||||
// tests can exercise a failed wipe.
|
||||
late Directory tmpDir;
|
||||
var failDbPathLookup = false;
|
||||
const pathProviderChannel = MethodChannel('plugins.flutter.io/path_provider');
|
||||
// these tests). Set its `failLookup` so tests can exercise a failed wipe.
|
||||
late FakePathProvider pathProvider;
|
||||
|
||||
const serverUrl = 'https://wger.example';
|
||||
const serverUrl = testServerUrl;
|
||||
const accessToken = 'access-token-12345';
|
||||
const powerSyncUrl = 'https://ps.example/';
|
||||
|
||||
// makeUri() defaults to a trailing slash; powersync-token is registered
|
||||
// without one on the Django side.
|
||||
final tProbe = Uri.parse('$serverUrl/api/v2/routine/?limit=1');
|
||||
final tVersion = Uri.parse('$serverUrl/api/v2/version/');
|
||||
final tMinAppVersion = Uri.parse('$serverUrl/api/v2/min-app-version/');
|
||||
final tPowerSyncToken = Uri.parse('$serverUrl/api/v2/powersync-token');
|
||||
final tLiveness = Uri.parse('${powerSyncUrl}probes/liveness');
|
||||
final tFallbackLiveness = Uri.parse('$serverUrl/ps/probes/liveness');
|
||||
final tHeadlessRefresh = Uri.parse('$serverUrl/allauth/app/v1/tokens/refresh');
|
||||
const uris = AuthBackendUris();
|
||||
final tProbe = uris.probe;
|
||||
final tVersion = uris.version;
|
||||
final tMinAppVersion = uris.minAppVersion;
|
||||
final tPowerSyncToken = uris.powerSyncToken;
|
||||
final tLiveness = uris.liveness;
|
||||
final tFallbackLiveness = uris.fallbackLiveness;
|
||||
final tHeadlessRefresh = uris.headlessRefresh;
|
||||
|
||||
/// Builds a fresh ProviderContainer with the mock HTTP client wired into
|
||||
/// the auth notifier. Auto-disposes after the test.
|
||||
@@ -121,55 +117,22 @@ void main() {
|
||||
when(mockSecureStorage.writeRefreshToken(any)).thenAnswer((_) async {});
|
||||
|
||||
// Point the on-disk wipe path at a real temp dir so a wiping logout
|
||||
// succeeds (no file present -> no-op). Set [failDbPathLookup] to make the
|
||||
// succeeds (no file present -> no-op). Set its `failLookup` to make the
|
||||
// lookup throw and exercise a failed wipe.
|
||||
failDbPathLookup = false;
|
||||
tmpDir = Directory.systemTemp.createTempSync('wger_ps_auth');
|
||||
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(pathProviderChannel, (call) async {
|
||||
if (failDbPathLookup) {
|
||||
throw PlatformException(code: 'unavailable', message: 'simulated path lookup failure');
|
||||
}
|
||||
return call.method == 'getApplicationSupportDirectory' ? tmpDir.path : null;
|
||||
});
|
||||
addTearDown(() {
|
||||
messenger.setMockMethodCallHandler(pathProviderChannel, null);
|
||||
if (tmpDir.existsSync()) {
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
// Wipe async prefs between tests (the platform instance is shared).
|
||||
final prefs = PreferenceHelper.asyncPref;
|
||||
pathProvider = FakePathProvider.install(prefix: 'wger_ps_auth');
|
||||
|
||||
// Persist a logged-in user so auto-login actually runs. The expiry sits
|
||||
// far enough in the future that no test trips the pre-emptive refresh
|
||||
// unless it re-seeds the bundle itself.
|
||||
await prefs.setString(PREFS_ACCESS_TOKEN, accessToken);
|
||||
await prefs.setInt(
|
||||
PREFS_ACCESS_EXPIRES_AT,
|
||||
DateTime.now().add(const Duration(hours: 1)).millisecondsSinceEpoch,
|
||||
);
|
||||
await prefs.setString(PREFS_SERVER_URL, serverUrl);
|
||||
await seedSavedLogin(serverUrl: serverUrl, accessToken: accessToken);
|
||||
|
||||
// Default happy-path mocks. Individual tests override what they need.
|
||||
when(
|
||||
mockClient.get(tProbe, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) async => Response('', 200));
|
||||
|
||||
when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200));
|
||||
when(mockClient.get(tMinAppVersion)).thenAnswer((_) async => Response('"0.0.1"', 200));
|
||||
stubAuthBackend(mockClient, uris: uris);
|
||||
|
||||
when(
|
||||
mockClient.get(tPowerSyncToken, headers: anyNamed('headers')),
|
||||
).thenAnswer(
|
||||
(_) async => Response(
|
||||
json.encode({'token': 'jwt-token', 'powersync_url': powerSyncUrl}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
|
||||
when(mockClient.get(tLiveness)).thenAnswer((_) async => Response('OK', 200));
|
||||
// When the advertised URL fails its probe, the resolution falls back to
|
||||
// <serverUrl>/ps/. A 404 keeps the "unreachable" scenarios unreachable;
|
||||
// fallback-specific tests override this.
|
||||
@@ -634,12 +597,6 @@ void main() {
|
||||
// from a 403 the way AuthHttpClient does. An access token past its
|
||||
// lifetime (a retry from the PowerSync-unreachable screen a while after
|
||||
// the login) therefore has to be renewed before the probe runs.
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
|
||||
late String newAccess;
|
||||
|
||||
setUp(() async {
|
||||
@@ -796,14 +753,9 @@ void main() {
|
||||
test('wipes the headless-JWT prefs bundle and the secure-storage refresh token', () async {
|
||||
// Seed both formats so we can assert each gets removed.
|
||||
final prefs = PreferenceHelper.asyncPref;
|
||||
await prefs.setString(PREFS_ACCESS_TOKEN, 'jwt-access');
|
||||
// A live token: an expired one would send the never-synced auto-login
|
||||
// through a refresh first, which is not what this test is about
|
||||
await prefs.setInt(
|
||||
PREFS_ACCESS_EXPIRES_AT,
|
||||
DateTime.now().add(const Duration(hours: 1)).millisecondsSinceEpoch,
|
||||
);
|
||||
await prefs.setString(PREFS_SERVER_URL, serverUrl);
|
||||
await seedSavedLogin(accessToken: 'jwt-access');
|
||||
|
||||
final container = makeContainer();
|
||||
await container.read(authProvider.future);
|
||||
@@ -821,21 +773,8 @@ void main() {
|
||||
// logout from the PowerSync-unreachable screen) the wipe must remove the
|
||||
// on-disk file, otherwise the owner marker is reset to null while the
|
||||
// previous user's data lingers -> the next different user docks onto it.
|
||||
final tmpDir = Directory.systemTemp.createTempSync('wger_ps_logout');
|
||||
const channel = MethodChannel('plugins.flutter.io/path_provider');
|
||||
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
(call) async => call.method == 'getApplicationSupportDirectory' ? tmpDir.path : null,
|
||||
);
|
||||
addTearDown(() {
|
||||
messenger.setMockMethodCallHandler(channel, null);
|
||||
if (tmpDir.existsSync()) {
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
final dbFile = File('${tmpDir.path}/powersync-wger.db')..writeAsStringSync('user-7-data');
|
||||
final dbFile = File('${pathProvider.dir.path}/powersync-wger.db')
|
||||
..writeAsStringSync('user-7-data');
|
||||
final prefs = PreferenceHelper.asyncPref;
|
||||
await prefs.setString(PREFS_DB_OWNER_USER_ID, '7');
|
||||
// Logout keeps the local DB by default; opt out so the file is wiped.
|
||||
@@ -863,7 +802,7 @@ void main() {
|
||||
await container.read(authProvider.notifier).revalidationDone;
|
||||
|
||||
// Make the on-disk wipe fail.
|
||||
failDbPathLookup = true;
|
||||
pathProvider.failLookup = true;
|
||||
await container.read(authProvider.notifier).logout();
|
||||
|
||||
// Credentials are still cleared (the user logged out), but the marker
|
||||
@@ -968,12 +907,6 @@ void main() {
|
||||
group('background revalidation: headless pre-emptive refresh', () {
|
||||
final tRefresh = Uri.parse('$serverUrl/allauth/app/v1/tokens/refresh');
|
||||
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
|
||||
test(
|
||||
'expired access token + valid refresh token → refresh runs first, probe succeeds, '
|
||||
'session kept',
|
||||
@@ -1060,23 +993,7 @@ void main() {
|
||||
group('refreshAccessToken', () {
|
||||
final tRefresh = Uri.parse('$serverUrl/allauth/app/v1/tokens/refresh');
|
||||
|
||||
/// Builds a JWT-shaped string with the given payload (signature is a sham,
|
||||
/// we only ever decode the middle segment).
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
|
||||
Future<void> seedHeadlessBundle() async {
|
||||
final prefs = PreferenceHelper.asyncPref;
|
||||
await prefs.setString(PREFS_ACCESS_TOKEN, 'old-access');
|
||||
await prefs.setInt(
|
||||
PREFS_ACCESS_EXPIRES_AT,
|
||||
DateTime.now().add(const Duration(hours: 1)).millisecondsSinceEpoch,
|
||||
);
|
||||
await prefs.setString(PREFS_SERVER_URL, serverUrl);
|
||||
}
|
||||
Future<void> seedHeadlessBundle() => seedSavedLogin(accessToken: 'old-access');
|
||||
|
||||
test('happy path: persists rotated refresh + updates state with new access/exp', () async {
|
||||
await seedHeadlessBundle();
|
||||
@@ -1512,12 +1429,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('involuntary logout surfacing', () {
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
|
||||
/// Replaces the legacy seed from setUp with a restored headless-JWT
|
||||
/// session whose access token expires at [expiresAt].
|
||||
Future<void> seedJwtSession({required DateTime expiresAt}) async {
|
||||
|
||||
@@ -21,15 +21,9 @@ import 'dart:convert';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/core/network/jwt.dart';
|
||||
|
||||
void main() {
|
||||
/// Builds a JWT-shaped string with the given payload (signature is a sham,
|
||||
/// we only ever decode the middle segment).
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
import '../../helpers/fake_auth_backend.dart';
|
||||
|
||||
void main() {
|
||||
group('decodeJwtPayload', () {
|
||||
test('decodes the middle segment into a map', () {
|
||||
final jwt = makeJwt({'sub': '42', 'exp': 1700000000});
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -35,6 +34,7 @@ import 'package:wger/core/shared_preferences.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../helpers/fake_auth_backend.dart';
|
||||
import '../helpers/fake_auth_environment.dart';
|
||||
import 'recovery_screens_test.mocks.dart';
|
||||
|
||||
@@ -48,15 +48,9 @@ void main() {
|
||||
late MockClient mockClient;
|
||||
late MockSecureTokenStorage mockSecureStorage;
|
||||
|
||||
const serverUrl = 'https://wger.example';
|
||||
const accessToken = 'access-token-12345';
|
||||
const powerSyncUrl = 'https://ps.example/';
|
||||
|
||||
final tProbe = Uri.parse('$serverUrl/api/v2/routine/?limit=1');
|
||||
final tVersion = Uri.parse('$serverUrl/api/v2/version/');
|
||||
final tMinAppVersion = Uri.parse('$serverUrl/api/v2/min-app-version/');
|
||||
final tPowerSyncToken = Uri.parse('$serverUrl/api/v2/powersync-token');
|
||||
final tLiveness = Uri.parse('${powerSyncUrl}probes/liveness');
|
||||
const uris = AuthBackendUris();
|
||||
final tProbe = uris.probe;
|
||||
final tLiveness = uris.liveness;
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return ProviderScope(
|
||||
@@ -97,33 +91,15 @@ void main() {
|
||||
when(mockSecureStorage.readRefreshToken()).thenAnswer((_) async => null);
|
||||
when(mockSecureStorage.writeRefreshToken(any)).thenAnswer((_) async {});
|
||||
|
||||
// Wipe async prefs between tests (the platform instance is shared).
|
||||
final prefs = PreferenceHelper.asyncPref;
|
||||
|
||||
// Saved login → autoLogin runs the full probe path.
|
||||
await prefs.setString(PREFS_ACCESS_TOKEN, accessToken);
|
||||
await prefs.setInt(
|
||||
PREFS_ACCESS_EXPIRES_AT,
|
||||
DateTime.now().add(const Duration(hours: 1)).millisecondsSinceEpoch,
|
||||
);
|
||||
await prefs.setString(PREFS_SERVER_URL, serverUrl);
|
||||
await seedSavedLogin();
|
||||
|
||||
// Default happy-path mocks. Test groups override one of these to
|
||||
// steer the auth notifier into the targeted recovery state.
|
||||
when(
|
||||
mockClient.get(tProbe, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) async => Response('', 200));
|
||||
when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200));
|
||||
when(mockClient.get(tMinAppVersion)).thenAnswer((_) async => Response('"0.0.1"', 200));
|
||||
when(
|
||||
mockClient.get(tPowerSyncToken, headers: anyNamed('headers')),
|
||||
).thenAnswer(
|
||||
(_) async => Response(
|
||||
json.encode({'token': 'jwt', 'powersync_url': powerSyncUrl}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
when(mockClient.get(tLiveness)).thenAnswer((_) async => Response('OK', 200));
|
||||
stubAuthBackend(mockClient, uris: uris);
|
||||
});
|
||||
|
||||
group('PowerSyncUnreachableScreen', () {
|
||||
|
||||
@@ -38,6 +38,7 @@ import 'package:wger/features/auth/screens/mfa_challenge_screen.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../helpers/fake_auth_backend.dart';
|
||||
import '../../../helpers/fake_auth_environment.dart';
|
||||
import '../../../helpers/fake_connectivity.dart';
|
||||
import 'auth_screen_test.mocks.dart';
|
||||
@@ -534,28 +535,7 @@ void main() {
|
||||
addTearDown(tester.view.reset);
|
||||
// The config check only runs once login fully reaches loggedIn, so the
|
||||
// version and PowerSync probes must all report a healthy server.
|
||||
when(
|
||||
mockClient.get(Uri.parse('https://wger.de/api/v2/version/')),
|
||||
).thenAnswer((_) => Future(() => Response('"99.99.99"', 200)));
|
||||
when(
|
||||
mockClient.get(Uri.parse('https://wger.de/api/v2/min-app-version/')),
|
||||
).thenAnswer((_) => Future(() => Response('"0.0.1"', 200)));
|
||||
when(
|
||||
mockClient.get(
|
||||
Uri.parse('https://wger.de/api/v2/powersync-token'),
|
||||
headers: anyNamed('headers'),
|
||||
),
|
||||
).thenAnswer(
|
||||
(_) => Future(
|
||||
() => Response(
|
||||
json.encode({'token': 'ps-jwt', 'powersync_url': 'https://ps.example/'}),
|
||||
200,
|
||||
),
|
||||
),
|
||||
);
|
||||
when(
|
||||
mockClient.get(Uri.parse('https://ps.example/probes/liveness')),
|
||||
).thenAnswer((_) => Future(() => Response('OK', 200)));
|
||||
stubAuthBackend(mockClient, uris: const AuthBackendUris(serverUrl: 'https://wger.de'));
|
||||
// _serverConfigSane fetches the exercise list; a `next` URL on a
|
||||
// different host than the server flags a reverse-proxy misconfiguration.
|
||||
when(
|
||||
|
||||
@@ -33,6 +33,7 @@ import 'package:wger/features/auth/screens/mfa_challenge_screen.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../helpers/fake_auth_backend.dart';
|
||||
import '../../../helpers/fake_auth_environment.dart';
|
||||
import 'mfa_challenge_screen_test.mocks.dart';
|
||||
|
||||
@@ -43,19 +44,11 @@ void main() {
|
||||
late MockClient mockClient;
|
||||
late MockSecureTokenStorage mockSecureStorage;
|
||||
|
||||
const serverUrl = 'https://wger.example';
|
||||
const powerSyncUrl = 'https://ps.example/';
|
||||
final tMfa = Uri.parse('$serverUrl/allauth/app/v1/auth/2fa/authenticate');
|
||||
final tVersion = Uri.parse('$serverUrl/api/v2/version/');
|
||||
final tMinAppVersion = Uri.parse('$serverUrl/api/v2/min-app-version/');
|
||||
final tPowerSyncToken = Uri.parse('$serverUrl/api/v2/powersync-token');
|
||||
final tLiveness = Uri.parse('${powerSyncUrl}probes/liveness');
|
||||
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
const serverUrl = testServerUrl;
|
||||
const uris = AuthBackendUris();
|
||||
final tMfa = uris.mfaAuthenticate;
|
||||
final tVersion = uris.version;
|
||||
final tMinAppVersion = uris.minAppVersion;
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return ProviderScope(
|
||||
@@ -92,33 +85,13 @@ void main() {
|
||||
when(mockSecureStorage.readRefreshToken()).thenAnswer((_) async => null);
|
||||
when(mockSecureStorage.writeRefreshToken(any)).thenAnswer((_) async {});
|
||||
|
||||
// Gating-chain happy-path stubs so a successful completeMfa reaches
|
||||
// AuthStatus.loggedIn rather than getting stuck on a probe.
|
||||
when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200));
|
||||
when(mockClient.get(tMinAppVersion)).thenAnswer((_) async => Response('"0.0.1"', 200));
|
||||
when(
|
||||
mockClient.get(tPowerSyncToken, headers: anyNamed('headers')),
|
||||
).thenAnswer(
|
||||
(_) async => Response(
|
||||
jsonEncode({'token': 'ps', 'powersync_url': powerSyncUrl}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
when(mockClient.get(tLiveness)).thenAnswer((_) async => Response('OK', 200));
|
||||
when(
|
||||
mockClient.get(any, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) async => Response(jsonEncode({'next': null}), 200));
|
||||
when(mockClient.get(tVersion)).thenAnswer((_) async => Response('"99.99.99"', 200));
|
||||
when(mockClient.get(tMinAppVersion)).thenAnswer((_) async => Response('"0.0.1"', 200));
|
||||
when(
|
||||
mockClient.get(tPowerSyncToken, headers: anyNamed('headers')),
|
||||
).thenAnswer(
|
||||
(_) async => Response(
|
||||
jsonEncode({'token': 'ps', 'powersync_url': powerSyncUrl}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
when(mockClient.get(tLiveness)).thenAnswer((_) async => Response('OK', 200));
|
||||
// Gating-chain happy-path stubs so a successful completeMfa reaches
|
||||
// AuthStatus.loggedIn rather than getting stuck on a probe. After the
|
||||
// any-match above, so they win.
|
||||
stubAuthBackend(mockClient, uris: uris);
|
||||
});
|
||||
|
||||
Future<void> openScreen(WidgetTester tester, Widget screen) async {
|
||||
|
||||
@@ -20,8 +20,8 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_calculation.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../helpers/pump_app.dart';
|
||||
|
||||
void main() {
|
||||
group('the table', () {
|
||||
@@ -73,10 +73,8 @@ void main() {
|
||||
// added to the table without a string would otherwise show a wrong name
|
||||
late BuildContext ctx;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
testApp(
|
||||
Builder(
|
||||
builder: (context) {
|
||||
ctx = context;
|
||||
return const SizedBox.shrink();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -29,12 +28,11 @@ import 'package:wger/features/measurements/providers/measurement_repository.dart
|
||||
import 'package:wger/features/measurements/screens/measurement_categories_screen.dart';
|
||||
import 'package:wger/features/measurements/widgets/measurement_fab.dart';
|
||||
import 'package:wger/features/measurements/widgets/measurement_tile.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'measurement_categories_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository])
|
||||
@@ -50,7 +48,8 @@ void main() {
|
||||
final mockRepo = MockMeasurementRepository();
|
||||
stubMeasurementReads(mockRepo, categories, entries);
|
||||
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
const MeasurementCategoriesScreen(),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
// A fresh accessor per test: the app-wide singleton keeps the
|
||||
@@ -60,12 +59,7 @@ void main() {
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(entries)),
|
||||
measurementGroupBucketsProvider.overrideWith(groupBucketsFrom(categories, entries)),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const MeasurementCategoriesScreen(),
|
||||
),
|
||||
locale: Locale(locale),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,18 +16,16 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/screens/measurement_category_sort_screen.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/body_weight.dart';
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'measurement_category_sort_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository])
|
||||
@@ -48,15 +46,11 @@ void main() {
|
||||
});
|
||||
|
||||
Widget createSortScreen() {
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
const MeasurementCategorySortScreen(),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: MeasurementCategorySortScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -33,12 +32,11 @@ import 'package:wger/features/measurements/screens/measurement_entries_screen.da
|
||||
import 'package:wger/features/measurements/widgets/charts/line_chart.dart';
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart';
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'measurement_entries_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, NutritionRepository, IngredientRepository])
|
||||
@@ -78,7 +76,16 @@ void main() {
|
||||
stubMeasurementReads(mockMeasurementRepo, [getMeasurementCategories()[0]], entries);
|
||||
}
|
||||
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
TextButton(
|
||||
onPressed: () => key.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(arguments: '1'),
|
||||
builder: (_) => const MeasurementEntriesScreen(),
|
||||
),
|
||||
),
|
||||
child: Container(),
|
||||
),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockMeasurementRepo),
|
||||
// A fresh accessor per test: the app-wide singleton keeps the
|
||||
@@ -89,21 +96,8 @@ void main() {
|
||||
nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo),
|
||||
ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
navigatorKey: key,
|
||||
home: TextButton(
|
||||
onPressed: () => key.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(arguments: '1'),
|
||||
builder: (_) => const MeasurementEntriesScreen(),
|
||||
),
|
||||
),
|
||||
child: Container(),
|
||||
),
|
||||
),
|
||||
locale: Locale(locale),
|
||||
navigatorKey: key,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -36,13 +35,12 @@ import 'package:wger/features/measurements/widgets/charts/line_chart.dart';
|
||||
import 'package:wger/features/measurements/widgets/weight_form.dart';
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart';
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/body_weight.dart';
|
||||
import '../../../../test_data/profile.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'weight_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([
|
||||
@@ -81,7 +79,8 @@ void main() {
|
||||
});
|
||||
|
||||
Widget createWeightScreen({locale = 'en'}) {
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
const WeightScreen(),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockMeasurementRepository),
|
||||
// A fresh accessor per test: the app-wide singleton keeps the
|
||||
@@ -93,13 +92,8 @@ void main() {
|
||||
nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo),
|
||||
ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const WeightScreen(),
|
||||
routes: {FormScreen.routeName: (_) => const FormScreen()},
|
||||
),
|
||||
locale: Locale(locale),
|
||||
routes: {FormScreen.routeName: (_) => const FormScreen()},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,17 +16,15 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/calculation_mark.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'calculation_mark_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository])
|
||||
@@ -41,17 +39,11 @@ void main() {
|
||||
final repo = MockMeasurementRepository();
|
||||
stubMeasurementReads(repo, [waist, category]);
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [measurementRepositoryProvider.overrideWithValue(repo)],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(body: CalculationMark(category, dense: dense)),
|
||||
),
|
||||
),
|
||||
await pumpApp(
|
||||
tester,
|
||||
Scaffold(body: CalculationMark(category, dense: dense)),
|
||||
overrides: [measurementRepositoryProvider.overrideWithValue(repo)],
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('a hand-kept category is not marked at all', (tester) async {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -29,12 +28,11 @@ import 'package:wger/features/measurements/models/measurement_calculation.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/calculation_params.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/exercises.dart';
|
||||
import '../../../helpers/fake_auth_environment.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'calculation_params_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, ExerciseRepository])
|
||||
@@ -69,36 +67,30 @@ void main() {
|
||||
saved = {...params};
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(measurementRepo),
|
||||
exerciseRepositoryProvider.overrideWithValue(exerciseRepo),
|
||||
// The search then reads the local catalogue instead of the API
|
||||
networkStatusProvider.overrideWithValue(false),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
key: formKey,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => SingleChildScrollView(
|
||||
child: CalculationParamsBlock(
|
||||
type: calculationTypeOf(slug)!,
|
||||
params: saved,
|
||||
categoryId: categoryId,
|
||||
onChanged: (next) => setState(() => saved = next),
|
||||
),
|
||||
),
|
||||
await pumpApp(
|
||||
tester,
|
||||
Scaffold(
|
||||
body: Form(
|
||||
key: formKey,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => SingleChildScrollView(
|
||||
child: CalculationParamsBlock(
|
||||
type: calculationTypeOf(slug)!,
|
||||
params: saved,
|
||||
categoryId: categoryId,
|
||||
onChanged: (next) => setState(() => saved = next),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(measurementRepo),
|
||||
exerciseRepositoryProvider.overrideWithValue(exerciseRepo),
|
||||
// The search then reads the local catalogue instead of the API
|
||||
networkStatusProvider.overrideWithValue(false),
|
||||
],
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return formKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/features/measurements/charts/range.dart';
|
||||
@@ -25,11 +24,10 @@ import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
import 'package:wger/features/measurements/widgets/categories_card.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
|
||||
/// A category and the entries it holds, which it no longer carries itself.
|
||||
typedef _Seed = ({MeasurementCategory category, Map<String, List<MeasurementEntry>> entries});
|
||||
@@ -40,7 +38,8 @@ Widget _wrap(
|
||||
List<MeasurementCategory> categories = const [],
|
||||
Map<String, List<MeasurementEntry>> entries = const {},
|
||||
Locale? locale,
|
||||
}) => ProviderScope(
|
||||
}) => testApp(
|
||||
Scaffold(body: child),
|
||||
overrides: [
|
||||
// The component rows read their last known value from its own query
|
||||
latestMeasurementEntriesProvider.overrideWith((ref) => Stream.value(latest)),
|
||||
@@ -48,12 +47,7 @@ Widget _wrap(
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(entries)),
|
||||
measurementGroupBucketsProvider.overrideWith(groupBucketsFrom(categories, entries)),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: locale,
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(body: child),
|
||||
),
|
||||
locale: locale,
|
||||
);
|
||||
|
||||
/// The newest entry per category, i.e. what the query behind the rows returns
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -33,14 +32,13 @@ import 'package:wger/features/measurements/providers/measurement_repository.dart
|
||||
import 'package:wger/features/measurements/widgets/categories.dart';
|
||||
import 'package:wger/features/measurements/widgets/categories_card.dart';
|
||||
import 'package:wger/features/measurements/widgets/measurement_tile.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/body_weight.dart';
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../../test_data/profile.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'categories_test.mocks.dart';
|
||||
|
||||
Widget _wrap(
|
||||
@@ -53,7 +51,8 @@ Widget _wrap(
|
||||
final mockProfileRepo = MockUserProfileRepository();
|
||||
when(mockProfileRepo.watchDrift()).thenAnswer((_) => Stream.value(tUserProfile1));
|
||||
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
const Scaffold(body: CategoriesList()),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockProfileRepo),
|
||||
@@ -64,11 +63,6 @@ Widget _wrap(
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(entries)),
|
||||
measurementGroupBucketsProvider.overrideWith(groupBucketsFrom(categories, entries)),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(body: CategoriesList()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,26 +21,23 @@ import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/features/measurements/charts/range.dart';
|
||||
import 'package:wger/features/measurements/widgets/chart_range_selector.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../helpers/pump_app.dart';
|
||||
|
||||
void main() {
|
||||
late ChartRange picked;
|
||||
|
||||
Future<void> pumpSelector(WidgetTester tester, ChartRange selected) async {
|
||||
picked = selected;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: ChartRangeSelector(
|
||||
value: selected,
|
||||
onChanged: (range) => picked = range,
|
||||
),
|
||||
await pumpApp(
|
||||
tester,
|
||||
Scaffold(
|
||||
body: ChartRangeSelector(
|
||||
value: selected,
|
||||
onChanged: (range) => picked = range,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('every range is offered', (tester) async {
|
||||
|
||||
@@ -22,13 +22,11 @@ import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/features/measurements/charts/series.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/bar_chart.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/line_chart.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
Widget _wrap(Widget child) => MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
import '../../../../helpers/pump_app.dart';
|
||||
|
||||
Widget _wrap(Widget child) => testApp(
|
||||
Scaffold(
|
||||
body: SizedBox(width: 400, height: 300, child: child),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -20,16 +20,14 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/features/measurements/charts/data.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/distribution_chart.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
Widget _wrap(Widget child, {Locale? locale}) => MaterialApp(
|
||||
locale: locale,
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
import '../../../../helpers/pump_app.dart';
|
||||
|
||||
Widget _wrap(Widget child, {Locale? locale}) => testApp(
|
||||
Scaffold(
|
||||
body: SizedBox(width: 400, height: 300, child: child),
|
||||
),
|
||||
locale: locale,
|
||||
);
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -23,13 +23,11 @@ import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/features/measurements/charts/data.dart';
|
||||
import 'package:wger/features/measurements/charts/series.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/heatmap_chart.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
Widget _wrap(Widget child) => MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
import '../../../../helpers/pump_app.dart';
|
||||
|
||||
Widget _wrap(Widget child) => testApp(
|
||||
Scaffold(
|
||||
body: SizedBox(width: 400, height: 300, child: child),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -23,10 +23,12 @@ import 'package:wger/features/measurements/charts/series.dart';
|
||||
import 'package:wger/features/measurements/charts/spark.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/spark_charts.dart';
|
||||
|
||||
import '../../../../helpers/pump_app.dart';
|
||||
|
||||
const _size = Size(150, 40);
|
||||
|
||||
Widget _wrap(Widget spark) => MaterialApp(
|
||||
home: Scaffold(
|
||||
Widget _wrap(Widget spark) => testApp(
|
||||
Scaffold(
|
||||
body: SizedBox(width: _size.width, height: _size.height, child: spark),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -31,12 +30,11 @@ import 'package:wger/features/measurements/widgets/charts/stacked_bar_chart.dart
|
||||
import 'package:wger/features/measurements/widgets/entries.dart';
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart';
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'entries_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, NutritionRepository, IngredientRepository])
|
||||
@@ -66,7 +64,14 @@ void main() {
|
||||
final mockRepo = repo ?? MockMeasurementRepository();
|
||||
stubMeasurementReads(mockRepo, [category], entries);
|
||||
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
Scaffold(
|
||||
body: EntriesList(
|
||||
category,
|
||||
range: ChartRange.last3Months,
|
||||
onRangeChanged: (_) {},
|
||||
),
|
||||
),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
nutritionRepositoryProvider.overrideWithValue(MockNutritionRepository()),
|
||||
@@ -75,17 +80,6 @@ void main() {
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(entries)),
|
||||
measurementGroupBucketsProvider.overrideWith(groupBucketsFrom([category], entries)),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: EntriesList(
|
||||
category,
|
||||
range: ChartRange.last3Months,
|
||||
onRangeChanged: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -29,13 +28,12 @@ import 'package:wger/features/measurements/models/measurement_calculation.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/forms/category.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../../test_data/exercises.dart';
|
||||
import '../../../../../test_data/measurements.dart';
|
||||
import '../../../../helpers/fake_auth_environment.dart';
|
||||
import '../../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../../helpers/pump_app.dart';
|
||||
import 'category_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, ExerciseRepository, UserProfileRepository])
|
||||
@@ -62,17 +60,13 @@ void main() {
|
||||
/// The form as the app shows it: the screen hands it the space and the form
|
||||
/// brings its own scrolling, see FormScreenArguments.hasListView
|
||||
Widget wrap(Widget child) {
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
Scaffold(body: child),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
exerciseRepositoryProvider.overrideWithValue(mockExerciseRepo),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockProfileRepo),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(body: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -27,11 +26,10 @@ import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/forms/entry.dart';
|
||||
import 'package:wger/features/measurements/widgets/imported_entry_warning.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../../test_data/measurements.dart';
|
||||
import '../../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../../helpers/pump_app.dart';
|
||||
import 'entry_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository])
|
||||
@@ -45,17 +43,13 @@ void main() {
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
Scaffold(
|
||||
body: SingleChildScrollView(child: child),
|
||||
),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(child: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -25,11 +24,10 @@ import 'package:wger/core/widgets/decimal_input.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/forms/group_entry.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../../test_data/measurements.dart';
|
||||
import '../../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../../helpers/pump_app.dart';
|
||||
import 'group_entry_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository])
|
||||
@@ -43,17 +41,13 @@ void main() {
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
Scaffold(
|
||||
body: SingleChildScrollView(child: child),
|
||||
),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(child: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,13 @@ import 'package:wger/features/measurements/widgets/charts/line_chart.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/overall_change.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/stacked_bar_chart.dart';
|
||||
import 'package:wger/features/measurements/widgets/helpers.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
|
||||
Widget _wrapChart(Widget chart) => MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
Widget _wrapChart(Widget chart) => testApp(
|
||||
Scaffold(
|
||||
body: SizedBox(width: 400, height: 300, child: chart),
|
||||
),
|
||||
);
|
||||
@@ -50,18 +47,14 @@ Future<void> _pumpWidgetList(
|
||||
WidgetTester tester,
|
||||
List<Widget> Function(BuildContext context) builder,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
builder: (ctx) => Scaffold(
|
||||
body: SingleChildScrollView(child: Column(children: builder(ctx))),
|
||||
),
|
||||
await pumpApp(
|
||||
tester,
|
||||
Builder(
|
||||
builder: (ctx) => Scaffold(
|
||||
body: SingleChildScrollView(child: Column(children: builder(ctx))),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -16,30 +16,24 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/measurement_fab.dart';
|
||||
import 'package:wger/features/measurements/widgets/metric_picker.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'measurement_fab_test.mocks.dart';
|
||||
|
||||
Widget _wrap() {
|
||||
final mockRepo = MockMeasurementRepository();
|
||||
stubMeasurementReads(mockRepo, const [], const {});
|
||||
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
const Scaffold(floatingActionButton: MeasurementsFab()),
|
||||
overrides: [measurementRepositoryProvider.overrideWithValue(mockRepo)],
|
||||
child: const MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(floatingActionButton: MeasurementsFab()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -31,12 +30,11 @@ import 'package:wger/features/measurements/providers/measurement_repository.dart
|
||||
import 'package:wger/features/measurements/screens/measurement_entries_screen.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts/spark_charts.dart';
|
||||
import 'package:wger/features/measurements/widgets/measurement_tile.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'measurement_tile_test.mocks.dart';
|
||||
|
||||
/// The calendar day [daysAgo] days back, at midnight like a day bucket.
|
||||
@@ -64,7 +62,16 @@ Widget _wrap(
|
||||
final mockRepo = MockMeasurementRepository();
|
||||
stubMeasurementReads(mockRepo, categories.isEmpty ? [category] : categories, entries);
|
||||
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 180,
|
||||
height: measurementTileExtent,
|
||||
child: MeasurementTile(category, range: range),
|
||||
),
|
||||
),
|
||||
),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(entries)),
|
||||
@@ -72,23 +79,10 @@ Widget _wrap(
|
||||
groupBucketsFrom(categories.isEmpty ? [category] : categories, entries),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
routes: {
|
||||
MeasurementEntriesScreen.routeName: (_) => const Text('entries-screen'),
|
||||
FormScreen.routeName: (_) => const Text('form-screen'),
|
||||
},
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 180,
|
||||
height: measurementTileExtent,
|
||||
child: MeasurementTile(category, range: range),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
routes: {
|
||||
MeasurementEntriesScreen.routeName: (_) => const Text('entries-screen'),
|
||||
FormScreen.routeName: (_) => const Text('form-screen'),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -31,9 +30,9 @@ import 'package:wger/features/measurements/screens/measurement_entries_screen.da
|
||||
import 'package:wger/features/measurements/widgets/forms/category.dart';
|
||||
import 'package:wger/features/measurements/widgets/metric_picker.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'metric_picker_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, AuthCredentialsStorage])
|
||||
@@ -53,20 +52,16 @@ void main() {
|
||||
});
|
||||
|
||||
Widget wrap() {
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
const Scaffold(body: MetricPickerSheet()),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
authCredentialsStorageProvider.overrideWithValue(mockCredentials),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
routes: {
|
||||
FormScreen.routeName: (_) => const FormScreen(),
|
||||
MeasurementEntriesScreen.routeName: (_) => const MeasurementEntriesScreen(),
|
||||
},
|
||||
home: const Scaffold(body: MetricPickerSheet()),
|
||||
),
|
||||
routes: {
|
||||
FormScreen.routeName: (_) => const FormScreen(),
|
||||
MeasurementEntriesScreen.routeName: (_) => const MeasurementEntriesScreen(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,11 @@ import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/weight_form.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
import '../../../../test_data/body_weight.dart';
|
||||
import '../../../../test_data/profile.dart';
|
||||
import '../../../helpers/measurement_repository_stubs.dart';
|
||||
import '../../../helpers/pump_app.dart';
|
||||
import 'weight_form_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, UserProfileRepository])
|
||||
@@ -57,20 +56,16 @@ void main() {
|
||||
MeasurementEntry? entry,
|
||||
List<Override> overrides = const [],
|
||||
}) {
|
||||
return ProviderScope(
|
||||
return testApp(
|
||||
Scaffold(
|
||||
body: SingleChildScrollView(child: WeightForm(getBodyWeightCategory(), entry)),
|
||||
),
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockProfileRepo),
|
||||
...overrides,
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(child: WeightForm(getBodyWeightCategory(), entry)),
|
||||
),
|
||||
),
|
||||
locale: Locale(locale),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -182,17 +177,13 @@ void main() {
|
||||
await tester.runAsync(pumpEventQueue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: WeightForm(getBodyWeightCategory()),
|
||||
),
|
||||
testApp(
|
||||
Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: WeightForm(getBodyWeightCategory()),
|
||||
),
|
||||
),
|
||||
container: container,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -224,17 +215,13 @@ void main() {
|
||||
await tester.runAsync(pumpEventQueue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: WeightForm(getBodyWeightCategory()),
|
||||
),
|
||||
testApp(
|
||||
Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: WeightForm(getBodyWeightCategory()),
|
||||
),
|
||||
),
|
||||
container: container,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
137
test/helpers/fake_auth_backend.dart
Normal file
137
test/helpers/fake_auth_backend.dart
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (c) 2026 - 2026 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/core/shared_preferences.dart';
|
||||
|
||||
/// The server the auth tests talk to.
|
||||
const testServerUrl = 'https://wger.example';
|
||||
|
||||
/// Where that server says its PowerSync instance lives.
|
||||
const testPowerSyncUrl = 'https://ps.example/';
|
||||
|
||||
/// Builds a JWT-shaped string with [payload]. The signature is a sham, the
|
||||
/// app only decodes the middle segment.
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) =>
|
||||
base64Url.encode(utf8.encode(jsonEncode(m))).replaceAll('=', '');
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
|
||||
/// The endpoints the auth flow calls on its way to a logged-in state.
|
||||
class AuthBackendUris {
|
||||
const AuthBackendUris({this.serverUrl = testServerUrl, this.powerSyncUrl = testPowerSyncUrl});
|
||||
|
||||
final String serverUrl;
|
||||
final String powerSyncUrl;
|
||||
|
||||
Uri get version => Uri.parse('$serverUrl/api/v2/version/');
|
||||
Uri get minAppVersion => Uri.parse('$serverUrl/api/v2/min-app-version/');
|
||||
|
||||
/// Registered without a trailing slash on the Django side.
|
||||
Uri get powerSyncToken => Uri.parse('$serverUrl/api/v2/powersync-token');
|
||||
Uri get liveness => Uri.parse('${powerSyncUrl}probes/liveness');
|
||||
|
||||
/// Where the app looks when the advertised PowerSync URL fails its probe.
|
||||
Uri get fallbackLiveness => Uri.parse('$serverUrl/ps/probes/liveness');
|
||||
|
||||
/// The authenticated request a restored session checks its token with.
|
||||
Uri get probe => Uri.parse('$serverUrl/api/v2/routine/?limit=1');
|
||||
|
||||
Uri get headlessLogin => Uri.parse('$serverUrl/allauth/app/v1/auth/login');
|
||||
Uri get headlessSignup => Uri.parse('$serverUrl/allauth/app/v1/auth/signup');
|
||||
Uri get headlessRefresh => Uri.parse('$serverUrl/allauth/app/v1/tokens/refresh');
|
||||
Uri get mfaAuthenticate => Uri.parse('$serverUrl/allauth/app/v1/auth/2fa/authenticate');
|
||||
}
|
||||
|
||||
/// Stubs the gating chain of a healthy server on [client]: a recent server
|
||||
/// version, an old enough minimum app version, a PowerSync token and a live
|
||||
/// PowerSync instance. Tests override what they exercise afterwards; with
|
||||
/// mockito the stub set last wins, so a catch-all `get(any)` goes before this.
|
||||
///
|
||||
/// Stubs that need `any` for a non-nullable parameter stay in the test: only
|
||||
/// the generated mock classes, which are per test file, accept it.
|
||||
void stubAuthBackend(http.Client client, {AuthBackendUris uris = const AuthBackendUris()}) {
|
||||
when(client.get(uris.version)).thenAnswer((_) async => http.Response('"99.99.99"', 200));
|
||||
when(client.get(uris.minAppVersion)).thenAnswer((_) async => http.Response('"0.0.1"', 200));
|
||||
when(client.get(uris.powerSyncToken, headers: anyNamed('headers'))).thenAnswer(
|
||||
(_) async => http.Response(
|
||||
jsonEncode({'token': 'ps-jwt', 'powersync_url': uris.powerSyncUrl}),
|
||||
200,
|
||||
),
|
||||
);
|
||||
when(client.get(uris.liveness)).thenAnswer((_) async => http.Response('OK', 200));
|
||||
}
|
||||
|
||||
/// Persists a logged-in session, so the auth notifier auto-logs in on build.
|
||||
///
|
||||
/// The token expires far enough in the future that no test trips the
|
||||
/// pre-emptive refresh unless it seeds its own.
|
||||
Future<void> seedSavedLogin({
|
||||
String serverUrl = testServerUrl,
|
||||
String accessToken = 'access-token-12345',
|
||||
}) async {
|
||||
final prefs = PreferenceHelper.asyncPref;
|
||||
await prefs.setString(PREFS_ACCESS_TOKEN, accessToken);
|
||||
await prefs.setInt(
|
||||
PREFS_ACCESS_EXPIRES_AT,
|
||||
DateTime.now().add(const Duration(hours: 1)).millisecondsSinceEpoch,
|
||||
);
|
||||
await prefs.setString(PREFS_SERVER_URL, serverUrl);
|
||||
}
|
||||
|
||||
/// A temp directory behind `path_provider`'s application support directory,
|
||||
/// where the app keeps (and on logout wipes) the PowerSync database.
|
||||
class FakePathProvider {
|
||||
FakePathProvider._(this.dir);
|
||||
|
||||
static const _channel = MethodChannel('plugins.flutter.io/path_provider');
|
||||
|
||||
/// The directory the app sees as its support directory.
|
||||
final Directory dir;
|
||||
|
||||
/// Makes the lookup throw, to exercise a failed wipe.
|
||||
bool failLookup = false;
|
||||
|
||||
/// Installs the fake for the current test; it and its directory are removed
|
||||
/// when the test ends. Call from `setUp` or a test body.
|
||||
static FakePathProvider install({String prefix = 'wger_test'}) {
|
||||
final fake = FakePathProvider._(Directory.systemTemp.createTempSync(prefix));
|
||||
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(_channel, (call) async {
|
||||
if (fake.failLookup) {
|
||||
throw PlatformException(code: 'unavailable', message: 'simulated path lookup failure');
|
||||
}
|
||||
return call.method == 'getApplicationSupportDirectory' ? fake.dir.path : null;
|
||||
});
|
||||
addTearDown(() {
|
||||
messenger.setMockMethodCallHandler(_channel, null);
|
||||
if (fake.dir.existsSync()) {
|
||||
fake.dir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
return fake;
|
||||
}
|
||||
}
|
||||
163
test/helpers/pump_app.dart
Normal file
163
test/helpers/pump_app.dart
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (c) 2026 - 2026 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/misc.dart' show Override;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/l10n/localizations_delegates.dart';
|
||||
|
||||
/// The app shell a widget test needs: a provider scope and a localized
|
||||
/// [MaterialApp] around [home].
|
||||
///
|
||||
/// Pass [container] to share a [ProviderContainer] the test reads from or
|
||||
/// seeds itself (wrapped in an [UncontrolledProviderScope]); otherwise a
|
||||
/// [ProviderScope] with [overrides] is built. [locale] null follows the test
|
||||
/// platform, as a plain [MaterialApp] does. [home] may be null when [routes]
|
||||
/// or [initialRoute] decide what is shown.
|
||||
Widget testApp(
|
||||
Widget? home, {
|
||||
List<Override> overrides = const [],
|
||||
ProviderContainer? container,
|
||||
Locale? locale,
|
||||
Map<String, WidgetBuilder> routes = const {},
|
||||
String? initialRoute,
|
||||
GlobalKey<NavigatorState>? navigatorKey,
|
||||
}) {
|
||||
assert(
|
||||
container == null || overrides.isEmpty,
|
||||
'Overrides belong into the container when one is passed',
|
||||
);
|
||||
|
||||
final app = MaterialApp(
|
||||
locale: locale,
|
||||
localizationsDelegates: appLocalizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
navigatorKey: navigatorKey,
|
||||
initialRoute: initialRoute,
|
||||
routes: routes,
|
||||
home: home,
|
||||
);
|
||||
|
||||
return container != null
|
||||
? UncontrolledProviderScope(container: container, child: app)
|
||||
: ProviderScope(overrides: overrides, child: app);
|
||||
}
|
||||
|
||||
/// Pumps [testApp] and settles.
|
||||
///
|
||||
/// [size] is the logical size of the test view; it is applied through
|
||||
/// `tester.view` and reset when the test ends, so it can't leak into the next
|
||||
/// test the way `setSurfaceSize` does. Without it the test keeps the default
|
||||
/// 800x600. Pass `settle: false` to inspect the first frame or to settle
|
||||
/// yourself (e.g. inside `mockNetworkImagesFor`).
|
||||
Future<void> pumpApp(
|
||||
WidgetTester tester,
|
||||
Widget? home, {
|
||||
List<Override> overrides = const [],
|
||||
ProviderContainer? container,
|
||||
Locale? locale,
|
||||
Map<String, WidgetBuilder> routes = const {},
|
||||
String? initialRoute,
|
||||
GlobalKey<NavigatorState>? navigatorKey,
|
||||
Size? size,
|
||||
double devicePixelRatio = 1.0,
|
||||
bool settle = true,
|
||||
}) async {
|
||||
if (size != null) {
|
||||
setTestViewSize(tester, size, devicePixelRatio: devicePixelRatio);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
testApp(
|
||||
home,
|
||||
overrides: overrides,
|
||||
container: container,
|
||||
locale: locale,
|
||||
routes: routes,
|
||||
initialRoute: initialRoute,
|
||||
navigatorKey: navigatorKey,
|
||||
),
|
||||
);
|
||||
if (settle) {
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the logical size of the test view and resets it when the test ends.
|
||||
void setTestViewSize(WidgetTester tester, Size size, {double devicePixelRatio = 1.0}) {
|
||||
tester.view.physicalSize = size * devicePixelRatio;
|
||||
tester.view.devicePixelRatio = devicePixelRatio;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
/// Key of the button [pumpRoute] taps to open the screen.
|
||||
const routeLauncherKey = Key('test-route-launcher');
|
||||
|
||||
/// Pumps an app whose first screen only opens [screen] as a pushed route,
|
||||
/// then opens it.
|
||||
///
|
||||
/// For screens that read their route arguments or pop back: they need a
|
||||
/// route below them and [arguments] in their settings, which `home` can't
|
||||
/// provide.
|
||||
Future<void> pumpRoute(
|
||||
WidgetTester tester,
|
||||
WidgetBuilder screen, {
|
||||
Object? arguments,
|
||||
List<Override> overrides = const [],
|
||||
ProviderContainer? container,
|
||||
Locale? locale,
|
||||
Map<String, WidgetBuilder> routes = const {},
|
||||
Size? size,
|
||||
double devicePixelRatio = 1.0,
|
||||
bool settle = true,
|
||||
}) async {
|
||||
await pumpApp(
|
||||
tester,
|
||||
Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
key: routeLauncherKey,
|
||||
onPressed: () => Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: RouteSettings(arguments: arguments),
|
||||
builder: screen,
|
||||
),
|
||||
),
|
||||
child: const Text('open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
overrides: overrides,
|
||||
container: container,
|
||||
locale: locale,
|
||||
routes: routes,
|
||||
size: size,
|
||||
devicePixelRatio: devicePixelRatio,
|
||||
settle: false,
|
||||
);
|
||||
await tester.tap(find.byKey(routeLauncherKey));
|
||||
if (settle) {
|
||||
await tester.pumpAndSettle();
|
||||
} else {
|
||||
await tester.pump();
|
||||
}
|
||||
}
|
||||
93
test/helpers/pump_app_test.dart
Normal file
93
test/helpers/pump_app_test.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (c) 2026 - 2026 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
import 'pump_app.dart';
|
||||
|
||||
final _greeting = Provider<String>((ref) => 'real');
|
||||
|
||||
/// Shows what a test can only see through the shell: the provider value, the
|
||||
/// active locale, a translated string and the logical size.
|
||||
class _Probe extends ConsumerWidget {
|
||||
const _Probe();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
return Column(
|
||||
children: [
|
||||
Text('provider: ${ref.watch(_greeting)}'),
|
||||
Text('locale: ${Localizations.localeOf(context).languageCode}'),
|
||||
Text('l10n: ${AppLocalizations.of(context).save}'),
|
||||
Text('size: ${size.width.round()}x${size.height.round()}'),
|
||||
Text('arguments: ${ModalRoute.of(context)?.settings.arguments}'),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('localizes and applies the overrides', (tester) async {
|
||||
await pumpApp(
|
||||
tester,
|
||||
const _Probe(),
|
||||
overrides: [_greeting.overrideWithValue('fake')],
|
||||
locale: const Locale('de'),
|
||||
);
|
||||
|
||||
expect(find.text('provider: fake'), findsOneWidget);
|
||||
expect(find.text('locale: de'), findsOneWidget);
|
||||
expect(find.text('l10n: Speichern'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('uses a passed container', (tester) async {
|
||||
final container = ProviderContainer.test(overrides: [_greeting.overrideWithValue('shared')]);
|
||||
|
||||
await pumpApp(tester, const _Probe(), container: container);
|
||||
|
||||
expect(find.text('provider: shared'), findsOneWidget);
|
||||
});
|
||||
|
||||
group('size', () {
|
||||
testWidgets('sets the logical size', (tester) async {
|
||||
await pumpApp(tester, const _Probe(), size: const Size(390, 844), devicePixelRatio: 3);
|
||||
|
||||
expect(find.text('size: 390x844'), findsOneWidget);
|
||||
expect(tester.view.physicalSize, const Size(1170, 2532));
|
||||
});
|
||||
|
||||
// Runs after the one above: a size that leaked would show here
|
||||
testWidgets('is gone in the next test', (tester) async {
|
||||
await pumpApp(tester, const _Probe());
|
||||
|
||||
expect(find.text('size: 800x600'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('pumpRoute opens the screen as a pushed route with its arguments', (tester) async {
|
||||
await pumpRoute(tester, (_) => const Scaffold(body: _Probe()), arguments: 'id-1');
|
||||
|
||||
expect(find.text('arguments: id-1'), findsOneWidget);
|
||||
expect(find.byKey(routeLauncherKey), findsNothing);
|
||||
expect(tester.state<NavigatorState>(find.byType(Navigator)).canPop(), isTrue);
|
||||
});
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import 'package:wger/database/converters/date_only_text_converter.dart';
|
||||
import 'package:wger/powersync/api_client.dart';
|
||||
import 'package:wger/powersync/connector.dart';
|
||||
|
||||
import '../helpers/fake_auth_backend.dart';
|
||||
import '../helpers/in_memory_drift.dart';
|
||||
import 'connector_test.mocks.dart';
|
||||
|
||||
@@ -49,18 +50,6 @@ void main() {
|
||||
connector = DjangoConnector(baseUrl: 'http://example.invalid', apiClient: MockApiClient());
|
||||
});
|
||||
|
||||
/// Builds a JWT-shaped string with the given payload (signature is a sham,
|
||||
/// we only ever decode the middle segment).
|
||||
String makeJwt(Map<String, dynamic> payload) {
|
||||
String enc(Map<String, dynamic> m) => base64Url
|
||||
.encode(utf8.encode(jsonEncode(m)))
|
||||
.replaceAll(
|
||||
'=',
|
||||
'',
|
||||
);
|
||||
return '${enc({'alg': 'HS256', 'typ': 'JWT'})}.${enc(payload)}.signature';
|
||||
}
|
||||
|
||||
group('genericTransform', () {
|
||||
test('injects the row id and copies all fields', () {
|
||||
final out = connector.genericTransform(
|
||||
|
||||
Reference in New Issue
Block a user