test(app): the password cubits' states, every refusal included

Signing in (a code, a recovery code, an account never finished, a lost
authenticator by mail and by phrase, an impostor instance, no
connection), setting up (signing up, a password for someone signed in,
finishing an account's reset with new keys or the old), getting back in
(with the phrase, starting a reset without it) and the account section
(what keeps the account, its steps, adding an authenticator, a new
phrase), each as the states it emits.

They found that reading what keeps the account wrapped two refusals at
once in a ParallelWaitError, which no caller takes for one: offline, the
account section showed nothing. The first refusal now goes up as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-20 20:12:31 +02:00
commit b51445a01a
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -0,0 +1,28 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
/// The states [cubit] emits while [step] runs, in order.
Future<List<S>> statesOf<S>(
BlocBase<S> cubit,
Future<void> Function() step,
) async {
final states = <S>[];
final listening = cubit.stream.listen(states.add);
await step();
// A cubit's stream hands its states on in a microtask.
await Future<void>.delayed(Duration.zero);
await listening.cancel();
return states;
}
/// The states [cubit] emits as [step] (not awaited: it emits at once).
Future<List<S>> statesNow<S>(BlocBase<S> cubit, void Function() step) =>
statesOf(cubit, () async => step());
/// A refusal of [problem].
Matcher refusedAs(PasswordProblem problem) => isA<PasswordFailed>().having(
(failed) => failed.problem,
'problem',
problem,
);