Skip to content

Commit

Permalink
✅ add tests for changing debugShowFloatingThemeButton state via const…
Browse files Browse the repository at this point in the history
…ructor.
  • Loading branch information
BirjuVachhani committed Dec 31, 2023
1 parent 68d63bb commit e835f1d
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 9 deletions.
105 changes: 105 additions & 0 deletions test/debug_floating_theme_buttons_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> debugShowFloatingThemeButton = ValueNotifier(true);

await tester.pumpWidget(
ValueListenableBuilder<bool>(
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<DebugFloatingThemeButton>(
find.byType(DebugFloatingThemeButton));
expect(widget.debugShow, isTrue);

BuildContext context = tester.element(find.byType(Scaffold));
AdaptiveThemeManager<ThemeData> 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);
Expand Down Expand Up @@ -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<bool> debugShowFloatingThemeButton = ValueNotifier(true);

await tester.pumpWidget(
ValueListenableBuilder<bool>(
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<DebugFloatingThemeButton>(
find.byType(DebugFloatingThemeButton));
expect(widget.debugShow, isTrue);

BuildContext context = tester.element(find.byType(CupertinoPageScaffold));
AdaptiveThemeManager<CupertinoThemeData> 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();
Expand Down
11 changes: 2 additions & 9 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Future<void> 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,
Expand All @@ -41,13 +40,7 @@ Future<void> 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].
Expand Down

0 comments on commit e835f1d

Please sign in to comment.