Skip to content

Commit 7a01a2a

Browse files
author
Kamil Klyta
committed
Add missing data tests
1 parent e5b070b commit 7a01a2a

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed

lib/src/controller.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class IndicatorController extends ChangeNotifier {
142142

143143
bool _shouldStopDrag;
144144

145+
/// Should the dragging be stopped
146+
bool get shouldStopDrag => _shouldStopDrag;
147+
145148
/// Whether custom refresh indicator can change [IndicatorState] from `idle` to `dragging`
146149
bool get isRefreshEnabled => _isRefreshEnabled;
147150
bool _isRefreshEnabled;

test/src/controller_test.dart

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,102 @@ void main() {
187187
expect(controller.isScrollingReverse, isTrue);
188188
expect(controller.isScrollIdle, isFalse);
189189
});
190+
191+
group('IndicatorSide -', () {
192+
test('AxisDirection.up - start edge', () {
193+
final controller = IndicatorController()
194+
..setAxisDirection(AxisDirection.up)
195+
..setIndicatorEdge(IndicatorEdge.start);
196+
197+
expect(controller.side, IndicatorSide.bottom);
198+
});
199+
test('AxisDirection.up - end edge', () {
200+
final controller = IndicatorController()
201+
..setAxisDirection(AxisDirection.up)
202+
..setIndicatorEdge(IndicatorEdge.end);
203+
204+
expect(controller.side, IndicatorSide.top);
205+
});
206+
207+
test('AxisDirection.down - start edge', () {
208+
final controller = IndicatorController()
209+
..setAxisDirection(AxisDirection.down)
210+
..setIndicatorEdge(IndicatorEdge.start);
211+
212+
expect(controller.side, IndicatorSide.top);
213+
});
214+
test('AxisDirection.down - end edge', () {
215+
final controller = IndicatorController()
216+
..setAxisDirection(AxisDirection.down)
217+
..setIndicatorEdge(IndicatorEdge.end);
218+
219+
expect(controller.side, IndicatorSide.bottom);
220+
});
221+
222+
test('AxisDirection.left - start edge', () {
223+
final controller = IndicatorController()
224+
..setAxisDirection(AxisDirection.left)
225+
..setIndicatorEdge(IndicatorEdge.start);
226+
227+
expect(controller.side, IndicatorSide.left);
228+
});
229+
test('AxisDirection.left - end edge', () {
230+
final controller = IndicatorController()
231+
..setAxisDirection(AxisDirection.left)
232+
..setIndicatorEdge(IndicatorEdge.end);
233+
234+
expect(controller.side, IndicatorSide.right);
235+
});
236+
test('AxisDirection.right - start edge', () {
237+
final controller = IndicatorController()
238+
..setAxisDirection(AxisDirection.right)
239+
..setIndicatorEdge(IndicatorEdge.start);
240+
241+
expect(controller.side, IndicatorSide.right);
242+
});
243+
test('AxisDirection.right - end edge', () {
244+
final controller = IndicatorController()
245+
..setAxisDirection(AxisDirection.right)
246+
..setIndicatorEdge(IndicatorEdge.end);
247+
248+
expect(controller.side, IndicatorSide.left);
249+
});
250+
251+
test('AxisDirection.right - end none', () {
252+
final controller = IndicatorController()..setIndicatorEdge(null);
253+
254+
expect(controller.side, IndicatorSide.none);
255+
});
256+
});
257+
258+
test('stopDrag - changes the shouldStopDrag - valid state', () {
259+
var controller = IndicatorController()
260+
..setIndicatorState(IndicatorState.dragging);
261+
expect(controller.shouldStopDrag, isFalse);
262+
controller.stopDrag();
263+
expect(controller.shouldStopDrag, isTrue);
264+
265+
controller = IndicatorController()..setIndicatorState(IndicatorState.armed);
266+
expect(controller.shouldStopDrag, isFalse);
267+
controller.stopDrag();
268+
expect(controller.shouldStopDrag, isTrue);
269+
});
270+
271+
test('stopDrag - changes the shouldStopDrag - invalid state', () {
272+
var controller = IndicatorController()
273+
..setIndicatorState(IndicatorState.idle);
274+
expect(() => controller.stopDrag(), throwsA(isA<StateError>()));
275+
276+
controller = IndicatorController()
277+
..setIndicatorState(IndicatorState.loading);
278+
expect(() => controller.stopDrag(), throwsA(isA<StateError>()));
279+
280+
controller = IndicatorController()
281+
..setIndicatorState(IndicatorState.complete);
282+
expect(() => controller.stopDrag(), throwsA(isA<StateError>()));
283+
284+
controller = IndicatorController()
285+
..setIndicatorState(IndicatorState.hiding);
286+
expect(() => controller.stopDrag(), throwsA(isA<StateError>()));
287+
});
190288
}

test/src/data/data_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ void main() {
5858
);
5959
});
6060

61+
test('Equality operator works correctly', () async {
62+
// ignore: prefer_const_constructors
63+
final a = IndicatorStateChange(
64+
IndicatorState.idle,
65+
IndicatorState.dragging,
66+
);
67+
// ignore: prefer_const_constructors
68+
final b = IndicatorStateChange(
69+
IndicatorState.idle,
70+
IndicatorState.dragging,
71+
);
72+
73+
expect(a, equals(b));
74+
expect(a.hashCode, equals(b.hashCode));
75+
});
76+
6177
test("toString method works correctly", () {
6278
var change = const IndicatorStateChange(
6379
IndicatorState.dragging,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:custom_refresh_indicator/src/data/indicator_edge.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
test('IndicatorEdgeGetters - end', () async {
6+
const end = IndicatorEdge.end;
7+
expect(end.isStart, isFalse);
8+
expect(end.isEnd, isTrue);
9+
});
10+
11+
test('IndicatorEdgeGetters - start', () async {
12+
const start = IndicatorEdge.start;
13+
expect(start.isStart, isTrue);
14+
expect(start.isEnd, isFalse);
15+
});
16+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
test('IndicatorSideGetters - left', () async {
6+
const left = IndicatorSide.left;
7+
expect(left.isLeft, isTrue);
8+
expect(left.isTop, isFalse);
9+
expect(left.isRight, isFalse);
10+
expect(left.isBottom, isFalse);
11+
expect(left.isNone, isFalse);
12+
});
13+
14+
test('IndicatorSideGetters - right', () async {
15+
const right = IndicatorSide.right;
16+
expect(right.isLeft, isFalse);
17+
expect(right.isTop, isFalse);
18+
expect(right.isRight, isTrue);
19+
expect(right.isBottom, isFalse);
20+
expect(right.isNone, isFalse);
21+
});
22+
23+
test('IndicatorSideGetters - top', () async {
24+
const right = IndicatorSide.top;
25+
expect(right.isLeft, isFalse);
26+
expect(right.isTop, isTrue);
27+
expect(right.isRight, isFalse);
28+
expect(right.isBottom, isFalse);
29+
expect(right.isNone, isFalse);
30+
});
31+
32+
test('IndicatorSideGetters - bottom', () async {
33+
const right = IndicatorSide.bottom;
34+
expect(right.isLeft, isFalse);
35+
expect(right.isTop, isFalse);
36+
expect(right.isRight, isFalse);
37+
expect(right.isBottom, isTrue);
38+
expect(right.isNone, isFalse);
39+
});
40+
41+
test('IndicatorSideGetters - none', () async {
42+
const none = IndicatorSide.none;
43+
expect(none.isLeft, isFalse);
44+
expect(none.isTop, isFalse);
45+
expect(none.isRight, isFalse);
46+
expect(none.isBottom, isFalse);
47+
expect(none.isNone, isTrue);
48+
});
49+
}

0 commit comments

Comments
 (0)