-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for button components
- add some tests for different states of `AdaptivePrimaryButton` - add some tests for different states of `AdaptiveSecondaryButton`
- Loading branch information
1 parent
f6f819f
commit 98aeec4
Showing
2 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
test/features/widgets/buttons/adaptive_primary_button/adaptive_primary_button_test.dart
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,113 @@ | ||
import 'package:fluent_ui/fluent_ui.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:pactus_gui_widgetbook/app_styles.dart'; | ||
import 'package:pactus_gui_widgetbook/src/core/enum/request_state_enum.dart'; | ||
import 'package:pactus_gui_widgetbook/src/features/widgets/buttons/adaptive_primary_button/adaptive_primary_button.dart'; | ||
|
||
void main() { | ||
group('AdaptivePrimaryButton', () { | ||
late bool wasPressed; | ||
|
||
setUp(() { | ||
wasPressed = false; | ||
}); | ||
|
||
Widget createTestableWidget({ | ||
required String title, | ||
required RequestStateEnum requestState, | ||
required VoidCallback? onPressed, | ||
required FluentThemeData themeWithAccent, | ||
}) { | ||
return FluentApp( | ||
debugShowCheckedModeBanner: false, | ||
theme: themeWithAccent, | ||
home: AppTheme( | ||
themeData: themeWithAccent, | ||
child: ScaffoldPage( | ||
content: Center( | ||
child: AdaptivePrimaryButton( | ||
title: title, | ||
requestState: requestState, | ||
onPressed: onPressed, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
testWidgets('renders correctly and is clickable when idle', (WidgetTester tester) async { | ||
const testTitle = 'Test Button'; | ||
final themeWithAccent = AppThemeData.lightTheme(const Color(0xFF0A4D7E)); | ||
|
||
await tester.pumpWidget(createTestableWidget( | ||
title: testTitle, | ||
requestState: RequestStateEnum.loaded, | ||
onPressed: () { | ||
wasPressed = true; | ||
}, | ||
themeWithAccent: themeWithAccent, | ||
)); | ||
|
||
expect(find.text(testTitle), findsOneWidget); | ||
|
||
final button = find.byType(FilledButton); | ||
expect(tester.widget<FilledButton>(button).onPressed, isNotNull); | ||
|
||
await tester.tap(button); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(wasPressed, isTrue); | ||
}); | ||
|
||
testWidgets('renders correctly and is disabled when loading', (WidgetTester tester) async { | ||
const testTitle = 'Loading Button'; | ||
final themeWithAccent = AppThemeData.lightTheme(const Color(0xFF0A4D7E)); | ||
|
||
await tester.pumpWidget(createTestableWidget( | ||
title: testTitle, | ||
requestState: RequestStateEnum.loading, | ||
onPressed: () { | ||
wasPressed = true; | ||
}, | ||
themeWithAccent: themeWithAccent, | ||
)); | ||
|
||
expect(find.text(testTitle), findsNothing); | ||
|
||
expect(find.byType(SizedBox), findsWidgets); | ||
|
||
final button = find.byType(FilledButton); | ||
expect(tester.widget<FilledButton>(button).onPressed, isNull); | ||
|
||
await tester.tap(button); | ||
await tester.pumpAndSettle(); | ||
expect(wasPressed, isFalse); | ||
}); | ||
|
||
|
||
testWidgets('renders correctly with dark theme', (WidgetTester tester) async { | ||
const testTitle = 'Dark Theme Button'; | ||
final themeWithAccent = AppThemeData.darkTheme(const Color(0xFF0F6CBD)); | ||
|
||
await tester.pumpWidget(createTestableWidget( | ||
title: testTitle, | ||
requestState: RequestStateEnum.loaded, | ||
onPressed: () { | ||
wasPressed = true; | ||
}, | ||
themeWithAccent: themeWithAccent, | ||
)); | ||
|
||
expect(find.text(testTitle), findsOneWidget); | ||
|
||
final button = find.byType(FilledButton); | ||
expect(tester.widget<FilledButton>(button).onPressed, isNotNull); | ||
|
||
await tester.tap(button); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(wasPressed, isTrue); | ||
}); | ||
}); | ||
} |
112 changes: 112 additions & 0 deletions
112
test/features/widgets/buttons/adaptive_secondary_button/adaptive_secondary_button_test.dart
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,112 @@ | ||
import 'package:fluent_ui/fluent_ui.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:pactus_gui_widgetbook/app_styles.dart'; | ||
import 'package:pactus_gui_widgetbook/src/core/enum/request_state_enum.dart'; | ||
import 'package:pactus_gui_widgetbook/src/features/widgets/buttons/adaptive_secondary_button/adaptive_secondary_button.dart'; | ||
|
||
void main() { | ||
group('AdaptiveSecondaryButton', () { | ||
late bool wasPressed; | ||
|
||
setUp(() { | ||
wasPressed = false; | ||
}); | ||
|
||
Widget createTestableWidget({ | ||
required String title, | ||
required RequestStateEnum requestState, | ||
required VoidCallback? onPressed, | ||
required FluentThemeData themeWithAccent, | ||
}) { | ||
return FluentApp( | ||
debugShowCheckedModeBanner: false, | ||
theme: themeWithAccent, | ||
home: AppTheme( | ||
themeData: themeWithAccent, | ||
child: ScaffoldPage( | ||
content: Center( | ||
child: AdaptiveSecondaryButton( | ||
title: title, | ||
requestState: requestState, | ||
onPressed: onPressed, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
testWidgets('renders correctly and is clickable when idle', (WidgetTester tester) async { | ||
const testTitle = 'Test Button'; | ||
final themeWithAccent = AppThemeData.lightTheme(const Color(0xFF0A4D7E)); | ||
|
||
await tester.pumpWidget(createTestableWidget( | ||
title: testTitle, | ||
requestState: RequestStateEnum.loaded, | ||
onPressed: () { | ||
wasPressed = true; | ||
}, | ||
themeWithAccent: themeWithAccent, | ||
)); | ||
|
||
expect(find.text(testTitle), findsOneWidget); | ||
|
||
final button = find.byType(OutlinedButton); | ||
expect(tester.widget<OutlinedButton>(button).onPressed, isNotNull); | ||
|
||
await tester.tap(button); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(wasPressed, isTrue); | ||
}); | ||
|
||
testWidgets('renders correctly and is disabled when loading', (WidgetTester tester) async { | ||
const testTitle = 'Loading Button'; | ||
final themeWithAccent = AppThemeData.lightTheme(const Color(0xFF0A4D7E)); | ||
|
||
await tester.pumpWidget(createTestableWidget( | ||
title: testTitle, | ||
requestState: RequestStateEnum.loading, | ||
onPressed: () { | ||
wasPressed = true; | ||
}, | ||
themeWithAccent: themeWithAccent, | ||
)); | ||
|
||
expect(find.text(testTitle), findsNothing); | ||
|
||
expect(find.byType(SizedBox), findsWidgets); | ||
|
||
final button = find.byType(OutlinedButton); | ||
expect(tester.widget<OutlinedButton>(button).onPressed, isNull); | ||
|
||
await tester.tap(button); | ||
await tester.pumpAndSettle(); | ||
expect(wasPressed, isFalse); | ||
}); | ||
|
||
testWidgets('renders correctly with dark theme', (WidgetTester tester) async { | ||
const testTitle = 'Dark Theme Button'; | ||
final themeWithAccent = AppThemeData.darkTheme(const Color(0xFF0F6CBD)); | ||
|
||
await tester.pumpWidget(createTestableWidget( | ||
title: testTitle, | ||
requestState: RequestStateEnum.loaded, | ||
onPressed: () { | ||
wasPressed = true; | ||
}, | ||
themeWithAccent: themeWithAccent, | ||
)); | ||
|
||
expect(find.text(testTitle), findsOneWidget); | ||
|
||
final button = find.byType(OutlinedButton); | ||
expect(tester.widget<OutlinedButton>(button).onPressed, isNotNull); | ||
|
||
await tester.tap(button); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(wasPressed, isTrue); | ||
}); | ||
}); | ||
} |