initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:manager/app.dart';
|
||||
import 'package:manager/core/utils/shared_preferences_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Future<void> _pumpApp(WidgetTester tester, Map<String, Object> prefsValues) async {
|
||||
// Wide enough that NavRailShell renders its expanded (non-narrow) rail,
|
||||
// which is what shows the "NodeMaster" wordmark asserted on below.
|
||||
tester.view.physicalSize = const Size(1280, 800);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
SharedPreferences.setMockInitialValues(prefsValues);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
// Matches main.dart: no container-wide auto-retry, so a deliberately
|
||||
// unreachable test connection settles into AsyncError deterministically
|
||||
// instead of retrying with backoff mid-test.
|
||||
retry: (retryCount, error) => null,
|
||||
overrides: [sharedPreferencesProvider.overrideWithValue(prefs)],
|
||||
child: const App(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('redirects to Settings when no connection is configured', (tester) async {
|
||||
await _pumpApp(tester, {});
|
||||
|
||||
expect(find.text('NodeMaster'), findsOneWidget);
|
||||
// The router redirect lands on Settings — its "Connections" block
|
||||
// header (unique to that screen) proves we're actually there, not
|
||||
// just that the nav rail lists the label.
|
||||
expect(find.text('Connections'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('launches on the Dashboard when a connection is configured', (tester) async {
|
||||
await _pumpApp(tester, {
|
||||
// Port 1 refuses immediately rather than hanging until a timeout,
|
||||
// so the test doesn't depend on real network access or reachability
|
||||
// — only on routing/shell behavior once a connection exists.
|
||||
'connections': '[{"id":"conn_test","name":"Test","baseUrl":"http://127.0.0.1:1"}]',
|
||||
'active_connection_id': 'conn_test',
|
||||
});
|
||||
|
||||
expect(find.text('NodeMaster'), findsOneWidget);
|
||||
expect(find.text('Dashboard'), findsWidgets);
|
||||
expect(find.text('Services'), findsOneWidget);
|
||||
expect(find.text('Settings'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user