feat(app): one Profile for every app, the person's own tab first, then each app's (ADR 0014)
The public profile was already one per person for every service of an instance (the register, ADR 0016); its app side was Learn's alone. It moves into halkyon_app: the model, the repository on the module's endpoints, the form, the avatar drawn on the device and the sheet with someone's profile. They take the Public prefix (PublicProfileRepository, BasePublicProfileGateway), as Train's own ProfileRepository holds the body's figures. AppDependencies gains profiles and files, the picker the avatar is chosen with, which moves out of Learn too. HalkyonProfile is every app's Profile screen: the person's own tab first, the same in every app (the account and the ways they sign in, the app's own cards, then the public profile), then the app's own tabs, folding into the title. Learn adds its inbox and Statistics. Train adds Progress, Days and, where nothing records, Plans, and so opens on the person's tab, no longer on Progress. Todo, which has no Profile tab, opens it from a row at the top of Browse, where Todoist keeps the account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
a0bb75f1ad
commit
b7b0b937fe
2 changed files with 1668 additions and 1293 deletions
|
|
@ -1,66 +0,0 @@
|
|||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/data/avatar_image.dart';
|
||||
|
||||
/// A PNG [width] × [height], red on its left half, blue on its right.
|
||||
Future<Uint8List> picture(int width, int height) async {
|
||||
final recorder = ui.PictureRecorder();
|
||||
ui.Canvas(recorder)
|
||||
..drawRect(
|
||||
ui.Rect.fromLTWH(0, 0, width / 2, height.toDouble()),
|
||||
ui.Paint()..color = const ui.Color(0xFFFF0000),
|
||||
)
|
||||
..drawRect(
|
||||
ui.Rect.fromLTWH(width / 2, 0, width / 2, height.toDouble()),
|
||||
ui.Paint()..color = const ui.Color(0xFF0000FF),
|
||||
);
|
||||
final image = await recorder.endRecording().toImage(width, height);
|
||||
final png = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
return png!.buffer.asUint8List();
|
||||
}
|
||||
|
||||
Future<ui.Image> decoded(Uint8List png) async {
|
||||
final codec = await ui.instantiateImageCodec(png);
|
||||
return (await codec.getNextFrame()).image;
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('a picture becomes its middle square, at most 400 pixels a side, as '
|
||||
'a PNG', () async {
|
||||
final wide = await avatarPng(await picture(1200, 600));
|
||||
final image = await decoded(wide);
|
||||
|
||||
expect((image.width, image.height), (400, 400));
|
||||
expect(wide.sublist(0, 8), [
|
||||
0x89,
|
||||
0x50,
|
||||
0x4e,
|
||||
0x47,
|
||||
0x0d,
|
||||
0x0a,
|
||||
0x1a,
|
||||
0x0a,
|
||||
]);
|
||||
// The middle square of a picture red and blue side by side holds both.
|
||||
final pixels = (await image.toByteData())!;
|
||||
expect(pixels.getUint8(0), greaterThan(200));
|
||||
expect(pixels.getUint8(399 * 4 + 2), greaterThan(200));
|
||||
});
|
||||
|
||||
test('a small picture keeps its size', () async {
|
||||
final image = await decoded(await avatarPng(await picture(100, 160)));
|
||||
|
||||
expect((image.width, image.height), (100, 100));
|
||||
});
|
||||
|
||||
test('what is no picture is refused', () async {
|
||||
await expectLater(
|
||||
avatarPng(Uint8List.fromList([1, 2, 3])),
|
||||
throwsA(anything),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -5,14 +5,9 @@ import 'package:flutter_test/flutter_test.dart';
|
|||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/router/route_paths.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/bloc/public_profile_bloc.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/data/profile_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/model/public_profile.dart';
|
||||
import 'package:halkyon_ui/halkyon_ui.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../support/fake_file_picker.dart';
|
||||
import '../../support/fake_profile_gateway.dart';
|
||||
import '../../support/pump_app.dart';
|
||||
import '../../support/test_dependencies.dart';
|
||||
|
||||
|
|
@ -27,7 +22,7 @@ void main() {
|
|||
/// through [profiles].
|
||||
Future<void> showProfile(
|
||||
WidgetTester tester,
|
||||
FakeProfileGateway profiles, {
|
||||
FakePublicProfileGateway profiles, {
|
||||
FakeFilePicker? files,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(1000, 1800);
|
||||
|
|
@ -69,7 +64,7 @@ void main() {
|
|||
testWidgets('a person with an identity writes first, then chooses a '
|
||||
'handle in a dialog saying whether it is free; that makes the profile '
|
||||
'with what was written', (tester) async {
|
||||
final profiles = FakeProfileGateway(taken: {'Tizian'});
|
||||
final profiles = FakePublicProfileGateway(taken: {'Tizian'});
|
||||
await showProfile(tester, profiles);
|
||||
|
||||
expect(find.text('Public profile'), findsOneWidget);
|
||||
|
|
@ -107,7 +102,7 @@ void main() {
|
|||
|
||||
testWidgets('the dialog says when the instance answers no more about '
|
||||
'handles this hour, and nothing can be chosen', (tester) async {
|
||||
final profiles = FakeProfileGateway()..checksSpent = true;
|
||||
final profiles = FakePublicProfileGateway()..checksSpent = true;
|
||||
await showProfile(tester, profiles);
|
||||
|
||||
await tester.tap(find.text('Choose a handle'));
|
||||
|
|
@ -130,7 +125,7 @@ void main() {
|
|||
'only what changed, without losing what is being written', (
|
||||
tester,
|
||||
) async {
|
||||
final profiles = FakeProfileGateway(
|
||||
final profiles = FakePublicProfileGateway(
|
||||
profile: const PublicProfile(
|
||||
handle: 'raisondetredev',
|
||||
address: 'raisondetredev@halkyon.eu',
|
||||
|
|
@ -169,7 +164,7 @@ void main() {
|
|||
|
||||
testWidgets('the handle changes through the dialog, which says one is '
|
||||
'yours', (tester) async {
|
||||
final profiles = FakeProfileGateway(
|
||||
final profiles = FakePublicProfileGateway(
|
||||
profile: const PublicProfile(
|
||||
handle: 'raisondetredev',
|
||||
address: 'raisondetredev@halkyon.eu',
|
||||
|
|
@ -195,7 +190,7 @@ void main() {
|
|||
'profile stays', (tester) async {
|
||||
await showProfile(
|
||||
tester,
|
||||
FakeProfileGateway(
|
||||
FakePublicProfileGateway(
|
||||
profile: const PublicProfile(
|
||||
handle: 'raisondetredev',
|
||||
address: 'raisondetredev@halkyon.eu',
|
||||
|
|
@ -217,7 +212,7 @@ void main() {
|
|||
|
||||
testWidgets('removing a profile asks first, then makes it private: the '
|
||||
'handle stays, what was filled in goes (ADR 0020, D27)', (tester) async {
|
||||
final profiles = FakeProfileGateway(
|
||||
final profiles = FakePublicProfileGateway(
|
||||
profile: const PublicProfile(
|
||||
handle: 'raisondetredev',
|
||||
address: 'raisondetredev@halkyon.eu',
|
||||
|
|
@ -257,7 +252,7 @@ void main() {
|
|||
'something is filled in', (tester) async {
|
||||
await showProfile(
|
||||
tester,
|
||||
FakeProfileGateway(
|
||||
FakePublicProfileGateway(
|
||||
profile: const PublicProfile(
|
||||
handle: 'raisondetredev',
|
||||
address: 'raisondetredev@halkyon.eu',
|
||||
|
|
@ -280,7 +275,7 @@ void main() {
|
|||
|
||||
testWidgets('a saved profile takes a picture as its avatar, and gives it '
|
||||
'up', (tester) async {
|
||||
final profiles = FakeProfileGateway(
|
||||
final profiles = FakePublicProfileGateway(
|
||||
profile: const PublicProfile(
|
||||
handle: 'raisondetredev',
|
||||
address: 'raisondetredev@halkyon.eu',
|
||||
|
|
@ -305,7 +300,7 @@ void main() {
|
|||
testWidgets('a profile not yet saved has no picture to choose', (
|
||||
tester,
|
||||
) async {
|
||||
await showProfile(tester, FakeProfileGateway());
|
||||
await showProfile(tester, FakePublicProfileGateway());
|
||||
|
||||
expect(find.text('Choose your handle to add a picture.'), findsOneWidget);
|
||||
expect(find.text('Choose picture'), findsNothing);
|
||||
|
|
@ -314,7 +309,7 @@ void main() {
|
|||
testWidgets('without the instance, it says so and tries again', (
|
||||
tester,
|
||||
) async {
|
||||
final profiles = FakeProfileGateway()..fail = Exception('offline');
|
||||
final profiles = FakePublicProfileGateway()..fail = Exception('offline');
|
||||
await showProfile(tester, profiles);
|
||||
|
||||
expect(
|
||||
|
|
@ -336,7 +331,7 @@ void main() {
|
|||
address: 'raisondetredev@halkyon.eu',
|
||||
),
|
||||
);
|
||||
final bloc = PublicProfileBloc(ProfileRepository(gateway))
|
||||
final bloc = PublicProfileBloc(PublicProfileRepository(gateway))
|
||||
..add(const PublicProfileEventStarted());
|
||||
addTearDown(bloc.close);
|
||||
await bloc.stream.firstWhere((state) => state is PublicProfileStateReady);
|
||||
|
|
@ -371,8 +366,8 @@ void main() {
|
|||
test(
|
||||
'the repository leaves blank links out and trims what it saves',
|
||||
() async {
|
||||
final profiles = FakeProfileGateway();
|
||||
await ProfileRepository(profiles).save(
|
||||
final profiles = FakePublicProfileGateway();
|
||||
await PublicProfileRepository(profiles).save(
|
||||
handle: ' tizian ',
|
||||
displayName: ' Tizian ',
|
||||
bio: '',
|
||||
|
|
@ -410,7 +405,10 @@ void main() {
|
|||
null,
|
||||
),
|
||||
);
|
||||
await showProfile(tester, FakeProfileGateway(profile: withLinks([])));
|
||||
await showProfile(
|
||||
tester,
|
||||
FakePublicProfileGateway(profile: withLinks([])),
|
||||
);
|
||||
|
||||
expect(
|
||||
find.text('Your profile page: halkyon.eu/@raisondetredev'),
|
||||
|
|
@ -425,7 +423,7 @@ void main() {
|
|||
|
||||
testWidgets('a link saved is checked by itself, and gets a checkmark once '
|
||||
'its page links back, without a message', (tester) async {
|
||||
final profiles = FakeProfileGateway(profile: withLinks([]))
|
||||
final profiles = FakePublicProfileGateway(profile: withLinks([]))
|
||||
..linkingBack.add('https://halkyon.app');
|
||||
await showProfile(tester, profiles);
|
||||
|
||||
|
|
@ -446,7 +444,7 @@ void main() {
|
|||
testWidgets('Check links checks again, and says how many link back', (
|
||||
tester,
|
||||
) async {
|
||||
final profiles = FakeProfileGateway(
|
||||
final profiles = FakePublicProfileGateway(
|
||||
profile: withLinks(['https://halkyon.app', 'https://example.org']),
|
||||
)..linkingBack.add('https://example.org');
|
||||
await showProfile(tester, profiles);
|
||||
|
|
@ -463,7 +461,7 @@ void main() {
|
|||
});
|
||||
|
||||
testWidgets('checking too often says so', (tester) async {
|
||||
final profiles = FakeProfileGateway(
|
||||
final profiles = FakePublicProfileGateway(
|
||||
profile: withLinks(['https://halkyon.app']),
|
||||
)..refuseLinkChecks = true;
|
||||
await showProfile(tester, profiles);
|
||||
|
|
@ -480,12 +478,12 @@ void main() {
|
|||
test('a check that ends after a save keeps what was saved, and adds the '
|
||||
"check's answer to it", () async {
|
||||
final profiles =
|
||||
FakeProfileGateway(
|
||||
FakePublicProfileGateway(
|
||||
profile: withLinks(['https://a.example']),
|
||||
)
|
||||
..linkingBack.add('https://a.example')
|
||||
..checkWaits = Completer();
|
||||
final bloc = PublicProfileBloc(ProfileRepository(profiles))
|
||||
final bloc = PublicProfileBloc(PublicProfileRepository(profiles))
|
||||
..add(const PublicProfileEventStarted());
|
||||
addTearDown(bloc.close);
|
||||
await expectLater(
|
||||
|
|
@ -540,7 +538,7 @@ void main() {
|
|||
}
|
||||
|
||||
/// Saves only once [release] lets each through.
|
||||
class _HeldProfileGateway({super.profile}) extends FakeProfileGateway {
|
||||
class _HeldProfileGateway({super.profile}) extends FakePublicProfileGateway {
|
||||
final _held = <Completer<void>>[];
|
||||
|
||||
/// Lets the save waiting longest through.
|
||||
|
|
|
|||
Loading…
Reference in a new issue