Showing
2 changed files
with
127 additions
and
0 deletions
test/get_rxstate_test.dart
0 → 100644
1 | +import 'package:flutter/material.dart'; | ||
2 | +import 'package:flutter_test/flutter_test.dart'; | ||
3 | +import 'package:get/get.dart'; | ||
4 | + | ||
5 | +void main() { | ||
6 | + testWidgets("GetController smoke test", (tester) async { | ||
7 | + await tester.pumpWidget( | ||
8 | + MaterialApp( | ||
9 | + home: GetX<Controller>( | ||
10 | + init: Controller(), | ||
11 | + builder: (controller) { | ||
12 | + return Column( | ||
13 | + children: [ | ||
14 | + Text( | ||
15 | + 'Count: ${controller.counter.value}', | ||
16 | + ), | ||
17 | + Text( | ||
18 | + 'Double: ${controller.doubleNum.value}', | ||
19 | + ), | ||
20 | + Text( | ||
21 | + 'String: ${controller.string.value}', | ||
22 | + ), | ||
23 | + Text( | ||
24 | + 'List: ${controller.list.length}', | ||
25 | + ), | ||
26 | + Text( | ||
27 | + 'Bool: ${controller.boolean.value}', | ||
28 | + ), | ||
29 | + Text( | ||
30 | + 'Map: ${controller.map.value.length}', | ||
31 | + ), | ||
32 | + FlatButton( | ||
33 | + child: Text("increment"), | ||
34 | + onPressed: () => controller.increment(), | ||
35 | + ) | ||
36 | + ], | ||
37 | + ); | ||
38 | + }, | ||
39 | + ), | ||
40 | + ), | ||
41 | + ); | ||
42 | + | ||
43 | + expect(find.text("Count: 0"), findsOneWidget); | ||
44 | + expect(find.text("Double: 0.0"), findsOneWidget); | ||
45 | + expect(find.text("String: string"), findsOneWidget); | ||
46 | + expect(find.text("Bool: true"), findsOneWidget); | ||
47 | + expect(find.text("List: 0"), findsOneWidget); | ||
48 | + expect(find.text("Map: 0"), findsOneWidget); | ||
49 | + | ||
50 | + Controller.to.increment(); | ||
51 | + | ||
52 | + await tester.pump(); | ||
53 | + | ||
54 | + expect(find.text("Count: 1"), findsOneWidget); | ||
55 | + | ||
56 | + await tester.tap(find.text('increment')); | ||
57 | + | ||
58 | + await tester.pump(); | ||
59 | + | ||
60 | + expect(find.text("Count: 2"), findsOneWidget); | ||
61 | + }); | ||
62 | +} | ||
63 | + | ||
64 | +class Controller extends RxController { | ||
65 | + static Controller get to => Get.find(); | ||
66 | + | ||
67 | + var counter = 0.obs; | ||
68 | + var doubleNum = 0.0.obs; | ||
69 | + var string = "string".obs; | ||
70 | + var list = [].obs; | ||
71 | + var map = {}.obs; | ||
72 | + var boolean = true.obs; | ||
73 | + | ||
74 | + void increment() { | ||
75 | + counter.value++; | ||
76 | + } | ||
77 | +} |
test/get_state_test.dart
0 → 100644
1 | +import 'package:flutter/material.dart'; | ||
2 | +import 'package:flutter_test/flutter_test.dart'; | ||
3 | +import 'package:get/get.dart'; | ||
4 | + | ||
5 | +void main() { | ||
6 | + testWidgets("GetController smoke test", (tester) async { | ||
7 | + await tester.pumpWidget( | ||
8 | + MaterialApp( | ||
9 | + home: GetBuilder<Controller>( | ||
10 | + init: Controller(), | ||
11 | + builder: (controller) => Column( | ||
12 | + children: [ | ||
13 | + Text( | ||
14 | + '${controller.counter}', | ||
15 | + ), | ||
16 | + FlatButton( | ||
17 | + child: Text("increment"), | ||
18 | + onPressed: () => controller.increment(), | ||
19 | + ) | ||
20 | + ], | ||
21 | + ), | ||
22 | + ), | ||
23 | + ), | ||
24 | + ); | ||
25 | + | ||
26 | + expect(find.text("0"), findsOneWidget); | ||
27 | + | ||
28 | + Controller.to.increment(); | ||
29 | + | ||
30 | + await tester.pump(); | ||
31 | + | ||
32 | + expect(find.text("1"), findsOneWidget); | ||
33 | + | ||
34 | + await tester.tap(find.text('increment')); | ||
35 | + | ||
36 | + await tester.pump(); | ||
37 | + | ||
38 | + expect(find.text("2"), findsOneWidget); | ||
39 | + }); | ||
40 | +} | ||
41 | + | ||
42 | +class Controller extends GetController { | ||
43 | + static Controller get to => Get.find(); | ||
44 | + | ||
45 | + int counter = 0; | ||
46 | + void increment() { | ||
47 | + counter++; | ||
48 | + update(this); | ||
49 | + } | ||
50 | +} |
-
Please register or login to post a comment