diff --git a/test/debug_floating_theme_buttons_test.dart b/test/debug_floating_theme_buttons_test.dart new file mode 100644 index 0000000..67cd299 --- /dev/null +++ b/test/debug_floating_theme_buttons_test.dart @@ -0,0 +1,81 @@ +/* + * // Copyright © 2020 Birju Vachhani. All rights reserved. + * // Use of this source code is governed by an Apache license that can be + * // found in the LICENSE file. + */ + +import 'package:adaptive_theme/adaptive_theme.dart'; +import 'package:adaptive_theme/src/debug_floating_theme_buttons.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'test_utils.dart'; + +void main() { + testWidgets('debugShowFloatingThemeButton test', (tester) async { + final light = ThemeData.light(); + final dark = ThemeData.dark(); + await pumpMaterialApp( + tester, + light: light, + dark: dark, + mode: AdaptiveThemeMode.light, + debugShowFloatingThemeButton: true, + ); + + final widget = tester.widget( + find.byType(DebugFloatingThemeButton)); + expect(widget.debugShow, isTrue); + }); + + testWidgets('DebugFloatingThemeButton show/hide test', (tester) async { + final light = ThemeData.light(); + final dark = ThemeData.dark(); + await pumpMaterialApp( + tester, + light: light, + dark: dark, + mode: AdaptiveThemeMode.light, + debugShowFloatingThemeButton: true, + ); + + final BuildContext context = tester.element(find.byType(Scaffold)); + final manager = AdaptiveTheme.of(context); + + final widgetFinder = find.byType(DebugFloatingThemeButton); + final dragIndicatorFinder = find.descendant( + of: widgetFinder, matching: find.byIcon(Icons.drag_indicator_rounded)); + + final widget = tester.widget(widgetFinder); + expect(widget.debugShow, isTrue); + + final rect = tester.getRect(dragIndicatorFinder); + await tester.tapAt(rect.center); + await tester.pumpAndSettle(); + + final toggleButtonFinder = + find.descendant(of: widgetFinder, matching: find.byType(ToggleButtons)); + ToggleButtons buttonsWidget() => + tester.widget(toggleButtonFinder); + + // check if light theme is selected + expect( + buttonsWidget().isSelected, containsAllInOrder([true, false, false])); + + // select dark theme + buttonsWidget().onPressed?.call(1); + await tester.pumpAndSettle(); + + expect(manager.mode, AdaptiveThemeMode.dark); + expect( + buttonsWidget().isSelected, containsAllInOrder([false, true, false])); + + // select system theme + buttonsWidget().onPressed?.call(2); + await tester.pumpAndSettle(); + + expect(manager.mode, AdaptiveThemeMode.system); + expect( + buttonsWidget().isSelected, containsAllInOrder([false, false, true])); + }); +} diff --git a/test/test_utils.dart b/test/test_utils.dart index 4d9d557..d679764 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -20,11 +20,13 @@ Future pumpMaterialApp( required ThemeData light, required ThemeData dark, required AdaptiveThemeMode mode, + bool? debugShowFloatingThemeButton, }) async { await tester.pumpWidget(AdaptiveTheme( light: light, dark: dark, initial: mode, + debugShowFloatingThemeButton: debugShowFloatingThemeButton ?? false, builder: (light, dark) => MaterialApp( theme: light, darkTheme: dark,