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,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