forked from solutelabs/horizontal_calendar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdate_widget_test.dart
246 lines (217 loc) · 7.42 KB
/
date_widget_test.dart
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:horizontal_calendar_widget/date_helper.dart';
import 'package:horizontal_calendar_widget/date_widget.dart';
void main() {
final defaultLabelOrder = [
LabelType.month,
LabelType.date,
LabelType.weekday,
];
testWidgets(
'Render widgets with date / month/ weekday by default formats if formats are provided not explicitly',
(WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
child: DateWidget(
date: DateTime(2019, 11, 17),
padding: EdgeInsets.all(8),
labelOrder: defaultLabelOrder,
),
textDirection: TextDirection.ltr,
),
);
final date17 = find.text('17');
expect(date17, findsOneWidget);
final month11 = find.text('Nov');
expect(month11, findsOneWidget);
final week17 = find.text('Sun');
expect(week17, findsOneWidget);
});
testWidgets(
'Render widgets with dates / month / week day by default formats if formats are provided explicitly',
(WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
child: DateWidget(
date: DateTime(2019, 11, 17),
padding: EdgeInsets.all(8),
dateFormat: 'dd/MMM',
monthFormat: 'MM',
weekDayFormat: 'EEEE',
labelOrder: defaultLabelOrder,
),
textDirection: TextDirection.ltr,
),
);
final month11 = find.text('11');
expect(month11, findsOneWidget);
final date17 = find.text('17/Nov');
expect(date17, findsOneWidget);
final week17 = find.text('Sunday');
expect(week17, findsOneWidget);
},
);
testWidgets(
'Default decoration should be applied to Date / month / weekday if not selected',
(WidgetTester tester) async {
final dateDecoration = BoxDecoration(
color: Colors.blue,
);
await tester.pumpWidget(
Directionality(
child: DateWidget(
date: DateTime(2019, 11, 17),
padding: EdgeInsets.all(8),
dateFormat: null,
monthFormat: null,
weekDayFormat: null,
defaultDecoration: dateDecoration,
labelOrder: defaultLabelOrder,
),
textDirection: TextDirection.ltr,
),
);
WidgetPredicate datePredicate = (Widget widget) =>
widget is Container && widget.decoration == dateDecoration;
expect(find.byWidgetPredicate(datePredicate), findsOneWidget);
},
);
testWidgets(
'Selected decoration should be applied to Date / month / weekday is selected',
(WidgetTester tester) async {
final dateDecoration = BoxDecoration(
color: Colors.blue,
);
await tester.pumpWidget(
Directionality(
child: DateWidget(
date: DateTime(2019, 11, 17),
padding: EdgeInsets.all(8),
dateFormat: null,
monthFormat: null,
weekDayFormat: null,
selectedDecoration: dateDecoration,
isSelected: true,
labelOrder: defaultLabelOrder,
),
textDirection: TextDirection.ltr,
),
);
WidgetPredicate datePredicate = (Widget widget) =>
widget is Container && widget.decoration == dateDecoration;
expect(find.byWidgetPredicate(datePredicate), findsOneWidget);
},
);
testWidgets(
'Disabled decoration should be applied to Date / month / weekday if is disabled',
(WidgetTester tester) async {
final dateDecoration = BoxDecoration(
color: Colors.blue,
);
final style = TextStyle(color: Colors.white);
await tester.pumpWidget(
Directionality(
child: DateWidget(
date: DateTime(2019, 11, 17),
padding: EdgeInsets.all(8),
dateFormat: null,
monthFormat: null,
weekDayFormat: null,
disabledDecoration: dateDecoration,
isDisabled: true,
dateTextStyle: style,
labelOrder: defaultLabelOrder,
),
textDirection: TextDirection.ltr,
),
);
WidgetPredicate datePredicate = (Widget widget) =>
widget is Container && widget.decoration == dateDecoration;
expect(find.byWidgetPredicate(datePredicate), findsOneWidget);
WidgetPredicate dateTextStyle =
(Widget widget) => widget is Text && widget.style == style;
expect(find.byWidgetPredicate(dateTextStyle), findsOneWidget);
},
);
testWidgets(
'Default Date with all properties',
(WidgetTester tester) async {
final defaultDecoration = BoxDecoration(
color: Colors.blue,
);
final padding = EdgeInsets.symmetric(horizontal: 8);
final monthStyle = TextStyle(color: Colors.white);
final monthFormat = 'MM';
final dateStyle = TextStyle(color: Colors.black);
final dateFormat = 'dd/MM';
final weekDayStyle = TextStyle(color: Colors.green);
final weekDayFormat = 'EEE';
await tester.pumpWidget(
Directionality(
child: DateWidget(
date: DateTime(2019, 11, 17),
padding: padding,
dateFormat: dateFormat,
dateTextStyle: dateStyle,
monthFormat: monthFormat,
monthTextStyle: monthStyle,
weekDayFormat: weekDayFormat,
weekDayTextStyle: weekDayStyle,
defaultDecoration: defaultDecoration,
labelOrder: defaultLabelOrder,
),
textDirection: TextDirection.ltr,
),
);
WidgetPredicate datePredicate = (Widget widget) =>
widget is Container && widget.decoration == defaultDecoration;
expect(find.byWidgetPredicate(datePredicate), findsOneWidget);
WidgetPredicate dateTextStyle = (Widget widget) =>
widget is Text && widget.style == dateStyle && widget.data == '17/11';
expect(find.byWidgetPredicate(dateTextStyle), findsOneWidget);
WidgetPredicate monthTextStyle = (Widget widget) =>
widget is Text && widget.style == monthStyle && widget.data == '11';
expect(find.byWidgetPredicate(monthTextStyle), findsOneWidget);
WidgetPredicate weekDayTextStyle = (Widget widget) =>
widget is Text &&
widget.style == weekDayStyle &&
widget.data == 'Sun';
expect(find.byWidgetPredicate(weekDayTextStyle), findsOneWidget);
},
);
testWidgets(
'Lables should render as per provided order',
(WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
child: DateWidget(
date: DateTime(2019, 11, 17),
padding: EdgeInsets.all(8),
labelOrder: [
LabelType.date,
LabelType.month,
],
dateTextStyle: null,
),
textDirection: TextDirection.ltr,
),
);
WidgetPredicate columnPredicate = (Widget widget) {
if (widget is Column) {
final children = widget.children;
if (children.length < 2) {
return false;
}
Text firstText = children[0];
Text secondText = children[1];
if (firstText.data == "17" && secondText.data == "Nov") {
return true;
}
}
return false;
};
expect(find.byWidgetPredicate(columnPredicate), findsOneWidget);
},
);
}