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
1 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,331 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/citation/model/citation.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/device_settings/model/device_settings.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/router/route_paths.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/version/app_version.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/dictionary/model/device_dictionary.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/settings/data/settings_repository.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/fake_device_dictionaries.dart';
|
||||
import '../../../support/fake_settings_gateway.dart';
|
||||
import '../../../support/memory_device_settings_store.dart';
|
||||
import '../../../support/pump_app.dart';
|
||||
import '../../../support/test_dependencies.dart';
|
||||
|
||||
void main() {
|
||||
/// How bright the app is where [finder] shows.
|
||||
Brightness brightnessAt(WidgetTester tester, Finder finder) =>
|
||||
Theme.of(tester.element(finder)).brightness;
|
||||
|
||||
Future<void> choose(WidgetTester tester, String from, String to) async {
|
||||
await tester.tap(find.text(from));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(to).last);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('Home opens the settings', (tester) async {
|
||||
await pumpApp(tester, testDependencies());
|
||||
|
||||
await tester.tap(find.byTooltip('Settings'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Appearance'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows the version and build at the bottom', (tester) async {
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(
|
||||
appVersion: const AppVersion(version: '1.2.3', build: '45'),
|
||||
),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Version 1.2.3 (build 45)'),
|
||||
200,
|
||||
// The preview's citation is selectable, a scroll view of its own.
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
expect(find.text('Version 1.2.3 (build 45)'), findsOneWidget);
|
||||
});
|
||||
|
||||
group('Japanese on this device', () {
|
||||
/// Opens Settings, tall enough to show every card at once.
|
||||
Future<void> openSettings(
|
||||
WidgetTester tester,
|
||||
FakeDeviceDictionaryGateway gateway, {
|
||||
DeviceDictionaryStatus initial = const DeviceDictionaryStatus(),
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(800, 5000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(
|
||||
deviceDictionaries: deviceDictionariesIn(gateway, initial: initial),
|
||||
),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('downloads the dictionaries the instance offers devices, and '
|
||||
'says when that failed', (tester) async {
|
||||
final gateway = FakeDeviceDictionaryGateway(offered: offeredJapanese());
|
||||
await openSettings(tester, gateway);
|
||||
|
||||
expect(find.text('Japanese on this device'), findsOneWidget);
|
||||
gateway.fail = const SocketException('offline');
|
||||
await tester.tap(find.text('Download (34.0 MB)'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.asked, 2);
|
||||
expect(find.text('The download failed.'), findsOneWidget);
|
||||
expect(find.text('Download (34.0 MB)'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('says how much room they take, and removes them', (
|
||||
tester,
|
||||
) async {
|
||||
await openSettings(
|
||||
tester,
|
||||
FakeDeviceDictionaryGateway(offered: offeredJapanese()),
|
||||
initial: DeviceDictionaryStatus(
|
||||
installed: installedJapanese(),
|
||||
asked: true,
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('On this device: 150.0 MB'), findsOneWidget);
|
||||
await tester.tap(find.text('Remove'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('On this device: 150.0 MB'), findsNothing);
|
||||
expect(find.text('Download (34.0 MB)'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows nothing of them where the instance offers none and '
|
||||
'the device holds none', (tester) async {
|
||||
await openSettings(tester, FakeDeviceDictionaryGateway());
|
||||
|
||||
expect(find.text('Japanese on this device'), findsNothing);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('a device that never chose follows its own theme', (
|
||||
tester,
|
||||
) async {
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
await pumpApp(tester, testDependencies(), location: RoutePaths.settings);
|
||||
|
||||
expect(find.text('Device theme'), findsOneWidget);
|
||||
expect(find.text('Device language'), findsOneWidget);
|
||||
expect(brightnessAt(tester, find.text('Appearance')), Brightness.dark);
|
||||
});
|
||||
|
||||
testWidgets('a forced appearance applies at once and is kept', (
|
||||
tester,
|
||||
) async {
|
||||
final store = MemoryDeviceSettingsStore();
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(deviceSettingsStore: store),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
|
||||
await choose(tester, 'Device theme', 'Dark');
|
||||
|
||||
expect(brightnessAt(tester, find.text('Appearance')), Brightness.dark);
|
||||
expect(
|
||||
store.writes.last,
|
||||
const DeviceSettings(appearance: Appearance.dark),
|
||||
);
|
||||
|
||||
await choose(tester, 'Dark', 'Light');
|
||||
|
||||
expect(brightnessAt(tester, find.text('Appearance')), Brightness.light);
|
||||
});
|
||||
|
||||
testWidgets('the citation style chosen shows on a sample at once and is '
|
||||
'kept', (tester) async {
|
||||
final store = MemoryDeviceSettingsStore();
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(deviceSettingsStore: store),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Official guide'),
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
|
||||
expect(find.textContaining('Brown, P. C., Roediger'), findsOneWidget);
|
||||
|
||||
await choose(tester, 'APA (7th edition)', 'MLA (9th edition)');
|
||||
|
||||
expect(find.textContaining('Brown, Peter C., et al.'), findsOneWidget);
|
||||
expect(
|
||||
store.writes.last,
|
||||
const DeviceSettings(citationStyle: CitationStyle.mla),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the Study card hides the Pomodoro timer while studying, and '
|
||||
'opens the Pomodoro profiles', (tester) async {
|
||||
final store = MemoryDeviceSettingsStore();
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(deviceSettingsStore: store),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
final timer = find.text('Show the Pomodoro timer while studying');
|
||||
await tester.scrollUntilVisible(
|
||||
timer,
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
expect(find.text('Pomodoro profiles'), findsOneWidget);
|
||||
|
||||
final toggle = find.widgetWithText(
|
||||
SwitchListTile,
|
||||
'Show the Pomodoro timer while studying',
|
||||
);
|
||||
await tester.ensureVisible(toggle);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.descendant(of: toggle, matching: find.byType(Switch)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(store.writes.last.pomodoroWhileStudying, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('starts with the appearance the device kept', (tester) async {
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(
|
||||
deviceSettings: const DeviceSettings(appearance: Appearance.light),
|
||||
),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
|
||||
expect(find.text('Light'), findsOneWidget);
|
||||
expect(brightnessAt(tester, find.text('Appearance')), Brightness.light);
|
||||
});
|
||||
|
||||
testWidgets('the device language comes first, then each language in its '
|
||||
'own name', (tester) async {
|
||||
await pumpApp(tester, testDependencies(), location: RoutePaths.settings);
|
||||
|
||||
await tester.tap(find.text('Device language'));
|
||||
await tester.pumpAndSettle();
|
||||
final menu = find.byWidgetPredicate(
|
||||
(widget) => widget is DropdownMenuItem<String?>,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widgetList<DropdownMenuItem<String?>>(menu)
|
||||
.map((item) => item.value)
|
||||
.toSet()
|
||||
.toList(),
|
||||
[null, 'en-GB', 'en-US', 'de'],
|
||||
);
|
||||
for (final name in ['English (UK)', 'English (US)', 'Deutsch']) {
|
||||
expect(find.text(name), findsWidgets);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('a language chosen applies at once and is kept, until the '
|
||||
'device language is chosen again', (tester) async {
|
||||
final store = MemoryDeviceSettingsStore();
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(deviceSettingsStore: store),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
|
||||
await choose(tester, 'Device language', 'Deutsch');
|
||||
|
||||
expect(find.text('Einstellungen'), findsOneWidget);
|
||||
expect(find.text('Darstellung'), findsOneWidget);
|
||||
expect(store.writes.last, const DeviceSettings(language: 'de'));
|
||||
|
||||
await choose(tester, 'Deutsch', 'Gerätesprache');
|
||||
|
||||
expect(find.text('Settings'), findsOneWidget);
|
||||
expect(store.writes.last, const DeviceSettings());
|
||||
});
|
||||
|
||||
testWidgets('starts in the language the device kept', (tester) async {
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(deviceSettings: const DeviceSettings(language: 'de')),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
|
||||
expect(find.text('Einstellungen'), findsOneWidget);
|
||||
});
|
||||
|
||||
group('appearance and language', () {
|
||||
Future<void> pumpAt(WidgetTester tester, double width) async {
|
||||
tester.view.physicalSize = Size(width, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await pumpApp(tester, testDependencies(), location: RoutePaths.settings);
|
||||
}
|
||||
|
||||
testWidgets('sit side by side where there is room', (tester) async {
|
||||
await pumpAt(tester, 1000);
|
||||
|
||||
expect(
|
||||
tester.getTopLeft(find.text('Language')).dy,
|
||||
tester.getTopLeft(find.text('Appearance')).dy,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('sit one below the other on a phone', (tester) async {
|
||||
await pumpAt(tester, 400);
|
||||
|
||||
expect(
|
||||
tester.getTopLeft(find.text('Language')).dy,
|
||||
greaterThan(tester.getBottomLeft(find.text('Device theme')).dy),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets("a person's learning counts in Explore only once they choose "
|
||||
'so, on every device of theirs', (tester) async {
|
||||
final settings = FakeSettingsGateway();
|
||||
tester.view.physicalSize = const Size(900, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(settingsGateway: settings),
|
||||
location: RoutePaths.settings,
|
||||
);
|
||||
final counting = find.widgetWithText(
|
||||
SwitchListTile,
|
||||
'Count my learning in Explore',
|
||||
);
|
||||
expect(tester.widget<SwitchListTile>(counting).value, isFalse);
|
||||
|
||||
await tester.tap(counting);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.widget<SwitchListTile>(counting).value, isTrue);
|
||||
expect(
|
||||
(await SettingsRepository(settings).read()).countLearning,
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue