chore: Halkyon Learn moves into apps/learn
Its server, client, app and curator, and the tools that write its assets (maps, Anki fixtures, icons), as they are; paths are fixed in the commits that follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
11abd9afce
commit
649499be23
2 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,197 @@
|
|||
import 'package:flag/flag.dart';
|
||||
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/app/learn_frame.dart';
|
||||
import 'package:halkyon_learn_flutter/src/app/learn_sessions.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/device_settings/widget/device_settings_scope.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/settings/widget/settings_screen.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../support/memory_device_settings_store.dart';
|
||||
import '../support/pump_app.dart';
|
||||
import '../support/test_dependencies.dart';
|
||||
|
||||
void main() {
|
||||
final builtIn = Instance.parse('learn.halkyon.eu')!;
|
||||
final other = Instance.parse('learn.example.org')!;
|
||||
late MemoryInstanceStore store;
|
||||
late List<Instance> opened;
|
||||
late List<Instance> forgotten;
|
||||
|
||||
setUp(() {
|
||||
store = MemoryInstanceStore();
|
||||
opened = [];
|
||||
forgotten = [];
|
||||
});
|
||||
|
||||
/// Starts the app on a device that [usedBefore] the choice existed, with
|
||||
/// [answering] instances answering a check, saying where they keep data
|
||||
/// as [locations] has it.
|
||||
Future<InstanceChoice> start(
|
||||
WidgetTester tester, {
|
||||
bool usedBefore = false,
|
||||
Set<Instance> answering = const {},
|
||||
Map<Instance, InstanceLocations> locations = const {},
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(412, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final choice = InstanceChoice(
|
||||
store,
|
||||
builtIn: builtIn,
|
||||
forget: (instance) async => forgotten.add(instance),
|
||||
);
|
||||
await choice.load(usedBefore: usedBefore);
|
||||
await tester.pumpWidget(
|
||||
InstanceGate(
|
||||
frame: learnFrame,
|
||||
choice: choice,
|
||||
checker: FakeInstanceChecker(answering, locations),
|
||||
countryNames: MemoryCountryNames(const {
|
||||
'CH': {'en': 'Switzerland'},
|
||||
}),
|
||||
readLook: () async => (await MemoryDeviceSettingsStore().read()).look,
|
||||
open: (instance) async {
|
||||
opened.add(instance);
|
||||
return testDependencies();
|
||||
},
|
||||
app: const LearnSessions(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return choice;
|
||||
}
|
||||
|
||||
/// Opens Settings › Switch account, further down Settings.
|
||||
Future<void> openSwitcher(WidgetTester tester) async {
|
||||
await openTab(tester, 'Profile');
|
||||
await tester.tap(find.byTooltip('Settings'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Switch account'),
|
||||
200,
|
||||
// Settings' list; its citation preview is a scroll view of its own.
|
||||
scrollable: find
|
||||
.descendant(
|
||||
of: find.byType(SettingsScreen),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
// Built, but perhaps still below the window's edge.
|
||||
await tester.ensureVisible(find.text('Switch account'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Switch account'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('a new install asks for the instance first, and opens the '
|
||||
"build's in one tap", (tester) async {
|
||||
await start(tester);
|
||||
|
||||
// The wordmark says it to screen readers.
|
||||
expect(find.bySemanticsLabel('Welcome to Halkyon Learn'), findsOneWidget);
|
||||
expect(opened, isEmpty, reason: 'nothing made anywhere yet');
|
||||
expect(find.byType(TextField), findsNothing, reason: 'no address asked');
|
||||
|
||||
await tester.tap(find.text('learn.halkyon.eu'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, [builtIn]);
|
||||
expect(tab('Home'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("the build's instance shows where it keeps people's data, "
|
||||
'once it says', (tester) async {
|
||||
await start(
|
||||
tester,
|
||||
answering: {builtIn},
|
||||
locations: {
|
||||
builtIn: const InstanceLocations(data: 'EU', backups: 'CH'),
|
||||
},
|
||||
);
|
||||
|
||||
expect(find.text('Data: European Union\nBackups: Switzerland'), findsOne);
|
||||
expect(find.byType(Flag), findsOne);
|
||||
});
|
||||
|
||||
testWidgets('an instance saying nothing, or not answering, comes with the '
|
||||
'app, without a flag', (tester) async {
|
||||
await start(tester);
|
||||
|
||||
expect(find.text('Comes with the app'), findsOne);
|
||||
expect(find.byType(Flag), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('another instance is checked before the app moves there', (
|
||||
tester,
|
||||
) async {
|
||||
await start(tester, answering: {other});
|
||||
|
||||
await tester.tap(find.text('Another instance'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
FocusManager.instance.primaryFocus?.context
|
||||
?.findAncestorWidgetOfExactType<TextField>(),
|
||||
isNotNull,
|
||||
reason: 'the address is typed at once',
|
||||
);
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'nowhere.example.org');
|
||||
await tester.tap(find.text('Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text(
|
||||
'No instance of Halkyon Learn answers at nowhere.example.org.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(opened, isEmpty);
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'learn.example.org');
|
||||
await tester.tap(find.text('Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, [other]);
|
||||
});
|
||||
|
||||
testWidgets('an install from before goes on without asking', (tester) async {
|
||||
await start(tester, usedBefore: true);
|
||||
|
||||
expect(opened, [builtIn]);
|
||||
expect(tab('Home'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Settings switches between the accounts on the device, and '
|
||||
'removes one not in use', (tester) async {
|
||||
store = MemoryInstanceStore((current: builtIn, known: [builtIn, other]));
|
||||
await start(
|
||||
tester,
|
||||
answering: {builtIn, other},
|
||||
locations: {
|
||||
other: const InstanceLocations(
|
||||
data: 'CH',
|
||||
backups: InstanceLocations.noBackups,
|
||||
),
|
||||
},
|
||||
);
|
||||
await openSwitcher(tester);
|
||||
expect(find.text('learn.halkyon.eu'), findsWidgets);
|
||||
// Each account with where its instance says it keeps people's data.
|
||||
expect(find.text('Data: Switzerland\nNo backups'), findsOne);
|
||||
expect(find.byType(Flag), findsOne);
|
||||
await tester.tap(find.text('learn.example.org'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, [builtIn, other]);
|
||||
expect(tab('Home'), findsOneWidget, reason: 'a new app, on Home');
|
||||
|
||||
await openSwitcher(tester);
|
||||
await tester.tap(find.byTooltip('Remove account'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Remove'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(forgotten, [builtIn]);
|
||||
expect(store.kept?.known, [other]);
|
||||
});
|
||||
}
|
||||
238
apps/learn/halkyon_learn_flutter/test/app/long_names_test.dart
Normal file
238
apps/learn/halkyon_learn_flutter/test/app/long_names_test.dart
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
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/content/rich_content.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/profile/public_person.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/router/route_paths.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/card/data/card_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/card/model/card_content.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/learning_path/data/learning_path_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/learning_path/model/learning_path.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/note/data/note_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/note/model/note_content.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/pomodoro/model/pomodoro_profile.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/settings/data/settings_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/studyset/data/studyset_payload.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/studyset/model/studyset_content.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/tag/data/tag_repository.dart';
|
||||
import 'package:halkyon_ui/halkyon_ui.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../support/fake_card_gateway.dart';
|
||||
import '../support/fake_discussion_gateway.dart';
|
||||
import '../support/fake_learning_path_gateway.dart';
|
||||
import '../support/fake_note_gateway.dart';
|
||||
import '../support/fake_settings_gateway.dart';
|
||||
import '../support/fake_studyset_gateway.dart';
|
||||
import '../support/fake_tag_gateway.dart';
|
||||
import '../support/pump_app.dart';
|
||||
import '../support/test_dependencies.dart';
|
||||
|
||||
/// Names longer than the fields allow ([TextLimits]), as an older app, an
|
||||
/// import or another person's release can bring them: every screen that
|
||||
/// shows them cuts them short rather than overflowing, which fails a test.
|
||||
void main() {
|
||||
/// [length] characters of a name made of words, as long names are.
|
||||
String long(String word, int length) =>
|
||||
List.filled(length, word).join(' ').substring(0, length);
|
||||
|
||||
final studysetTitle = long('Japanese', TextLimits.title * 2);
|
||||
final kicker = long('日本語', TextLimits.secondary * 2);
|
||||
final topicTitle = long('Grammar', TextLimits.title * 2);
|
||||
final tagName = long('Particles', TextLimits.name * 3);
|
||||
final profileName = long('Deep focus', TextLimits.name * 3);
|
||||
|
||||
late FakeStudysetGateway studysets;
|
||||
late FakeCardGateway cardGateway;
|
||||
late FakeNoteGateway noteGateway;
|
||||
late FakeLearningPathGateway pathGateway;
|
||||
late FakeTagGateway tagGateway;
|
||||
late FakeSettingsGateway settingsGateway;
|
||||
late FakeDiscussionGateway discussions;
|
||||
|
||||
setUp(() async {
|
||||
studysets = FakeStudysetGateway()
|
||||
..receiveRemoteChange(
|
||||
'japanese',
|
||||
encodeStudysetPayload(
|
||||
StudysetContent(
|
||||
title: studysetTitle,
|
||||
secondaryTitle: kicker,
|
||||
description: RichContent.plain(long('About', 400)),
|
||||
),
|
||||
),
|
||||
)
|
||||
..receiveRemoteChange(
|
||||
'grammar',
|
||||
encodeStudysetPayload(StudysetContent.titled(topicTitle)),
|
||||
parentId: 'japanese',
|
||||
)
|
||||
..receiveRemoteChange(
|
||||
'inner',
|
||||
encodeStudysetPayload(StudysetContent.titled(topicTitle)),
|
||||
parentId: 'grammar',
|
||||
);
|
||||
cardGateway = FakeCardGateway();
|
||||
noteGateway = FakeNoteGateway();
|
||||
pathGateway = FakeLearningPathGateway();
|
||||
tagGateway = FakeTagGateway();
|
||||
settingsGateway = FakeSettingsGateway();
|
||||
final someone = PublicPerson(
|
||||
handle: long('someone', 30).replaceAll(' ', '_'),
|
||||
displayName: long('Someone', TextLimits.name * 3),
|
||||
);
|
||||
discussions = FakeDiscussionGateway(studysetTitle: studysetTitle)
|
||||
..addQuestion(
|
||||
long('Meaning', TextLimits.title * 2),
|
||||
by: someone,
|
||||
answers: [
|
||||
FakeDiscussionGateway().answerBy(long('Answer', 300), by: someone),
|
||||
],
|
||||
);
|
||||
|
||||
final cards = CardRepository(cardGateway);
|
||||
final cardId = await cards.create(
|
||||
'japanese',
|
||||
CardContent(
|
||||
front: RichContent.plain(long('front', 300)),
|
||||
back: RichContent.plain(long('back', 300)),
|
||||
),
|
||||
);
|
||||
final tags = TagRepository(tagGateway, cardChanges: cards.changes);
|
||||
await tags.setTagsOf(cardId, {await tags.create(tagName)});
|
||||
await NoteRepository(noteGateway).create(
|
||||
'japanese',
|
||||
NoteContent(
|
||||
title: long('Note', TextLimits.title * 2),
|
||||
body: RichContent.empty(),
|
||||
),
|
||||
);
|
||||
await LearningPathRepository(pathGateway).createPath(
|
||||
'japanese',
|
||||
LearningPathContent.titled(
|
||||
long('Path', TextLimits.title * 2),
|
||||
).withSecondaryTitle(long('Book', TextLimits.secondary * 2)),
|
||||
);
|
||||
final profile = PomodoroProfile(id: 'long', name: profileName);
|
||||
await SettingsRepository(settingsGateway).update(
|
||||
(settings) => settings.withPomodoro(
|
||||
settings.pomodoro.withProfile(profile).withSelected(profile.id),
|
||||
),
|
||||
);
|
||||
await Future.wait([tags.dispose(), cards.dispose()]);
|
||||
});
|
||||
|
||||
for (final (window, width) in [('a phone', 360.0), ('a desktop', 1200.0)]) {
|
||||
Future<void> show(
|
||||
WidgetTester tester,
|
||||
String location, {
|
||||
AuthGateway? authGateway,
|
||||
SignInAddresses? signInAddresses,
|
||||
}) async {
|
||||
tester.view.physicalSize = Size(width, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(
|
||||
authGateway: authGateway,
|
||||
signInAddresses: signInAddresses,
|
||||
studysetGateway: studysets,
|
||||
cardGateway: cardGateway,
|
||||
noteGateway: noteGateway,
|
||||
pathGateway: pathGateway,
|
||||
tagGateway: tagGateway,
|
||||
settingsGateway: settingsGateway,
|
||||
discussionGateway: discussions,
|
||||
),
|
||||
location: location,
|
||||
);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
}
|
||||
|
||||
testWidgets('on $window, Home with a long Pomodoro profile', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester, RoutePaths.home);
|
||||
|
||||
expect(find.textContaining('Deep focus'), findsWidgets);
|
||||
await tester.tap(find.byTooltip(_profilesTooltip));
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('on $window, the library and a long studyset', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester, RoutePaths.library);
|
||||
|
||||
expect(find.textContaining('Japanese'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets("on $window, a long studyset's screen, its parts and topics", (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester, RoutePaths.studyset('grammar'));
|
||||
|
||||
for (final part in ['Study plan', 'Material']) {
|
||||
await openPart(tester, part);
|
||||
}
|
||||
if (width < 840) {
|
||||
await tester.tap(find.byTooltip('Show topics'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('on $window, the card browser with a long tag', (
|
||||
tester,
|
||||
) async {
|
||||
await show(tester, RoutePaths.cardBrowser('japanese'));
|
||||
|
||||
await tester.tap(find.byTooltip('Detail'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Select'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('More'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Manage tags'));
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets("on $window, a long studyset's discussions and a question", (
|
||||
tester,
|
||||
) async {
|
||||
await show(
|
||||
tester,
|
||||
RoutePaths.discussions('pub-1', title: topicTitle),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.textContaining('Meaning'));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('on $window, studying a long studyset', (tester) async {
|
||||
await show(tester, RoutePaths.study('japanese'));
|
||||
});
|
||||
|
||||
testWidgets('on $window, the profile of someone signing in with a long '
|
||||
'email address', (tester) async {
|
||||
final address =
|
||||
'${long('anna', TextLimits.emailAddress - 12)}@example.org';
|
||||
await show(
|
||||
tester,
|
||||
RoutePaths.profile,
|
||||
authGateway: FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'anna', isIdentified: true),
|
||||
)..addressOwners[address] = 'anna',
|
||||
signInAddresses: MemorySignInAddresses()..addresses['anna'] = address,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('anna anna'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// The tooltip of the Pomodoro card's profiles button.
|
||||
const _profilesTooltip = 'Pomodoro profiles';
|
||||
Loading…
Reference in a new issue