Skip to content

Commit

Permalink
✅ add tests for dynamically changing debugShowFloatingThemeButton state.
Browse files Browse the repository at this point in the history
  • Loading branch information
BirjuVachhani committed Dec 31, 2023
1 parent 2918641 commit 68d63bb
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
57 changes: 57 additions & 0 deletions test/debug_floating_theme_buttons_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:adaptive_theme/src/debug_floating_theme_buttons.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

Expand All @@ -28,6 +29,62 @@ void main() {
expect(widget.debugShow, isTrue);
});

testWidgets('setDebugShowFloatingThemeButton test', (tester) async {
final light = ThemeData.light();
final dark = ThemeData.dark();
await pumpMaterialApp(
tester,
light: light,
dark: dark,
mode: AdaptiveThemeMode.light,
debugShowFloatingThemeButton: true,
);

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);
manager.setDebugShowFloatingThemeButton(false);

await tester.pumpAndSettle();

expect(find.byType(DebugFloatingThemeButton), findsNothing);
expect(manager.debugShowFloatingThemeButton, isFalse);
});

testWidgets('setDebugShowFloatingThemeButton for cupertino test',
(tester) async {
const light = CupertinoThemeData(brightness: Brightness.light);
const dark = CupertinoThemeData(brightness: Brightness.dark);
await pumpCupertinoApp(
tester,
light: light,
dark: dark,
mode: AdaptiveThemeMode.light,
debugShowFloatingThemeButton: true,
);

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);
manager.setDebugShowFloatingThemeButton(false);

await tester.pumpAndSettle();

expect(find.byType(DebugFloatingThemeButton), findsNothing);
expect(manager.debugShowFloatingThemeButton, isFalse);
});

testWidgets('DebugFloatingThemeButton show/hide test', (tester) async {
final light = ThemeData.light();
final dark = ThemeData.dark();
Expand Down
14 changes: 12 additions & 2 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ Future<void> pumpMaterialApp(
required ThemeData dark,
required AdaptiveThemeMode mode,
bool? debugShowFloatingThemeButton,
bool pumpFrames = false,
Duration? maxDuration,
}) async {
await tester.pumpWidget(AdaptiveTheme(
final widget = AdaptiveTheme(
light: light,
dark: dark,
initial: mode,
Expand All @@ -39,7 +41,13 @@ 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 All @@ -48,11 +56,13 @@ Future<void> pumpCupertinoApp(
required CupertinoThemeData light,
required CupertinoThemeData dark,
required AdaptiveThemeMode mode,
bool debugShowFloatingThemeButton = false,
}) async {
await tester.pumpWidget(CupertinoAdaptiveTheme(
light: light,
dark: dark,
initial: mode,
debugShowFloatingThemeButton: debugShowFloatingThemeButton,
builder: (theme) => CupertinoApp(
theme: theme,
home: const CupertinoPageScaffold(
Expand Down

0 comments on commit 68d63bb

Please sign in to comment.