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({})); 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(), {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 [...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'), ); } }); }