The full window editor is also shown without a person's scope, as a privacy test pumps it, where GrammarHost asserted for want of one. halkyon_app's PersonScope gains maybeOf beside of. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
72 lines
2.4 KiB
Dart
72 lines
2.4 KiB
Dart
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';
|
|
|
|
/// What the person sees: whose dependencies are open above it.
|
|
class const _Person() extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
Text('Data of ${PersonScope.of<TestPerson>(context).person.authUserId}');
|
|
}
|
|
|
|
void main() {
|
|
const ada = SignedIn(authUserId: 'ada', isIdentified: true);
|
|
late TestAppDependencies dependencies;
|
|
|
|
setUp(() => dependencies = TestAppDependencies());
|
|
|
|
Future<void> show(WidgetTester tester, Widget scope) async {
|
|
await tester.pumpWidget(testApp(scope, dependencies: dependencies));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
testWidgets("shows the person's app once their data is open", (
|
|
tester,
|
|
) async {
|
|
await show(tester, const PersonScope(person: ada, child: _Person()));
|
|
|
|
expect(find.text('Data of ada'), findsOneWidget);
|
|
expect(dependencies.opened.single.person, ada);
|
|
});
|
|
|
|
testWidgets("says so when the person's data can't be opened, and offers "
|
|
'to try again; an attempt that works shows the app', (tester) async {
|
|
dependencies.openingError = Exception('database locked');
|
|
await show(tester, const PersonScope(person: ada, child: _Person()));
|
|
|
|
expect(find.text("Couldn't open this device's data."), findsOneWidget);
|
|
expect(find.text('Data of ada'), findsNothing);
|
|
|
|
dependencies.openingError = null;
|
|
await tester.tap(find.text('Try again'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Data of ada'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('maybeOf finds the dependencies of the person signed in '
|
|
'above, and none where nobody is', (tester) async {
|
|
TestPerson? found;
|
|
Widget looking() => Builder(
|
|
builder: (context) {
|
|
found = PersonScope.maybeOf<TestPerson>(context);
|
|
return const SizedBox();
|
|
},
|
|
);
|
|
|
|
await show(tester, PersonScope(person: ada, child: looking()));
|
|
expect(found?.person, ada);
|
|
|
|
await show(tester, looking());
|
|
expect(found, isNull);
|
|
});
|
|
|
|
testWidgets("closes the person's data when it goes away", (tester) async {
|
|
await show(tester, const PersonScope(person: ada, child: _Person()));
|
|
|
|
await show(tester, const Text('Someone else'));
|
|
|
|
expect(dependencies.opened.single.disposed, isTrue);
|
|
});
|
|
}
|