Skip to content

Commit

Permalink
Add test for theme card
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Aug 14, 2023
1 parent 1bf9cfb commit d331a36
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/common/widgets/fields/date_picker_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/common/widgets/fields/input_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/common/widgets/fields/select_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/common/widgets/fields/slider_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
93 changes: 93 additions & 0 deletions test/theme/widgets/theme_card_test.dart
Original file line number Diff line number Diff line change
@@ -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<void> _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
}

0 comments on commit d331a36

Please sign in to comment.