From e835f1dba31773ee433731bb59acf0a7724cec6e Mon Sep 17 00:00:00 2001 From: birjuvachhani Date: Sun, 31 Dec 2023 21:03:38 +0530 Subject: [PATCH] :white_check_mark: add tests for changing debugShowFloatingThemeButton state via constructor. --- test/debug_floating_theme_buttons_test.dart | 105 ++++++++++++++++++++ test/test_utils.dart | 11 +- 2 files changed, 107 insertions(+), 9 deletions(-) diff --git a/test/debug_floating_theme_buttons_test.dart b/test/debug_floating_theme_buttons_test.dart index ad075fb..5904466 100644 --- a/test/debug_floating_theme_buttons_test.dart +++ b/test/debug_floating_theme_buttons_test.dart @@ -56,6 +56,58 @@ void main() { expect(manager.debugShowFloatingThemeButton, isFalse); }); + testWidgets('setDebugShowFloatingThemeButton test with didUpdateWidget', + (tester) async { + final light = ThemeData.light(); + final dark = ThemeData.dark(); + ValueNotifier debugShowFloatingThemeButton = ValueNotifier(true); + + await tester.pumpWidget( + ValueListenableBuilder( + valueListenable: debugShowFloatingThemeButton, + builder: (context, value, child) { + return AdaptiveTheme( + light: light, + dark: dark, + initial: AdaptiveThemeMode.light, + debugShowFloatingThemeButton: value, + builder: (light, dark) => MaterialApp( + theme: light, + darkTheme: dark, + home: Scaffold( + appBar: AppBar( + title: const Text('AdaptiveTheme Test'), + ), + body: const Center( + child: Text('Hello'), + ), + ), + ), + ); + }, + ), + ); + + DebugFloatingThemeButton widget = tester.widget( + find.byType(DebugFloatingThemeButton)); + expect(widget.debugShow, isTrue); + + BuildContext context = tester.element(find.byType(Scaffold)); + AdaptiveThemeManager manager = AdaptiveTheme.of(context); + + expect(manager.debugShowFloatingThemeButton, isTrue); + + debugShowFloatingThemeButton.value = false; + + await tester.pumpAndSettle(); + + expect(find.byType(DebugFloatingThemeButton), findsNothing); + + context = tester.element(find.byType(Scaffold)); + manager = AdaptiveTheme.of(context); + expect(manager.debugShowFloatingThemeButton, isFalse); + }); + testWidgets('setDebugShowFloatingThemeButton for cupertino test', (tester) async { const light = CupertinoThemeData(brightness: Brightness.light); @@ -85,6 +137,59 @@ void main() { expect(manager.debugShowFloatingThemeButton, isFalse); }); + testWidgets( + 'setDebugShowFloatingThemeButton test for cupertino with didUpdateWidget', + (tester) async { + const light = CupertinoThemeData(brightness: Brightness.light); + const dark = CupertinoThemeData(brightness: Brightness.dark); + ValueNotifier debugShowFloatingThemeButton = ValueNotifier(true); + + await tester.pumpWidget( + ValueListenableBuilder( + valueListenable: debugShowFloatingThemeButton, + builder: (context, value, child) { + return CupertinoAdaptiveTheme( + light: light, + dark: dark, + initial: AdaptiveThemeMode.light, + debugShowFloatingThemeButton: value, + builder: (theme) => CupertinoApp( + theme: theme, + home: const CupertinoPageScaffold( + navigationBar: CupertinoNavigationBar( + middle: Text('Cupertino Example'), + ), + child: Center( + child: Text('Hello'), + ), + ), + ), + ); + }, + ), + ); + + DebugFloatingThemeButton widget = tester.widget( + find.byType(DebugFloatingThemeButton)); + expect(widget.debugShow, isTrue); + + BuildContext context = tester.element(find.byType(CupertinoPageScaffold)); + AdaptiveThemeManager manager = + CupertinoAdaptiveTheme.of(context); + + expect(manager.debugShowFloatingThemeButton, isTrue); + + debugShowFloatingThemeButton.value = false; + + await tester.pumpAndSettle(); + + expect(find.byType(DebugFloatingThemeButton), findsNothing); + + context = tester.element(find.byType(CupertinoPageScaffold)); + manager = CupertinoAdaptiveTheme.of(context); + expect(manager.debugShowFloatingThemeButton, isFalse); + }); + testWidgets('DebugFloatingThemeButton show/hide test', (tester) async { final light = ThemeData.light(); final dark = ThemeData.dark(); diff --git a/test/test_utils.dart b/test/test_utils.dart index e546ac8..5e24e7d 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -21,10 +21,9 @@ Future pumpMaterialApp( required ThemeData dark, required AdaptiveThemeMode mode, bool? debugShowFloatingThemeButton, - bool pumpFrames = false, Duration? maxDuration, }) async { - final widget = AdaptiveTheme( + await tester.pumpWidget(AdaptiveTheme( light: light, dark: dark, initial: mode, @@ -41,13 +40,7 @@ Future pumpMaterialApp( ), ), ), - ); - if (pumpFrames) { - await tester.pumpFrames( - widget, maxDuration ?? const Duration(milliseconds: 500)); - } else { - await tester.pumpWidget(widget); - } + )); } /// pumps [CupertinoAdaptiveTheme] and [CupertinoApp] with given [light], [dark] and [mode].