c24e7f40b4
Add font… picks one or more files, checks them with a bounded sfnt reader (name table family, OS/2 weight), registers them with FontLoader before storing, and chooses the new family. Added fonts list below the bundled ones with Rename and Remove; removing the chosen one falls back to System default. Bytes live in the app support directory natively and in IndexedDB on the web (localStorage is too small); a shared_preferences index names them. Limits: 10 MB per file, 40 MB total. The capture kit gains a files= step.
63 lines
2.1 KiB
Dart
63 lines
2.1 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 reads as no choice', () async {
|
|
expect(await const SharedPreferencesAppFontStore().load(), isNull);
|
|
});
|
|
|
|
test(
|
|
'a choice round-trips under its stable id, on the device only',
|
|
() async {
|
|
const store = SharedPreferencesAppFontStore();
|
|
expect(await store.save(AppFont.ibmPlexSans.id), isTrue);
|
|
final preferences = await SharedPreferences.getInstance();
|
|
expect(preferences.getKeys(), <String>{appFontKey});
|
|
expect(preferences.getString(appFontKey), 'ibm-plex-sans');
|
|
expect(await store.load(), AppFont.ibmPlexSans.id);
|
|
|
|
expect(await store.save(AppFont.system.id), isTrue);
|
|
expect(await store.load(), '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'),
|
|
);
|
|
}
|
|
});
|
|
}
|