1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_calendar_carousel/src/calendar_header.dart';
import 'package:flutter/material.dart';
void main() {
final title = "Test title";
final margin = const EdgeInsets.symmetric(vertical: 16.0);
final iconColor = Colors.blueAccent;
testWidgets('Verify Header Defaults', (WidgetTester tester) async {
var headerTapped = false;
var leftPressed = false;
var rightPressed = false;
await tester.pumpWidget(wrapped(CalendarHeader(
headerTitle: title,
headerMargin: margin,
showHeader: true,
showHeaderButtons: true,
headerIconColor: iconColor,
onHeaderTitlePressed: () => headerTapped = true,
onRightButtonPressed: () => rightPressed = true,
onLeftButtonPressed: () => leftPressed = true,
)));
expect(find.text(title), findsOneWidget);
await tester.tap(find.byType(TextButton));
await tester.pump();
expect(headerTapped, equals(true));
await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_right));
await tester.pump();
expect(rightPressed, equals(true));
await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_left));
await tester.pump();
expect(leftPressed, equals(true));
});
testWidgets('Verify No header Renders', (WidgetTester tester) async {
final noHeaderEmpty = CalendarHeader(
showHeader: false,
headerTitle: '',
onLeftButtonPressed: () {},
onHeaderTitlePressed: () {},
onRightButtonPressed: () {},
);
await tester.pumpWidget(Container(child: noHeaderEmpty));
expect(find.byWidget(noHeaderEmpty), findsOneWidget);
});
testWidgets('Verify Header Is Not Touchable', (WidgetTester tester) async {
await tester.pumpWidget(wrapped(CalendarHeader(
headerTitle: title,
headerMargin: margin,
showHeader: true,
showHeaderButtons: true,
headerIconColor: iconColor,
onHeaderTitlePressed: null,
onRightButtonPressed: () {},
onLeftButtonPressed: () {},
)));
// the header TextButton Should not render
final touchableHeader = find.byType(TextButton);
expect(touchableHeader, findsNothing);
});
testWidgets('Verify No Header Buttons', (WidgetTester tester) async {
await tester.pumpWidget(wrapped(CalendarHeader(
headerTitle: title,
headerMargin: margin,
showHeader: true,
showHeaderButtons: false,
headerIconColor: iconColor,
onHeaderTitlePressed: () {},
onRightButtonPressed: () {},
onLeftButtonPressed: () {},
)));
// the header IconButtons Should not render
final headerButton = find.byType(IconButton);
expect(headerButton, findsNothing);
});
}
// header uses Row which requires MaterialApp as an ancestor
Widget wrapped(Widget widget) => MaterialApp(
home: Container(
child: Material(child: widget),
),
);
|