From d331a364f0fc17a327a082428c792d5482e18b8e Mon Sep 17 00:00:00 2001 From: AhsanSarwar45 Date: Mon, 14 Aug 2023 18:39:21 +0500 Subject: [PATCH] Add test for theme card --- .../fields/date_picker_field_test.dart | 2 +- .../widgets/fields/input_field_test.dart | 2 +- .../widgets/fields/select_field_test.dart | 2 +- .../widgets/fields/slider_field_test.dart | 2 +- test/theme/widgets/theme_card_test.dart | 93 +++++++++++++++++++ 5 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 test/theme/widgets/theme_card_test.dart diff --git a/test/common/widgets/fields/date_picker_field_test.dart b/test/common/widgets/fields/date_picker_field_test.dart index 57e1c87f..318b5b1b 100644 --- a/test/common/widgets/fields/date_picker_field_test.dart +++ b/test/common/widgets/fields/date_picker_field_test.dart @@ -8,7 +8,7 @@ const title = 'Test'; const hintText = 'TestHint'; void main() { - group('DatePickerField Widget', () { + group('DatePickerField', () { group('shows input field', () { testWidgets('title correctly', (tester) async { await _renderWidget(tester); diff --git a/test/common/widgets/fields/input_field_test.dart b/test/common/widgets/fields/input_field_test.dart index d635c450..0d42472c 100644 --- a/test/common/widgets/fields/input_field_test.dart +++ b/test/common/widgets/fields/input_field_test.dart @@ -7,7 +7,7 @@ const title = 'Test'; const hintText = 'TestHint'; void main() { - group('InputField Widget', () { + group('InputField', () { group('shows input field', () { testWidgets('title correctly', (tester) async { await _renderWidget(tester); diff --git a/test/common/widgets/fields/select_field_test.dart b/test/common/widgets/fields/select_field_test.dart index 6527229b..c0c3a7f9 100644 --- a/test/common/widgets/fields/select_field_test.dart +++ b/test/common/widgets/fields/select_field_test.dart @@ -12,7 +12,7 @@ final choices = [ ]; void main() { - group('SelectField Widget', () { + group('SelectField', () { group('shows select field', () { testWidgets('title correctly', (tester) async { await _renderWidget(tester); diff --git a/test/common/widgets/fields/slider_field_test.dart b/test/common/widgets/fields/slider_field_test.dart index 833f3358..50227e32 100644 --- a/test/common/widgets/fields/slider_field_test.dart +++ b/test/common/widgets/fields/slider_field_test.dart @@ -6,7 +6,7 @@ const name = 'Test Slider'; const unit = 'unit'; void main() { - group('SliderField Widget', () { + group('SliderField', () { testWidgets('shows name correctly', (tester) async { await _renderWidget(tester); final nameFinder = find.text(name); diff --git a/test/theme/widgets/theme_card_test.dart b/test/theme/widgets/theme_card_test.dart new file mode 100644 index 00000000..1652f48d --- /dev/null +++ b/test/theme/widgets/theme_card_test.dart @@ -0,0 +1,93 @@ +import 'package:clock_app/alarm/types/alarm.dart'; +import 'package:clock_app/alarm/widgets/alarm_card.dart'; +import 'package:clock_app/common/types/time.dart'; +import 'package:clock_app/theme/theme.dart'; +import 'package:clock_app/theme/types/color_scheme.dart'; +import 'package:clock_app/theme/types/style_theme.dart'; +import 'package:clock_app/theme/utils/style_theme.dart'; +import 'package:clock_app/theme/widgets/theme_card.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +const testKey = Key('key'); +var sampleStyleTheme = StyleTheme(); +var sampleColorScheme = ColorSchemeData(); + +void main() { + group('ThemeCard', () { + setUp( + () async {}, + ); + + testWidgets( + 'shows theme name correctly', + (tester) async { + await _renderStyleThemeCard(tester); + + expect(find.text(sampleStyleTheme.name), findsOneWidget); + }, + ); + + testWidgets( + 'shows menu icon', + (tester) async { + await _renderStyleThemeCard(tester); + + expect(find.byIcon(Icons.keyboard_arrow_down_rounded), findsOneWidget); + }, + ); + + testWidgets( + 'shows edit icon', + (tester) async { + await _renderStyleThemeCard(tester); + + expect(find.byIcon(Icons.edit), findsOneWidget); + }, + ); + + group( + 'shows tick mark correctly', + () { + testWidgets( + 'when not selected', + (tester) async { + await _renderStyleThemeCard(tester); + + expect(find.byIcon(Icons.check), findsNothing); + }, + ); + + testWidgets( + 'when selected', + (tester) async { + await _renderStyleThemeCard(tester, isSelected: true); + + expect(find.byIcon(Icons.check), findsOneWidget); + }, + ); + }, + ); + }); +} + +Future _renderStyleThemeCard(WidgetTester tester, + {bool isSelected = false}) async { + await tester.pumpWidget( + MaterialApp( + theme: defaultTheme, + home: Scaffold( + body: ThemeCard( + themeItem: sampleStyleTheme, + isSelected: isSelected, + onPressDelete: () {}, + onPressDuplicate: () {}, + onPressEdit: () {}, + getThemeFromItem: getThemeFromStyleTheme, + key: testKey, + ), + ), + ), + ); + //action +}