|
1
|
-import 'package:doublefeel_flutter/app/modules/report_common/config/report_date_range_config.dart';
|
|
|
|
2
|
import 'package:doublefeel_flutter/app/modules/report_common/controllers/report_period_logic.dart';
|
1
|
import 'package:doublefeel_flutter/app/modules/report_common/controllers/report_period_logic.dart';
|
|
3
|
import 'package:doublefeel_flutter/app/modules/report_common/models/report_period.dart';
|
2
|
import 'package:doublefeel_flutter/app/modules/report_common/models/report_period.dart';
|
|
4
|
import 'package:flutter_test/flutter_test.dart';
|
3
|
import 'package:flutter_test/flutter_test.dart';
|
|
@@ -10,26 +9,6 @@ class _TestReportPeriodLogic extends ReportPeriodLogic { |
|
@@ -10,26 +9,6 @@ class _TestReportPeriodLogic extends ReportPeriodLogic { |
|
10
|
Future<void> loadReport() async {}
|
9
|
Future<void> loadReport() async {}
|
|
11
|
}
|
10
|
}
|
|
12
|
|
11
|
|
|
13
|
-class _MonthBoundaryReportPeriodLogic extends _TestReportPeriodLogic {
|
|
|
|
14
|
- _MonthBoundaryReportPeriodLogic(this.sourceMonth);
|
|
|
|
15
|
-
|
|
|
|
16
|
- final DateTime sourceMonth;
|
|
|
|
17
|
-
|
|
|
|
18
|
- @override
|
|
|
|
19
|
- DateTime normalizeDate(ReportPeriod period, DateTime date) {
|
|
|
|
20
|
- if (period == ReportPeriod.week &&
|
|
|
|
21
|
- date.year == sourceMonth.year &&
|
|
|
|
22
|
- date.month == sourceMonth.month) {
|
|
|
|
23
|
- // Simulates a month whose latest selectable week starts in the
|
|
|
|
24
|
- // preceding month.
|
|
|
|
25
|
- return sourceMonth.subtract(
|
|
|
|
26
|
- Duration(days: sourceMonth.weekday - DateTime.monday),
|
|
|
|
27
|
- );
|
|
|
|
28
|
- }
|
|
|
|
29
|
- return super.normalizeDate(period, date);
|
|
|
|
30
|
- }
|
|
|
|
31
|
-}
|
|
|
|
32
|
-
|
|
|
|
33
|
void main() {
|
12
|
void main() {
|
|
34
|
group('ReportPeriodLogic period transitions', () {
|
13
|
group('ReportPeriodLogic period transitions', () {
|
|
35
|
test('year to month selects December for a completed year', () async {
|
14
|
test('year to month selects December for a completed year', () async {
|
|
@@ -113,7 +92,7 @@ void main() { |
|
@@ -113,7 +92,7 @@ void main() { |
|
113
|
);
|
92
|
);
|
|
114
|
});
|
93
|
});
|
|
115
|
|
94
|
|
|
116
|
- test('month to week to month keeps the source month',
|
95
|
+ test('month to week to month uses the week start month',
|
|
117
|
() async {
|
96
|
() async {
|
|
118
|
final logic = _TestReportPeriodLogic();
|
97
|
final logic = _TestReportPeriodLogic();
|
|
119
|
final year = DateTime.now().year - 1;
|
98
|
final year = DateTime.now().year - 1;
|
|
@@ -126,52 +105,19 @@ void main() { |
|
@@ -126,52 +105,19 @@ void main() { |
|
126
|
expect(logic.monthStart, DateTime(year, DateTime.december));
|
105
|
expect(logic.monthStart, DateTime(year, DateTime.december));
|
|
127
|
});
|
106
|
});
|
|
128
|
|
107
|
|
|
129
|
- test('clamped cross-month week returns to the original source month',
|
|
|
|
130
|
- () async {
|
|
|
|
131
|
- final year = DateTime.now().year - 1;
|
|
|
|
132
|
- final sourceMonth = List<DateTime>.generate(
|
|
|
|
133
|
- 12,
|
|
|
|
134
|
- (index) => DateTime(year, index + 1),
|
|
|
|
135
|
- ).firstWhere((month) => month.weekday != DateTime.monday);
|
|
|
|
136
|
- final logic = _MonthBoundaryReportPeriodLogic(sourceMonth);
|
|
|
|
137
|
- final clampedWeekStart = sourceMonth.subtract(
|
|
|
|
138
|
- Duration(days: sourceMonth.weekday - DateTime.monday),
|
|
|
|
139
|
- );
|
|
|
|
140
|
- logic.initializeQuery(ReportPeriod.month, sourceMonth);
|
|
|
|
141
|
-
|
|
|
|
142
|
- await logic.selectPeriod(ReportPeriod.week);
|
|
|
|
143
|
- expect(logic.weekStart, clampedWeekStart);
|
|
|
|
144
|
-
|
|
|
|
145
|
- await logic.selectPeriod(ReportPeriod.month);
|
|
|
|
146
|
-
|
|
|
|
147
|
- expect(logic.monthStart, sourceMonth);
|
|
|
|
148
|
- });
|
|
|
|
149
|
-
|
|
|
|
150
|
- test('week to day selects Sunday when the whole week is selectable',
|
108
|
+ test('week to day selects Monday',
|
|
151
|
() async {
|
109
|
() async {
|
|
152
|
final logic = _TestReportPeriodLogic();
|
110
|
final logic = _TestReportPeriodLogic();
|
|
153
|
logic.initializeQuery(
|
111
|
logic.initializeQuery(
|
|
154
|
ReportPeriod.week,
|
112
|
ReportPeriod.week,
|
|
155
|
DateTime(DateTime.now().year - 1, 10, 20),
|
113
|
DateTime(DateTime.now().year - 1, 10, 20),
|
|
156
|
);
|
114
|
);
|
|
157
|
- final expectedDay = logic.weekEnd;
|
115
|
+ final expectedDay = logic.weekStart;
|
|
158
|
|
116
|
|
|
159
|
await logic.selectPeriod(ReportPeriod.day);
|
117
|
await logic.selectPeriod(ReportPeriod.day);
|
|
160
|
|
118
|
|
|
161
|
expect(logic.selectedDate.value, expectedDay);
|
119
|
expect(logic.selectedDate.value, expectedDay);
|
|
162
|
});
|
120
|
});
|
|
163
|
|
121
|
|
|
164
|
- test('week to day clamps a partial latest week to the latest date',
|
|
|
|
165
|
- () async {
|
|
|
|
166
|
- final logic = _TestReportPeriodLogic();
|
|
|
|
167
|
- logic.initializeQuery(
|
|
|
|
168
|
- ReportPeriod.week,
|
|
|
|
169
|
- ReportDateRangeConfig.lastWeekStart(),
|
|
|
|
170
|
- );
|
|
|
|
171
|
-
|
|
|
|
172
|
- await logic.selectPeriod(ReportPeriod.day);
|
|
|
|
173
|
-
|
|
|
|
174
|
- expect(logic.selectedDate.value, ReportDateRangeConfig.lastDate());
|
|
|
|
175
|
- });
|
|
|
|
176
|
});
|
122
|
});
|
|
177
|
} |
123
|
} |