feat(app): phone onboarding (server, then password) kept across launches; a known server opens straight into the app; a refused session asks for the password
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_session.dart';
|
||||
|
||||
void main() {
|
||||
test('a known server opens the app instead of the connection screen', () {
|
||||
final fresh = AppSession(endpoint: null);
|
||||
final known = AppSession(endpoint: null, knownServer: true);
|
||||
addTearDown(fresh.dispose);
|
||||
addTearDown(known.dispose);
|
||||
expect(fresh.everConnected, isFalse);
|
||||
expect(known.everConnected, isTrue);
|
||||
});
|
||||
}
|
||||
@@ -26,29 +26,25 @@ class _TestSettingsStore implements SettingsStore {
|
||||
void main() {
|
||||
const nativeBase = 'http://127.0.0.1:8096/';
|
||||
|
||||
test(
|
||||
'uses saved endpoint natively only when build configuration is blank',
|
||||
() async {
|
||||
final store = _TestSettingsStore('wss://saved.example.test');
|
||||
final saved = await resolveLaunchServer(
|
||||
base: Uri.parse(nativeBase),
|
||||
configured: '',
|
||||
web: false,
|
||||
settingsStore: store,
|
||||
);
|
||||
expect(saved.uri, Uri.parse('wss://saved.example.test/connect'));
|
||||
expect(store.loads, 1);
|
||||
test('a saved endpoint wins over the build default on a phone', () async {
|
||||
final store = _TestSettingsStore('wss://saved.example.test');
|
||||
final saved = await resolveLaunchServer(
|
||||
base: Uri.parse(nativeBase),
|
||||
configured: 'ws://build.example.test',
|
||||
web: false,
|
||||
settingsStore: store,
|
||||
);
|
||||
expect(saved.uri, Uri.parse('wss://saved.example.test/connect'));
|
||||
|
||||
final configured = await resolveLaunchServer(
|
||||
base: Uri.parse(nativeBase),
|
||||
configured: 'ws://build.example.test',
|
||||
web: false,
|
||||
settingsStore: store,
|
||||
);
|
||||
expect(configured.uri, Uri.parse('ws://build.example.test/connect'));
|
||||
expect(store.loads, 1);
|
||||
},
|
||||
);
|
||||
// Nothing saved yet: the build default stands (and pre-fills onboarding).
|
||||
final fallback = await resolveLaunchServer(
|
||||
base: Uri.parse(nativeBase),
|
||||
configured: 'ws://build.example.test',
|
||||
web: false,
|
||||
settingsStore: _TestSettingsStore(''),
|
||||
);
|
||||
expect(fallback.uri, Uri.parse('ws://build.example.test/connect'));
|
||||
});
|
||||
|
||||
test(
|
||||
'blank or failed settings load leaves native configuration required',
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/pipelines_root.dart';
|
||||
import 'package:pipelines_app/application/server_endpoint.dart';
|
||||
import 'package:pipelines_app/core/session/server_session.dart';
|
||||
import 'package:pipelines_app/features/onboarding/onboarding_flow.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_store.dart';
|
||||
|
||||
class _Store implements SettingsStore {
|
||||
@override
|
||||
Future<SettingsValues> load() async => const SettingsValues();
|
||||
|
||||
@override
|
||||
Future<bool> saveServerUrl(String value) async => true;
|
||||
|
||||
@override
|
||||
Future<bool> saveWorkspace(String value) async => true;
|
||||
}
|
||||
|
||||
ServerEndpoint _server(String url) => ServerEndpoint.resolve(
|
||||
base: Uri.parse('file:///'),
|
||||
web: false,
|
||||
configured: url,
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'a first launch starts at the server, pre-filled from the build',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
PipelinesRoot(
|
||||
server: _server(''),
|
||||
buildDefault: 'wss://build.example/connect',
|
||||
check: (_) async => SessionState.signedOut,
|
||||
settingsStore: _Store(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(OnboardingFlow), findsOneWidget);
|
||||
expect(find.byKey(const Key('onboarding-server')), findsOneWidget);
|
||||
expect(find.text('wss://build.example/connect'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a kept session the server refuses asks for the password', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
PipelinesRoot(
|
||||
server: _server('wss://home.example/connect'),
|
||||
// A saved server with no kept session goes to onboarding directly.
|
||||
signedIn: false,
|
||||
check: (_) async => SessionState.signedOut,
|
||||
settingsStore: _Store(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('onboarding-server')), findsOneWidget);
|
||||
expect(find.text('wss://home.example/connect'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/session/server_session.dart';
|
||||
import 'package:pipelines_app/features/onboarding/onboarding_flow.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('server, then password; both kept, then the app opens', (
|
||||
tester,
|
||||
) async {
|
||||
final saved = <String>[];
|
||||
final signIns = <(Uri, String)>[];
|
||||
Uri? done;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: OnboardingFlow(
|
||||
initialServer: 'wss://build.example/connect',
|
||||
check: (_) async => SessionState.signedOut,
|
||||
signIn: (endpoint, password) async {
|
||||
signIns.add((endpoint, password));
|
||||
return password == 'right-password' ? null : 'Wrong password.';
|
||||
},
|
||||
saveServer: (url) async => saved.add(url),
|
||||
onDone: (endpoint) => done = endpoint,
|
||||
),
|
||||
),
|
||||
);
|
||||
// The build's server is pre-filled; another one can be typed.
|
||||
expect(find.text('wss://build.example/connect'), findsOneWidget);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('onboarding-server')),
|
||||
'wss://home.example/connect',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('onboarding-next')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved, ['wss://home.example/connect']);
|
||||
expect(find.byKey(const Key('onboarding-password')), findsOneWidget);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('onboarding-password')),
|
||||
'nope-nope',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('onboarding-next')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Wrong password.'), findsOneWidget);
|
||||
expect(done, isNull);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('onboarding-password')),
|
||||
'right-password',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('onboarding-next')));
|
||||
// Signed in: the app replaces this screen (the spinner stays until then).
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(done, Uri.parse('wss://home.example/connect'));
|
||||
expect(signIns.last.$1, Uri.parse('wss://home.example/connect'));
|
||||
});
|
||||
|
||||
testWidgets('an unreachable server is explained and nothing is kept', (
|
||||
tester,
|
||||
) async {
|
||||
final saved = <String>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: OnboardingFlow(
|
||||
check: (_) async => SessionState.unreachable,
|
||||
signIn: (_, _) async => null,
|
||||
saveServer: (url) async => saved.add(url),
|
||||
onDone: (_) {},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('onboarding-server')),
|
||||
'wss://nowhere.example/connect',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('onboarding-next')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('onboarding-error')), findsOneWidget);
|
||||
expect(find.byKey(const Key('onboarding-password')), findsNothing);
|
||||
expect(saved, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a refused session asks only for the password again', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: OnboardingFlow(
|
||||
initialServer: 'wss://home.example/connect',
|
||||
startAtPassword: true,
|
||||
check: (_) async => SessionState.signedOut,
|
||||
signIn: (_, _) async => null,
|
||||
onDone: (_) {},
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const Key('onboarding-password')), findsOneWidget);
|
||||
expect(find.byKey(const Key('onboarding-server')), findsNothing);
|
||||
expect(find.text('Change server'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user