halkyon/packages/halkyon_app/test/simplelogin/widget/simplelogin_section_test.dart

117 lines
3.5 KiB
Dart
Raw Normal View History

import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
import 'package:halkyon_app/testing.dart';
import 'package:material_ui/material_ui.dart';
const password = 'correct horse battery';
void main() {
late FakeAuthGateway gateway;
late TestAppDependencies dependencies;
setUp(() {
gateway = FakeAuthGateway();
dependencies = TestAppDependencies(gateway: gateway);
dependencies.simpleLoginGateway.isOffered = true;
});
tearDown(() => dependencies.dispose());
/// An app's account section.
Future<void> show(WidgetTester tester) async {
tester.view.physicalSize = const Size(412, 1200);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
testApp(
const Scaffold(
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: SimpleLoginSection(gapAbove: 16),
),
),
dependencies: dependencies,
),
);
await tester.pumpAndSettle();
}
Future<void> signInAccount() =>
gateway.useSession(const SessionGrant('person-9', 'session-9'));
testWidgets('an account without SimpleLogin is offered to add it', (
tester,
) async {
await signInAccount();
await show(tester);
expect(find.text('SimpleLogin'), findsOneWidget);
expect(find.widgetWithText(ListTile, 'Add SimpleLogin'), findsOneWidget);
expect(
find.text('Sign in with SimpleLogin, or with your Proton account.'),
findsOneWidget,
);
});
testWidgets('nothing where the instance offers no SimpleLogin', (
tester,
) async {
dependencies.simpleLoginGateway.isOffered = false;
await signInAccount();
await show(tester);
expect(find.textContaining('SimpleLogin'), findsNothing);
});
testWidgets('an account that has it: one more way in', (tester) async {
dependencies.simpleLoginGateway.addAccount(
'person-9',
subject: 'simplelogin-ben',
);
await signInAccount();
await show(tester);
expect(find.widgetWithText(ListTile, 'SimpleLogin'), findsOneWidget);
expect(find.text('Signs you in'), findsOneWidget);
expect(find.text('Add SimpleLogin'), findsNothing);
});
testWidgets('adding it: an account with its keys is done once the browser '
'is back, says so, and shows it as a way in', (tester) async {
final material = await dependencies.crypto.newKeys(password);
dependencies.simpleLoginGateway.accounts['person-9'] =
FakeSimpleLoginAccount(handle: 'ben', keys: material.setup);
await signInAccount();
await show(tester);
await tester.tap(find.widgetWithText(ListTile, 'Add SimpleLogin'));
await tester.pumpAndSettle();
expect(find.text('SimpleLogin added.'), findsOneWidget);
expect(dependencies.simpleLoginGateway.linked, {
'simplelogin-anna': 'person-9',
});
expect(find.text('Signs you in'), findsOneWidget);
});
testWidgets("a SimpleLogin account that is another account's is refused", (
tester,
) async {
dependencies.simpleLoginGateway.addAccount(
'person-7',
subject: 'simplelogin-anna',
);
await signInAccount();
await show(tester);
await tester.tap(find.widgetWithText(ListTile, 'Add SimpleLogin'));
await tester.pumpAndSettle();
expect(
find.text('This SimpleLogin account belongs to another account here.'),
findsOneWidget,
);
expect(dependencies.simpleLoginGateway.linked, {
'simplelogin-anna': 'person-7',
});
});
}