a7c41063fa
Keep the Material-only settings implementation and its focused tests while preserving public cupertino parameters for later cleanup. This removes unreachable platform-specific widgets and test variants without changing the Material path.
106 lines
3.2 KiB
Dart
106 lines
3.2 KiB
Dart
import 'dart:async';
|
|
|
|
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';
|
|
import 'package:pipelines_app/ui/theme/font_choice.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) async {
|
|
final section = SingleChildScrollView(
|
|
child: SettingsFontSection(controller: harness.fonts),
|
|
);
|
|
await tester.pumpWidget(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<FontChoice>>(
|
|
find.byType(RadioGroup<FontChoice>),
|
|
);
|
|
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.id, AppFont.sourceSans3.id);
|
|
expect(
|
|
tester
|
|
.widget<RadioGroup<FontChoice>>(find.byType(RadioGroup<FontChoice>))
|
|
.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('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);
|
|
});
|
|
}
|