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
3 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,156 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
import 'package:halkyon_ui/halkyon_ui.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/pump_app.dart';
|
||||
import '../../../support/test_dependencies.dart';
|
||||
|
||||
void main() {
|
||||
late FakeAuthGateway auth;
|
||||
late MemorySignInAddresses addresses;
|
||||
|
||||
setUp(() {
|
||||
auth = FakeAuthGateway();
|
||||
addresses = MemorySignInAddresses();
|
||||
});
|
||||
|
||||
Future<void> openProfile(WidgetTester tester) async {
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(authGateway: auth, signInAddresses: addresses),
|
||||
);
|
||||
await openTab(tester, 'Profile');
|
||||
}
|
||||
|
||||
/// The sheet's text field.
|
||||
final inSheet = find.descendant(
|
||||
of: find.byType(SheetScaffold),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
|
||||
/// Types [address] and sends a code to it, then types [code].
|
||||
Future<void> signInWith(
|
||||
WidgetTester tester,
|
||||
String address, {
|
||||
String code = 'CODE-1',
|
||||
}) async {
|
||||
await tester.enterText(inSheet, address);
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Send code'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text("We mailed a code to $address. It's valid for 15 minutes."),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.enterText(inSheet, code);
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('an anonymous person continues with email: the address, then '
|
||||
'the code mailed to it, and their progress is kept with their account, '
|
||||
'which shows the address', (tester) async {
|
||||
await openProfile(tester);
|
||||
|
||||
await tester.tap(find.text('Continue with email'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.textContaining('keeps only a fingerprint of your address'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await signInWith(tester, 'anna@example.org');
|
||||
|
||||
expect(find.text('Signed in with anna@example.org.'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Your progress is kept with your account.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Ways to sign in'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(ListTile, 'anna@example.org'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Add GitHub'), findsOneWidget);
|
||||
expect(addresses.addresses, {'anonymous-1': 'anna@example.org'});
|
||||
});
|
||||
|
||||
testWidgets('a wrong code says so, and a new one can be asked for', (
|
||||
tester,
|
||||
) async {
|
||||
await openProfile(tester);
|
||||
await tester.tap(find.text('Continue with email'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await signInWith(tester, 'anna@example.org', code: 'CODE-9');
|
||||
|
||||
expect(find.text("That code isn't right."), findsOneWidget);
|
||||
await tester.tap(find.text('Send a new code'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('A new code is on its way.'), findsOneWidget);
|
||||
expect(auth.mailed, hasLength(2));
|
||||
});
|
||||
|
||||
testWidgets('no email sign-in where the instance offers none', (
|
||||
tester,
|
||||
) async {
|
||||
auth.offersEmail = false;
|
||||
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.text('Continue with email'), findsNothing);
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('someone who signs in with GitHub adds an email address', (
|
||||
tester,
|
||||
) async {
|
||||
auth = FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
)..gitHubPeople.add('github-person');
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.text('Ways to sign in'), findsOneWidget);
|
||||
expect(find.text('Add GitHub'), findsNothing);
|
||||
await tester.tap(find.text('Add an email address'));
|
||||
await tester.pumpAndSettle();
|
||||
await signInWith(tester, 'carla@example.org');
|
||||
|
||||
expect(
|
||||
find.widgetWithText(ListTile, 'carla@example.org'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Add an email address'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("someone identified whose address is another account's is "
|
||||
'told so, and stays who they are', (tester) async {
|
||||
auth =
|
||||
FakeAuthGateway(
|
||||
status: const SignedIn(
|
||||
authUserId: 'github-person',
|
||||
isIdentified: true,
|
||||
),
|
||||
)
|
||||
..gitHubPeople.add('github-person')
|
||||
..addressOwners['ben@example.org'] = 'ben';
|
||||
await openProfile(tester);
|
||||
|
||||
await tester.tap(find.text('Add an email address'));
|
||||
await tester.pumpAndSettle();
|
||||
await signInWith(tester, 'ben@example.org');
|
||||
|
||||
expect(
|
||||
find.text(
|
||||
'ben@example.org already signs in to another account. To switch to '
|
||||
'it, sign out first.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(auth.emailSwitches, 0);
|
||||
expect(
|
||||
auth.status,
|
||||
const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
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/feature/home/widget/home_screen.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:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/fake_studyset_gateway.dart';
|
||||
import '../../../support/pump_app.dart';
|
||||
import '../../../support/test_dependencies.dart';
|
||||
|
||||
void main() {
|
||||
late FakeAuthGateway auth;
|
||||
|
||||
setUp(() => auth = FakeAuthGateway());
|
||||
|
||||
/// Signs in anonymously and opens the profile tab; this device holds
|
||||
/// [studysets] studysets.
|
||||
Future<void> openProfile(WidgetTester tester, {int studysets = 0}) async {
|
||||
final gateway = FakeStudysetGateway();
|
||||
for (var i = 1; i <= studysets; i++) {
|
||||
gateway.receiveRemoteChange(
|
||||
'studyset-$i',
|
||||
encodeStudysetPayload(
|
||||
StudysetContent(
|
||||
title: 'Studyset $i',
|
||||
description: RichContent.empty(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(authGateway: auth, studysetGateway: gateway),
|
||||
);
|
||||
await openTab(tester, 'Profile');
|
||||
}
|
||||
|
||||
testWidgets('offers GitHub sign-in to anonymous people', (tester) async {
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('offers none where the instance has no GitHub sign-in', (
|
||||
tester,
|
||||
) async {
|
||||
auth.offersGitHub = false;
|
||||
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.text('Sign in with GitHub'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('signing in with GitHub keeps the progress with the account', (
|
||||
tester,
|
||||
) async {
|
||||
await openProfile(tester);
|
||||
|
||||
await tester.tap(find.text('Sign in with GitHub'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text('Your progress is kept with your account.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Sign in with GitHub'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the account keeps its width once signed in', (tester) async {
|
||||
await openProfile(tester);
|
||||
Finder account() => find.ancestor(
|
||||
of: find.text('Sign in with GitHub'),
|
||||
matching: find.byType(ListView),
|
||||
);
|
||||
final anonymous = tester.getSize(account()).width;
|
||||
|
||||
await tester.tap(find.text('Sign in with GitHub'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
tester.getSize(find.byType(ListView).first).width,
|
||||
anonymous,
|
||||
);
|
||||
});
|
||||
|
||||
group("while GitHub's page is open in the browser", () {
|
||||
setUp(() => auth.gitHubPageOpens = true);
|
||||
|
||||
/// Opens the profile and starts signing in with GitHub.
|
||||
Future<void> startSignIn(WidgetTester tester) async {
|
||||
await openProfile(tester);
|
||||
await tester.tap(find.text('Sign in with GitHub'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('offers to cancel; cancelling changes nothing', (tester) async {
|
||||
auth.canCancelGitHub = true;
|
||||
await startSignIn(tester);
|
||||
expect(find.text('Continue in your browser.'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(auth.gitHubCancels, 1);
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
expect(find.text("Couldn't sign in with GitHub."), findsNothing);
|
||||
expect(
|
||||
find.text('Progress is saved on this device. Sign in to keep it.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets("offers no cancel where the system's sign-in screen has its "
|
||||
'own', (tester) async {
|
||||
await startSignIn(tester);
|
||||
|
||||
expect(find.text('Continue in your browser.'), findsNothing);
|
||||
expect(find.text('Cancel'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('signs in once GitHub answers', (tester) async {
|
||||
auth.canCancelGitHub = true;
|
||||
await startSignIn(tester);
|
||||
|
||||
auth.answerGitHub();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text('Your progress is kept with your account.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Continue in your browser.'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('choosing another tab cancels it', (tester) async {
|
||||
auth.canCancelGitHub = true;
|
||||
await startSignIn(tester);
|
||||
|
||||
await openTab(tester, 'Home');
|
||||
expect(auth.gitHubCancels, 1);
|
||||
await openTab(tester, 'Profile');
|
||||
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
expect(find.text("Couldn't sign in with GitHub."), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('settings, opened over the profile, keep it waiting', (
|
||||
tester,
|
||||
) async {
|
||||
auth.canCancelGitHub = true;
|
||||
await startSignIn(tester);
|
||||
|
||||
await tester.tap(find.byTooltip('Settings'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(auth.gitHubCancels, 0);
|
||||
expect(find.text('Continue in your browser.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a change of person cancels it', (tester) async {
|
||||
auth.canCancelGitHub = true;
|
||||
await startSignIn(tester);
|
||||
|
||||
auth.revokeSession();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(auth.gitHubCancels, 1);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets("asks before leaving this device's studysets behind; staying "
|
||||
'keeps them', (tester) async {
|
||||
auth.gitHubLinkOutcome = GitHubLinkOutcome.takenByAnotherPerson;
|
||||
await openProfile(tester, studysets: 1);
|
||||
|
||||
await tester.tap(find.text('Sign in with GitHub'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Switch to your GitHub account?'), findsOneWidget);
|
||||
await tester.tap(find.text('Stay anonymous'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(auth.gitHubSwitches, 0);
|
||||
expect(
|
||||
find.text('Progress is saved on this device. Sign in to keep it.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('switches once confirmed, and the app starts anew at home', (
|
||||
tester,
|
||||
) async {
|
||||
auth.gitHubLinkOutcome = GitHubLinkOutcome.takenByAnotherPerson;
|
||||
await openProfile(tester, studysets: 1);
|
||||
|
||||
await tester.tap(find.text('Sign in with GitHub'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Switch'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(auth.gitHubSwitches, 1);
|
||||
expect(find.text('Switch to your GitHub account?'), findsNothing);
|
||||
expect(find.byType(HomeScreen), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
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/feature/home/widget/home_screen.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/pump_app.dart';
|
||||
import '../../../support/test_dependencies.dart';
|
||||
|
||||
void main() {
|
||||
late FakeAuthGateway gateway;
|
||||
|
||||
setUp(() => gateway = FakeAuthGateway());
|
||||
|
||||
/// The home tab.
|
||||
final home = find.byType(HomeScreen);
|
||||
|
||||
Future<void> showApp(WidgetTester tester) =>
|
||||
pumpApp(tester, testDependencies(authGateway: gateway));
|
||||
|
||||
/// Shows the app and opens settings, from the profile tab, down to the
|
||||
/// account.
|
||||
Future<void> openSettings(WidgetTester tester) async {
|
||||
await showApp(tester);
|
||||
await openTab(tester, 'Profile');
|
||||
await tester.tap(find.byTooltip('Settings'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Delete account'),
|
||||
200,
|
||||
// The citation preview is selectable, a scroll view of its own.
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('shows the app once signed in anonymously', (tester) async {
|
||||
await showApp(tester);
|
||||
|
||||
expect(home, findsOneWidget);
|
||||
expect(gateway.signIns, 1);
|
||||
});
|
||||
|
||||
testWidgets('offers to try again when signing in fails', (tester) async {
|
||||
gateway.signInError = Exception('No connection');
|
||||
await showApp(tester);
|
||||
expect(find.text("Couldn't reach the server."), findsOneWidget);
|
||||
|
||||
gateway.signInError = null;
|
||||
await tester.tap(find.text('Try again'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(home, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the profile explains that progress lives on this device', (
|
||||
tester,
|
||||
) async {
|
||||
await showApp(tester);
|
||||
|
||||
await openTab(tester, 'Profile');
|
||||
|
||||
expect(
|
||||
find.text('Progress is saved on this device. Sign in to keep it.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Settings says the account is anonymous, on which instance; '
|
||||
'one with GitHub, signed in', (tester) async {
|
||||
await openSettings(tester);
|
||||
expect(find.text('Anonymous on learn.example.org'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byTooltip('Back'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign in with GitHub'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Settings'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Delete account'),
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
expect(find.text('Signed in on learn.example.org'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'signing out of an anonymous account asks first; Cancel keeps it',
|
||||
(tester) async {
|
||||
await openSettings(tester);
|
||||
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Sign out?'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.signOuts, 0);
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'anonymous-1', isIdentified: false),
|
||||
);
|
||||
expect(find.text('Settings'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a confirmed sign-out asks how to start, making no account; '
|
||||
'starting without one starts anew at home', (tester) async {
|
||||
await openSettings(tester);
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Sign out').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Signing out of an anonymous account deletes it.
|
||||
expect(gateway.accountDeletions, 1);
|
||||
expect(gateway.status, const SignedOut());
|
||||
expect(find.text('Signed out'), findsOneWidget);
|
||||
expect(find.text('Start on learn.example.org:'), findsOneWidget);
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
expect(find.text('Continue with email'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Start without an account'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'anonymous-2', isIdentified: false),
|
||||
);
|
||||
expect(home, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('from there, GitHub signs in its person, making no account '
|
||||
'here', (tester) async {
|
||||
await openSettings(tester);
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign out').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Sign in with GitHub'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
);
|
||||
expect(home, findsOneWidget);
|
||||
expect(gateway.signIns, 1);
|
||||
});
|
||||
|
||||
testWidgets('from there, an email address starts without an account and '
|
||||
'asks for the address on Profile', (tester) async {
|
||||
await openSettings(tester);
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign out').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Continue with email'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'anonymous-2', isIdentified: false),
|
||||
);
|
||||
// The email sign-in, over the Profile tab.
|
||||
expect(find.text('Continue with email'), findsWidgets);
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('deleting the account asks first; Cancel keeps it', (
|
||||
tester,
|
||||
) async {
|
||||
await openSettings(tester);
|
||||
|
||||
await tester.tap(find.text('Delete account'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Delete your account?'), findsOneWidget);
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.accountDeletions, 0);
|
||||
expect(find.text('Settings'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a confirmed deletion asks how to start; starting without an '
|
||||
'account starts anew at home', (tester) async {
|
||||
await openSettings(tester);
|
||||
await tester.tap(find.text('Delete account'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Delete account').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.accountDeletions, 1);
|
||||
expect(find.text('Signed out'), findsOneWidget);
|
||||
await tester.tap(find.text('Start without an account'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'anonymous-2', isIdentified: false),
|
||||
);
|
||||
expect(home, findsOneWidget);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue