-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ add tests for DebugFloatingThemeButton.
- Loading branch information
1 parent
5b82e8a
commit abc01e2
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DebugFloatingThemeButton>( | ||
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<DebugFloatingThemeButton>(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<ToggleButtons>(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])); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters