feat(app,learn,todo): the operator's "This instance" card, screen and badge (ADR 0021, step 1)
Whoever operates the instance approves, refuses and suspends accounts
and names other operators in the app (D21 to D24, D34):
- halkyon_app: InstanceOperatorRepository on
ServerpodInstanceOperatorGateway (the module's instanceOperator
endpoint; refusals as OperatorFailed: notFound, isOperator,
lastOperator, notAllowed for 401 and 403, failed), in AppDependencies.
OperatingCubit counts the accounts that wait: asked as the person's
app opens, after every change, and every 5 minutes only while they
operate the instance, so nobody else's app keeps asking.
InstanceOperatorCard (or its tiles) and WaitingAccountsBadge show
nothing at all for anyone else. InstanceOperatorScreen, laid out as
Settings: the accounts that wait, each showing its four words to read
out before Approve (D33), Refuse for new ones after asking; who
operates, Take back after asking, the last always kept; Name an
operator by handle; Find an account by the start of its handle, with
Suspend after asking and Name as operator. English and German texts
("Admin" as the role word in German).
- Learn: the card right after the Sync card in Settings, which the
cogs' count leads to as their dot leads to Sync; the count on the
Settings cogs of Home and Profile.
- Todo: the tiles in the account sheet and the count on its button.
Todo's server is a member, whose `operating()` is always null, so
nothing shows there until it holds the register.
Tests: the gateway's mapping, the repository, both cubits with their
denials, the card, the badge and the screen; Learn's Settings shows the
card and the count to an operator and neither to anyone else.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
7ac715cd97
commit
31b9c17850
2 changed files with 2999 additions and 28 deletions
|
|
@ -0,0 +1,111 @@
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
import 'package:halkyon_ui/halkyon_ui.dart';
|
||||
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
/// "This instance" in an app's Settings and the count on its cogs, for
|
||||
/// whoever operates the instance alone (Halkyon Learn's ADR 0021, D34).
|
||||
void main() {
|
||||
late TestAppDependencies dependencies;
|
||||
|
||||
OperatedAccount waiting(String id) => OperatedAccount(
|
||||
id: id,
|
||||
handle: id,
|
||||
since: DateTime.utc(2026, 10, 24),
|
||||
waitingSince: DateTime.utc(2026, 10, 24, 9),
|
||||
words: const ['abandon', 'ability', 'able', 'about'],
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
dependencies = TestAppDependencies();
|
||||
dependencies.operatorGateway
|
||||
..operates = true
|
||||
..add(
|
||||
OperatedAccount(
|
||||
id: 'anna',
|
||||
handle: 'anna',
|
||||
since: DateTime.utc(2026, 10),
|
||||
isOperator: true,
|
||||
),
|
||||
)
|
||||
..add(waiting('ben'))
|
||||
..add(waiting('cleo'));
|
||||
});
|
||||
|
||||
Future<void> show(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
testApp(
|
||||
BlocProvider(
|
||||
create: (context) =>
|
||||
OperatingCubit(AppScope.of(context).instanceOperators),
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
actions: const [
|
||||
WaitingAccountsBadge(child: Icon(LucideIcons.settings)),
|
||||
],
|
||||
),
|
||||
body: const Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [InstanceOperatorCard(below: 12), Text('Next card')],
|
||||
),
|
||||
),
|
||||
),
|
||||
dependencies: dependencies,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('an operator sees how many accounts wait, on the card and the '
|
||||
'cog', (tester) async {
|
||||
await show(tester);
|
||||
|
||||
expect(find.text('This instance'), findsOneWidget);
|
||||
expect(find.text('Accounts and operators'), findsOneWidget);
|
||||
expect(find.text('2 accounts wait for approval'), findsOneWidget);
|
||||
expect(find.widgetWithText(CountBadge, '2'), findsOneWidget);
|
||||
expect(find.widgetWithText(Badge, '2'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel(RegExp('2 accounts wait for approval')),
|
||||
findsWidgets,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the card leads to the screen where they are approved', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester);
|
||||
|
||||
await tester.tap(find.text('Accounts and operators'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Waiting'), findsOneWidget);
|
||||
expect(find.text('@ben'), findsOneWidget);
|
||||
expect(find.text('@cleo'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('nobody waiting, the card says so and the cog carries '
|
||||
'nothing', (tester) async {
|
||||
dependencies.operatorGateway.accounts
|
||||
..remove('ben')
|
||||
..remove('cleo');
|
||||
await show(tester);
|
||||
|
||||
expect(find.text('Nobody waits for approval'), findsOneWidget);
|
||||
expect(find.byType(CountBadge), findsNothing);
|
||||
expect(find.byType(Badge), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("someone who doesn't operate the instance sees neither card "
|
||||
'nor count, nor the room for them', (tester) async {
|
||||
dependencies.operatorGateway.operates = false;
|
||||
await show(tester);
|
||||
|
||||
expect(find.text('This instance'), findsNothing);
|
||||
expect(find.byType(Badge), findsNothing);
|
||||
expect(tester.getTopLeft(find.text('Next card')).dy, kToolbarHeight);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,220 @@
|
|||
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';
|
||||
|
||||
/// The operator's screen (Halkyon Learn's ADR 0021, D21 to D24, D33):
|
||||
/// approving once the words read out were confirmed, refusing, suspending,
|
||||
/// naming operators and taking the role back.
|
||||
void main() {
|
||||
late TestAppDependencies dependencies;
|
||||
late FakeInstanceOperatorGateway gateway;
|
||||
|
||||
final anna = OperatedAccount(
|
||||
id: 'anna',
|
||||
handle: 'anna',
|
||||
since: DateTime.utc(2026, 10),
|
||||
isOperator: true,
|
||||
);
|
||||
final ben = OperatedAccount(
|
||||
id: 'ben',
|
||||
handle: 'ben',
|
||||
since: DateTime.utc(2026, 10, 24),
|
||||
waitingSince: DateTime.utc(2026, 10, 24, 9),
|
||||
words: const ['abandon', 'ability', 'able', 'about'],
|
||||
);
|
||||
final bea = OperatedAccount(
|
||||
id: 'bea',
|
||||
handle: 'bea',
|
||||
since: DateTime.utc(2026, 10, 2),
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
dependencies = TestAppDependencies();
|
||||
gateway = dependencies.operatorGateway
|
||||
..operates = true
|
||||
..add(anna)
|
||||
..add(ben)
|
||||
..add(bea);
|
||||
});
|
||||
|
||||
Future<void> show(WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(412, 1400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
testApp(const InstanceOperatorScreen(), dependencies: dependencies),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> tap(WidgetTester tester, Finder finder) async {
|
||||
await tester.ensureVisible(finder);
|
||||
await tester.tap(finder);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('lists who waits, since when, and who operates', (tester) async {
|
||||
await show(tester);
|
||||
|
||||
expect(find.text('This instance'), findsOneWidget);
|
||||
expect(find.text('@ben'), findsOneWidget);
|
||||
expect(find.text('New, waiting since Oct 24, 2026'), findsOneWidget);
|
||||
expect(find.text('@anna'), findsOneWidget);
|
||||
expect(find.text('Take back'), findsOneWidget);
|
||||
expect(find.text('abandon'), findsNothing, reason: 'shown on asking');
|
||||
});
|
||||
|
||||
testWidgets('a waiting account shows its words to read out, and is '
|
||||
'approved only once asked to (D33)', (tester) async {
|
||||
await show(tester);
|
||||
|
||||
await tap(tester, find.text('@ben'));
|
||||
for (final word in ben.words!) {
|
||||
expect(find.text(word), findsOneWidget);
|
||||
}
|
||||
expect(
|
||||
find.text(
|
||||
'Read them these four words, and approve only once they confirm '
|
||||
'these are on their screen.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tap(tester, find.text('Cancel'));
|
||||
expect(gateway.calls, isNot(contains('approve ben')));
|
||||
|
||||
await tap(tester, find.text('@ben'));
|
||||
await tap(tester, find.text('Approve'));
|
||||
|
||||
expect(gateway.calls, contains('approve ben'));
|
||||
expect(find.text('Nobody waits.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('refusing a new account asks first, then deletes it', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester);
|
||||
|
||||
await tap(tester, find.text('@ben'));
|
||||
await tap(tester, find.widgetWithText(TextButton, 'Refuse'));
|
||||
expect(find.text('Refuse this account?'), findsOneWidget);
|
||||
expect(
|
||||
find.text(
|
||||
'It is deleted with everything it has. They can sign up again.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tap(tester, find.widgetWithText(FilledButton, 'Refuse'));
|
||||
|
||||
expect(gateway.accounts, isNot(contains('ben')));
|
||||
expect(find.text('Nobody waits.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a suspended account is found, suspended after asking, and '
|
||||
'waits; it can be approved, never refused', (tester) async {
|
||||
await show(tester);
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'bea');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Since Oct 2, 2026'), findsOneWidget);
|
||||
|
||||
await tap(tester, find.byTooltip('Show menu'));
|
||||
await tap(tester, find.text('Suspend').last);
|
||||
expect(find.text('Suspend this account?'), findsOneWidget);
|
||||
await tap(tester, find.widgetWithText(FilledButton, 'Suspend'));
|
||||
|
||||
expect(gateway.calls, contains('suspend bea'));
|
||||
expect(find.text('Suspended since Oct 25, 2026'), findsOneWidget);
|
||||
expect(find.text('Since Oct 2, 2026 · Suspended'), findsOneWidget);
|
||||
|
||||
await tap(tester, find.text('Suspended since Oct 25, 2026'));
|
||||
expect(find.text('zoo'), findsOneWidget);
|
||||
expect(find.widgetWithText(TextButton, 'Refuse'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('an operator is neither suspended nor offered it', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester);
|
||||
|
||||
await tester.enterText(find.byType(TextField), '@an');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Since Oct 1, 2026 · Operator'), findsOneWidget);
|
||||
expect(find.byTooltip('Show menu'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a handle nobody has is said so', (tester) async {
|
||||
await show(tester);
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'zed');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text("No account's handle starts like this."), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('naming an operator by handle, and taking the role back after '
|
||||
'asking', (tester) async {
|
||||
await show(tester);
|
||||
|
||||
await tap(tester, find.text('Name an operator'));
|
||||
expect(
|
||||
find.text(
|
||||
'They approve, refuse and suspend accounts here, and name '
|
||||
'operators, as you do.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.enterText(find.byType(TextField).last, 'bea');
|
||||
await tap(tester, find.widgetWithText(FilledButton, 'Name'));
|
||||
|
||||
expect(gateway.accounts['bea']!.isOperator, isTrue);
|
||||
expect(find.text('Take back'), findsNWidgets(2));
|
||||
|
||||
await tap(tester, find.text('Take back').last);
|
||||
expect(find.text('Take back the role?'), findsOneWidget);
|
||||
await tap(tester, find.widgetWithText(FilledButton, 'Take back'));
|
||||
|
||||
expect(gateway.accounts['bea']!.isOperator, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('the last operator stays, and the screen says why', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester);
|
||||
|
||||
await tap(tester, find.text('Take back'));
|
||||
await tap(tester, find.widgetWithText(FilledButton, 'Take back'));
|
||||
|
||||
expect(
|
||||
find.text('The instance needs at least one operator.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(gateway.accounts['anna']!.isOperator, isTrue);
|
||||
});
|
||||
|
||||
testWidgets("someone who doesn't operate the instance is shown nothing of "
|
||||
'its accounts', (tester) async {
|
||||
gateway.operates = false;
|
||||
await show(tester);
|
||||
|
||||
expect(
|
||||
find.text("Only the instance's operators can do this."),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('@ben'), findsNothing);
|
||||
expect(find.text('Try again'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an instance out of reach is said so, and read again', (
|
||||
tester,
|
||||
) async {
|
||||
gateway.failing = const OperatorFailed(OperatorProblem.failed);
|
||||
await show(tester);
|
||||
expect(find.text("Couldn't reach the server."), findsOneWidget);
|
||||
|
||||
gateway.failing = null;
|
||||
await tap(tester, find.text('Try again'));
|
||||
expect(find.text('@ben'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue