Files
pipelines/app/test/features/settings/settings_font_section_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

136 lines
4.1 KiB
Dart

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/settings_font_section.dart';
import 'package:pipelines_app/ui/theme/app_font.dart';
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
import 'package:pipelines_app/ui/theme/app_font_store.dart';
class _Harness {
_Harness({this.hold = false});
final bool hold;
final store = MemoryAppFontStore();
final loads = <String>[];
final held = <Completer<void>>[];
late final fonts = AppFontController(
store: store,
loader: (family, assets) {
loads.addAll(assets);
if (!hold || assets.length == 1) return Future<void>.value();
final done = Completer<void>();
held.add(done);
return done.future;
},
);
}
Future<void> _pump(
WidgetTester tester,
_Harness harness, {
bool cupertino = false,
}) async {
final section = SingleChildScrollView(
child: SettingsFontSection(controller: harness.fonts),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: section))
: MaterialApp(home: Scaffold(body: section)),
);
await tester.pumpAndSettle();
}
String? _familyOf(WidgetTester tester, AppFont font) => tester
.widget<Text>(
find.descendant(
of: find.byKey(settingsFontKey(font)),
matching: find.text(font.label),
),
)
.style
?.fontFamily;
void main() {
testWidgets('Material: every option is a radio named in its own face', (
tester,
) async {
final harness = _Harness();
await _pump(tester, harness);
expect(find.text(fontSectionTitle), findsOneWidget);
for (final font in AppFont.values) {
expect(find.byKey(settingsFontKey(font)), findsOneWidget);
expect(_familyOf(tester, font), font.family ?? 'Roboto');
}
// Showing the picker fetched one regular weight per option, no more.
expect(harness.loads, <String?>[
for (final font in AppFont.values)
if (font.previewAsset != null) font.previewAsset,
]);
final group = tester.widget<RadioGroup<AppFont>>(
find.byType(RadioGroup<AppFont>),
);
expect(group.groupValue, AppFont.system);
});
testWidgets('Material: choosing a font stores it and shows it loading', (
tester,
) async {
final harness = _Harness(hold: true);
await _pump(tester, harness);
await tester.tap(find.text('Source Sans 3'));
await tester.pump();
expect(harness.store.font, AppFont.sourceSans3);
expect(
tester
.widget<RadioGroup<AppFont>>(find.byType(RadioGroup<AppFont>))
.groupValue,
AppFont.sourceSans3,
);
expect(find.text(fontLoadingText), findsOneWidget);
expect(harness.fonts.family, isNull);
harness.held.single.complete();
await tester.pumpAndSettle();
expect(find.text(fontLoadingText), findsNothing);
expect(harness.fonts.family, 'Source Sans 3');
});
testWidgets('Cupertino: the chosen row carries the checkmark', (
tester,
) async {
final harness = _Harness();
await _pump(tester, harness, cupertino: true);
expect(find.byType(RadioListTile<AppFont>), findsNothing);
expect(_familyOf(tester, AppFont.system), 'CupertinoSystemText');
Finder check(AppFont font) => find.descendant(
of: find.byKey(settingsFontKey(font)),
matching: find.byIcon(CupertinoIcons.check_mark),
);
expect(check(AppFont.system), findsOneWidget);
await tester.tap(find.text('Inter'));
await tester.pumpAndSettle();
expect(check(AppFont.system), findsNothing);
expect(check(AppFont.inter), findsOneWidget);
expect(harness.store.font, AppFont.inter);
expect(harness.fonts.family, 'Inter');
});
testWidgets('a failed save is said under the group', (tester) async {
final harness = _Harness();
harness.store.failSaves = true;
await _pump(tester, harness);
await tester.tap(find.text('Inter'));
await tester.pumpAndSettle();
expect(find.text(fontSaveFailedText), findsOneWidget);
});
}