import 'dart:async'; import 'dart:ui'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/application/detached/detached_preferences.dart'; import 'package:pipelines_app/ui/theme/app_design.dart'; import 'package:pipelines_app/ui/theme/app_design_controller.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'; void main() { testWidgets('the design and font chosen in the main window follow into a ' 'detached window, on a storage event and on coming to the front', ( tester, ) async { final designStore = MemoryAppDesignStore(); final fontStore = MemoryAppFontStore(); final designs = AppDesignController(store: designStore); final fonts = AppFontController(store: fontStore, loader: (_, _) async {}); final changes = StreamController.broadcast(); var reloads = 0; final follower = DetachedPreferencesFollower( changes: changes.stream, designs: designs, fonts: fonts, reload: () async => reloads++, )..start(); addTearDown(() { follower.dispose(); unawaited(changes.close()); }); // Another window stores the Terminal design and a font. designStore.id = AppDesign.terminal.id; fontStore.id = AppFont.inter.id; changes.add(null); await tester.pumpAndSettle(); expect(reloads, 1); expect(designs.design, AppDesign.terminal); expect(fonts.selected, AppFont.inter); expect(fonts.family, AppFont.inter.family); // Back to the defaults, seen when this window comes to the front. designStore.id = AppDesign.standard.id; fontStore.id = AppFont.system.id; tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive); tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed); await tester.pumpAndSettle(); expect(reloads, 2); expect(designs.design, AppDesign.standard); expect(fonts.selected, AppFont.system); expect(fonts.family, isNull); // Following never writes the choice back. expect(designStore.id, AppDesign.standard.id); }); test('a font id this device cannot resolve keeps the current font', () async { final store = MemoryAppFontStore(AppFont.inter.id); final fonts = AppFontController(store: store, loader: (_, _) async {}); await fonts.restore(); expect(fonts.selected, AppFont.inter); store.id = 'custom-unknown'; await fonts.restore(); expect(fonts.selected, AppFont.inter); }); }