Files
pipelines/app/test/ui/theme/app_font_store_test.dart
T
alan 2853b18b9e Settings: per-device interface font choice
System default plus Inter, IBM Plex Sans, Source Sans 3 and Atkinson
Hyperlegible Next (OFL 1.1, bundled as on-demand assets and loaded with
FontLoader, so the web fetches only the previewed/chosen files). Stored in
shared_preferences, applied live to Material and Cupertino text themes;
RobotoMono styles unchanged. Licences registered with LicenseRegistry.
2026-11-04 02:01:49 +00:00

70 lines
2.4 KiB
Dart

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/theme/app_font.dart';
import 'package:pipelines_app/ui/theme/app_font_store.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() => SharedPreferences.setMockInitialValues(<String, Object>{}));
test('nothing stored is the system default', () async {
expect(await const SharedPreferencesAppFontStore().load(), AppFont.system);
});
test(
'a choice round-trips under its stable id, on the device only',
() async {
const store = SharedPreferencesAppFontStore();
expect(await store.save(AppFont.ibmPlexSans), isTrue);
final preferences = await SharedPreferences.getInstance();
expect(preferences.getKeys(), <String>{appFontKey});
expect(preferences.getString(appFontKey), 'ibm-plex-sans');
expect(await store.load(), AppFont.ibmPlexSans);
expect(await store.save(AppFont.system), isTrue);
expect(await store.load(), AppFont.system);
},
);
test('an unknown stored id falls back to the system default', () async {
SharedPreferences.setMockInitialValues(<String, Object>{
appFontKey: 'comic-sans',
});
expect(await const SharedPreferencesAppFontStore().load(), AppFont.system);
});
test('every bundled option has its four weights and its licence', () {
for (final font in AppFont.values) {
if (font == AppFont.system) {
expect(font.family, isNull);
expect(font.assets, isEmpty);
continue;
}
expect(font.assets, hasLength(4));
expect(font.previewAsset, font.assets.first);
for (final asset in <String>[...font.assets, font.licenseAsset!]) {
expect(File(asset).existsSync(), isTrue, reason: asset);
}
expect(
File(font.licenseAsset!).readAsStringSync(),
contains('SIL OPEN FONT LICENSE Version 1.1'),
);
}
});
test('the optional fonts are assets, not startup fonts', () {
final pubspec = File('pubspec.yaml').readAsStringSync();
final fonts = pubspec.substring(pubspec.indexOf('\n fonts:'));
for (final font in AppFont.values.where((f) => f.family != null)) {
expect(fonts, isNot(contains('family: ${font.family}')));
expect(
pubspec,
contains(' - ${font.licenseAsset!.replaceAll('OFL.txt', '')}\n'),
);
}
});
}