main
 1
 2import 'package:blood_pressure_app/model/storage/interval_store.dart';
 3import 'package:flutter_test/flutter_test.dart';
 4import 'package:health_data_store/health_data_store.dart';
 5
 6void main() {
 7  test('base constructor should initialize with values', () {
 8    final storageObject = IntervalStorage(stepSize: TimeStep.month, range: DateRange(
 9        start: DateTime.fromMillisecondsSinceEpoch(1234),
10        end: DateTime.fromMillisecondsSinceEpoch(5678),
11    ),);
12
13    expect(storageObject.stepSize, TimeStep.month);
14    expect(storageObject.currentRange.start.millisecondsSinceEpoch, 1234);
15    expect(storageObject.currentRange.end.millisecondsSinceEpoch, 5678);
16  });
17
18  test('base constructor should initialize to default without values', () {
19    final storageObject = IntervalStorage();
20    expect(storageObject.stepSize, TimeStep.last7Days);
21    expect(storageObject.currentRange.start.millisecondsSinceEpoch, lessThanOrEqualTo(DateTime
22        .now()
23        .millisecondsSinceEpoch,),);
24  });
25
26  test('base constructor should initialize with only incomplete parameters', () {
27    // only tests for no crashes
28    IntervalStorage(stepSize: TimeStep.last30Days);
29    IntervalStorage(range: DateRange(
30        start: DateTime.fromMillisecondsSinceEpoch(1234),
31        end: DateTime.fromMillisecondsSinceEpoch(5678),
32    ),);
33  });
34
35
36  test('intervall lengths should match step size', () {
37    final dayIntervall = IntervalStorage(stepSize: TimeStep.day);
38    final weekIntervall = IntervalStorage(stepSize: TimeStep.week);
39    final monthIntervall = IntervalStorage(stepSize: TimeStep.month);
40    final yearIntervall = IntervalStorage(stepSize: TimeStep.year);
41    final last7DaysIntervall = IntervalStorage(stepSize: TimeStep.last7Days);
42    final last30DaysIntervall = IntervalStorage(stepSize: TimeStep.last30Days);
43
44    expect(dayIntervall.currentRange.duration.inHours, 24);
45    expect(weekIntervall.currentRange.duration.inDays, 7);
46    expect(monthIntervall.currentRange.duration.inDays, inInclusiveRange(28, 31));
47    expect(yearIntervall.currentRange.duration.inDays, inInclusiveRange(365, 366));
48    expect(last7DaysIntervall.currentRange.duration.inDays, 7);
49    expect(last30DaysIntervall.currentRange.duration.inDays, 30);
50  });
51
52  test('intervall lengths should still be correct after moving', () {
53    final dayIntervall = IntervalStorage(stepSize: TimeStep.day);
54    final weekIntervall = IntervalStorage(stepSize: TimeStep.week);
55    final monthIntervall = IntervalStorage(stepSize: TimeStep.month);
56    final yearIntervall = IntervalStorage(stepSize: TimeStep.year);
57    final last7DaysIntervall = IntervalStorage(stepSize: TimeStep.last7Days);
58    final last30DaysIntervall = IntervalStorage(stepSize: TimeStep.last30Days);
59    final customIntervall = IntervalStorage(stepSize: TimeStep.custom, range: DateRange(
60        start: DateTime.fromMillisecondsSinceEpoch(1234),
61        end: DateTime.fromMillisecondsSinceEpoch(1234 + 24 * 60 * 60 * 1000), // one day
62    ),);
63
64    expect(customIntervall.currentRange.duration.inMilliseconds, 24 * 60 * 60 * 1000);
65
66    dayIntervall.moveDataRangeByStep(1);
67    weekIntervall.moveDataRangeByStep(1);
68    monthIntervall.moveDataRangeByStep(1);
69    yearIntervall.moveDataRangeByStep(1);
70    last7DaysIntervall.moveDataRangeByStep(1);
71    last30DaysIntervall.moveDataRangeByStep(1);
72    customIntervall.moveDataRangeByStep(1);
73
74    expect(dayIntervall.currentRange.duration.inHours, 24);
75    expect(weekIntervall.currentRange.duration.inDays, 7);
76    expect(monthIntervall.currentRange.duration.inDays, inInclusiveRange(28, 31));
77    expect(yearIntervall.currentRange.duration.inDays, inInclusiveRange(365, 366));
78    expect(last7DaysIntervall.currentRange.duration.inDays, 7);
79    expect(last30DaysIntervall.currentRange.duration.inDays, 30);
80    expect(customIntervall.currentRange.duration.inMilliseconds, 24 * 60 * 60 * 1000);
81
82    dayIntervall.moveDataRangeByStep(-2);
83    weekIntervall.moveDataRangeByStep(-2);
84    monthIntervall.moveDataRangeByStep(-2);
85    yearIntervall.moveDataRangeByStep(-2);
86    last7DaysIntervall.moveDataRangeByStep(-2);
87    last30DaysIntervall.moveDataRangeByStep(-2);
88    customIntervall.moveDataRangeByStep(-2);
89
90    expect(dayIntervall.currentRange.duration.inHours, 24);
91    expect(weekIntervall.currentRange.duration.inDays, 7);
92    expect(monthIntervall.currentRange.duration.inDays, inInclusiveRange(28, 31));
93    expect(yearIntervall.currentRange.duration.inDays, inInclusiveRange(365, 366));
94    expect(last7DaysIntervall.currentRange.duration.inDays, 7);
95    expect(last30DaysIntervall.currentRange.duration.inDays, 30);
96    expect(customIntervall.currentRange.duration.inMilliseconds, 24 * 60 * 60 * 1000);
97  });
98
99}