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
2 changed files with 10761 additions and 10 deletions
|
|
@ -0,0 +1,62 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/l10n/halkyon_app_localizations_de.dart';
|
||||
import 'package:halkyon_app/l10n/halkyon_app_localizations_en.dart';
|
||||
|
||||
void main() {
|
||||
final en = HalkyonAppLocalizationsEn();
|
||||
final de = HalkyonAppLocalizationsDe();
|
||||
const names = {'CH': 'Switzerland', 'DE': 'Germany'};
|
||||
String? words(InstanceLocations locations) =>
|
||||
instanceLocationWords(en, locations, names);
|
||||
|
||||
test('data and backups in one place are named once', () {
|
||||
expect(
|
||||
words(const InstanceLocations(data: 'EU', backups: 'EU')),
|
||||
'Data and backups: European Union',
|
||||
);
|
||||
});
|
||||
|
||||
test('data and backups apart are named a line each', () {
|
||||
expect(
|
||||
words(const InstanceLocations(data: 'EU', backups: 'CH')),
|
||||
'Data: European Union\nBackups: Switzerland',
|
||||
);
|
||||
});
|
||||
|
||||
test('an instance keeping no backups says so', () {
|
||||
expect(
|
||||
words(
|
||||
const InstanceLocations(
|
||||
data: 'CH',
|
||||
backups: InstanceLocations.noBackups,
|
||||
),
|
||||
),
|
||||
'Data: Switzerland\nNo backups',
|
||||
);
|
||||
});
|
||||
|
||||
test('what the instance leaves unsaid is left out', () {
|
||||
expect(words(const InstanceLocations(data: 'DE')), 'Data: Germany');
|
||||
expect(
|
||||
words(const InstanceLocations(backups: 'CH')),
|
||||
'Backups: Switzerland',
|
||||
);
|
||||
expect(words(const InstanceLocations()), isNull);
|
||||
});
|
||||
|
||||
test('a country without a name here goes by its code', () {
|
||||
expect(words(const InstanceLocations(data: 'XK')), 'Data: XK');
|
||||
});
|
||||
|
||||
test('in German too, without the articles some countries take', () {
|
||||
expect(
|
||||
instanceLocationWords(
|
||||
de,
|
||||
const InstanceLocations(data: 'EU', backups: 'CH'),
|
||||
const {'CH': 'Schweiz'},
|
||||
),
|
||||
'Daten: Europäische Union\nSicherungen: Schweiz',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
void main() {
|
||||
late List<String> tapped;
|
||||
|
||||
setUp(() => tapped = []);
|
||||
|
||||
/// Shows a tile beside something else to move the pointer or focus to.
|
||||
Future<void> show(WidgetTester tester, {bool? expanded}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
TextButton(onPressed: () {}, child: const Text('Elsewhere')),
|
||||
InstanceTile(
|
||||
icon: const Icon(LucideIcons.globe),
|
||||
label: 'learn.halkyon.eu',
|
||||
tagline: 'Comes with the app',
|
||||
expanded: expanded,
|
||||
onTap: () => tapped.add('tile'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
double ring(WidgetTester tester) =>
|
||||
tester.widget<Opacity>(find.byKey(InstanceTile.ringKey)).opacity;
|
||||
|
||||
double tagline(WidgetTester tester) => tester
|
||||
.widget<Opacity>(
|
||||
find.ancestor(
|
||||
of: find.text('Comes with the app'),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.opacity;
|
||||
|
||||
testWidgets('without a mouse, the tagline shows from the start', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester);
|
||||
|
||||
expect(tagline(tester), 1);
|
||||
expect(ring(tester), 0);
|
||||
});
|
||||
|
||||
testWidgets('with a mouse, the ring and the tagline come in under the '
|
||||
'pointer and go once it leaves', (tester) async {
|
||||
await show(tester);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
addTearDown(mouse.removePointer);
|
||||
await mouse.addPointer(location: tester.getCenter(find.text('Elsewhere')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tagline(tester), 0);
|
||||
expect(ring(tester), 0);
|
||||
|
||||
await mouse.moveTo(tester.getCenter(find.byType(Icon)));
|
||||
// The frame that starts it, then halfway.
|
||||
await tester.pump();
|
||||
await tester.pump(InstanceTile.duration ~/ 2);
|
||||
expect(ring(tester), inExclusiveRange(0, 1), reason: 'it fades in');
|
||||
await tester.pumpAndSettle();
|
||||
expect(tagline(tester), 1);
|
||||
expect(ring(tester), 1);
|
||||
|
||||
await mouse.moveTo(tester.getCenter(find.text('Elsewhere')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tagline(tester), 0);
|
||||
expect(ring(tester), 0);
|
||||
});
|
||||
|
||||
testWidgets("the keyboard's focus rings it, and Enter chooses it", (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester);
|
||||
|
||||
// From Elsewhere to the tile.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(ring(tester), 1);
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
expect(tapped, ['tile']);
|
||||
});
|
||||
|
||||
testWidgets('it rings while pressed', (tester) async {
|
||||
await show(tester);
|
||||
|
||||
final finger = await tester.startGesture(
|
||||
tester.getCenter(find.byType(Icon)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(ring(tester), 1);
|
||||
|
||||
await finger.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(ring(tester), 0);
|
||||
expect(tapped, ['tile']);
|
||||
});
|
||||
|
||||
testWidgets('it stays ringed while what it opens is open', (tester) async {
|
||||
await show(tester, expanded: true);
|
||||
expect(ring(tester), 1);
|
||||
|
||||
await show(tester, expanded: false);
|
||||
await tester.pumpAndSettle();
|
||||
expect(ring(tester), 0);
|
||||
});
|
||||
|
||||
testWidgets('a screen reader hears one button, its tagline included', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester, expanded: false);
|
||||
|
||||
expect(
|
||||
// The label's node is merged into the tile's.
|
||||
tester.getSemantics(find.text('learn.halkyon.eu')),
|
||||
matchesSemantics(
|
||||
label: 'learn.halkyon.eu\nComes with the app',
|
||||
isButton: true,
|
||||
hasTapAction: true,
|
||||
hasFocusAction: true,
|
||||
isFocusable: true,
|
||||
hasExpandedState: true,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('with animations off, it rings at once', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
// The app's own MediaQuery would hide one above it.
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(disableAnimations: true),
|
||||
child: child!,
|
||||
),
|
||||
home: Scaffold(
|
||||
body: InstanceTile(
|
||||
icon: const Icon(LucideIcons.globe),
|
||||
label: 'learn.halkyon.eu',
|
||||
tagline: 'Comes with the app',
|
||||
expanded: false,
|
||||
onTap: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.startGesture(tester.getCenter(find.byType(Icon)));
|
||||
await tester.pump();
|
||||
expect(ring(tester), 1);
|
||||
});
|
||||
}
|
||||
Reference in a new issue