import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/application/app.dart'; import 'package:pipelines_app/shell/destination.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/app_theme.dart'; void main() { test('Material themes take the family and keep sizes and weights', () { for (final build in [ appLightTheme, appDarkTheme, ]) { final system = build().textTheme; final inter = build(fontFamily: 'Inter').textTheme; expect(build().textTheme.bodyMedium?.fontFamily, isNot('Inter')); for (final (a, b) in <(TextStyle?, TextStyle?)>[ (system.bodyMedium, inter.bodyMedium), (system.titleMedium, inter.titleMedium), (system.labelLarge, inter.labelLarge), (system.headlineSmall, inter.headlineSmall), ]) { expect(b?.fontFamily, 'Inter'); expect(b?.fontSize, a?.fontSize); expect(b?.fontWeight, a?.fontWeight); } } }); testWidgets('the Material host switches font live, without a restart', ( tester, ) async { final fonts = AppFontController( store: MemoryAppFontStore(), loader: (family, assets) async {}, ); String? family; await tester.pumpWidget( MyApp( fonts: fonts, destination: AppDestination.settings, destinationBodies: { AppDestination.settings: (context) => Builder( builder: (context) { family = DefaultTextStyle.of(context).style.fontFamily; return const Text('body'); }, ), }, ), ); final before = family; expect(before, isNot('IBM Plex Sans')); await fonts.select(AppFont.ibmPlexSans); await tester.pumpAndSettle(); expect(family, 'IBM Plex Sans'); await fonts.select(AppFont.system); await tester.pumpAndSettle(); expect(family, before); }); }