halkyon_app: instances, sign-in and sync plumbing for Halkyon's apps
What every Halkyon app's shell needs, taken from Halkyon Learn's and set on halkyon_base's client: the instances a device keeps an account on, the first start's tiles and where an instance keeps people's data, the account switcher; signing in anonymously, with GitHub or an email code, switching person and the start screen; the gates that build an app's dependencies per instance and per person; and the sync service with its status, Settings card and banner. Texts of its own in English and German take the app's name; what only the app can say, it passes in. Fakes for apps' tests are in testing.dart. An instance's basics now name the app it serves (`app`, set by the host's configuration), and an app accepts only an instance of its own. SerialQueue and CoalescingRunner move into halkyon_core. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
af1de799f4
commit
e23cc77f7c
1 changed files with 10761 additions and 10 deletions
86
packages/halkyon_app/test/instance/instance_choice_test.dart
Normal file
86
packages/halkyon_app/test/instance/instance_choice_test.dart
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
|
||||
void main() {
|
||||
final builtIn = Instance.parse('learn.halkyon.eu')!;
|
||||
final other = Instance.parse('learn.example.org')!;
|
||||
late MemoryInstanceStore store;
|
||||
late List<Instance> forgotten;
|
||||
|
||||
InstanceChoice choice() => InstanceChoice(
|
||||
store,
|
||||
builtIn: builtIn,
|
||||
forget: (instance) async {
|
||||
forgotten.add(instance);
|
||||
},
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
store = MemoryInstanceStore();
|
||||
forgotten = [];
|
||||
});
|
||||
|
||||
test('a new install has no instance until one is chosen', () async {
|
||||
final instances = choice();
|
||||
await instances.load(usedBefore: false);
|
||||
|
||||
expect(instances.current, isNull);
|
||||
expect(instances.known, isEmpty);
|
||||
|
||||
await instances.use(other);
|
||||
expect(instances.current, other);
|
||||
expect(store.kept?.current, other);
|
||||
expect(store.kept?.known, [other]);
|
||||
});
|
||||
|
||||
test('an install from before there was a choice goes on with the '
|
||||
"build's instance", () async {
|
||||
final instances = choice();
|
||||
await instances.load(usedBefore: true);
|
||||
|
||||
expect(instances.current, builtIn);
|
||||
expect(store.kept?.current, builtIn);
|
||||
expect(store.kept?.known, [builtIn]);
|
||||
});
|
||||
|
||||
test('what was chosen is read back', () async {
|
||||
store = MemoryInstanceStore((current: other, known: [builtIn, other]));
|
||||
final instances = choice();
|
||||
await instances.load(usedBefore: true);
|
||||
|
||||
expect(instances.current, other);
|
||||
expect(instances.known, [builtIn, other]);
|
||||
});
|
||||
|
||||
test('switching keeps every account; removing one forgets what the '
|
||||
'device holds of it, never of the one in use', () async {
|
||||
final instances = choice();
|
||||
await instances.load(usedBefore: true);
|
||||
await instances.use(other);
|
||||
await instances.use(builtIn);
|
||||
expect(instances.known, [builtIn, other]);
|
||||
|
||||
await instances.remove(builtIn);
|
||||
expect(forgotten, isEmpty, reason: 'in use');
|
||||
|
||||
await instances.remove(other);
|
||||
expect(forgotten, [other]);
|
||||
expect(instances.known, [builtIn]);
|
||||
expect(store.kept?.current, builtIn);
|
||||
expect(store.kept?.known, [builtIn]);
|
||||
});
|
||||
|
||||
test('tells its listeners of every change', () async {
|
||||
final instances = choice();
|
||||
var changes = 0;
|
||||
instances.addListener(() => changes++);
|
||||
|
||||
await instances.load(usedBefore: false);
|
||||
await instances.use(other);
|
||||
await instances.use(builtIn);
|
||||
await instances.remove(other);
|
||||
|
||||
expect(changes, 4);
|
||||
});
|
||||
}
|
||||
Reference in a new issue