@@ -8,6 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
88void setupDataSnapshotTests () {
99 group ('DataSnapshot' , () {
1010 late DatabaseReference ref;
11+ DatabaseReference getRef (String path) {
12+ return FirebaseDatabase .instance.ref ('tests' ).child (path);
13+ }
1114
1215 setUp (() async {
1316 ref = FirebaseDatabase .instance.ref ('tests' );
@@ -17,35 +20,41 @@ void setupDataSnapshotTests() {
1720 });
1821
1922 test ('it returns the correct key' , () async {
23+ final ref = getRef ('key' );
2024 final s = await ref.get ();
21- expect (s.key, 'tests ' );
25+ expect (s.key, 'key ' );
2226 });
2327
2428 test ('it returns a string value' , () async {
29+ final ref = getRef ('string' );
2530 await ref.set ('foo' );
2631 final s = await ref.get ();
2732 expect (s.value, 'foo' );
2833 });
2934
3035 test ('it returns a number value' , () async {
36+ final ref = getRef ('num' );
3137 await ref.set (123 );
3238 final s = await ref.get ();
3339 expect (s.value, 123 );
3440 });
3541
3642 test ('it returns a bool value' , () async {
43+ final ref = getRef ('bool' );
3744 await ref.set (false );
3845 final s = await ref.get ();
3946 expect (s.value, false );
4047 });
4148
4249 test ('it returns a null value' , () async {
50+ final ref = getRef ('null' );
4351 await ref.set (null );
4452 final s = await ref.get ();
4553 expect (s.value, isNull);
4654 });
4755
4856 test ('it returns a List value' , () async {
57+ final ref = getRef ('list' );
4958 final data = [
5059 'a' ,
5160 2 ,
@@ -71,49 +80,58 @@ void setupDataSnapshotTests() {
7180 });
7281
7382 test ('it returns a Map value' , () async {
83+ final ref = getRef ('map' );
7484 final data = {'foo' : 'bar' };
85+
7586 await ref.set (data);
7687 final s = await ref.get ();
7788 expect (s.value, equals (data));
7889 });
7990
8091 test ('non-string Map keys are converted to strings' , () async {
92+ final ref = getRef ('converted' );
8193 final data = {1 : 'foo' , 2 : 'bar' , 'foo' : 'bar' };
8294 await ref.set (data);
8395 final s = await ref.get ();
8496 expect (s.value, equals ({'1' : 'foo' , '2' : 'bar' , 'foo' : 'bar' }));
8597 });
8698
8799 test ('setWithPriority returns the correct priority' , () async {
100+ final ref = getRef ('priority' );
88101 await ref.setWithPriority ('foo' , 1 );
89102 final s = await ref.get ();
90103 expect (s.priority, 1 );
91104 });
92105
93106 test ('setPriority returns the correct priority' , () async {
107+ final ref = getRef ('priority-2' );
94108 await ref.set ('foo' );
95109 await ref.setPriority (2 );
96110 final s = await ref.get ();
97111 expect (s.priority, 2 );
98112 });
99113
100114 test ('exists returns true' , () async {
115+ final ref = getRef ('exists' );
101116 await ref.set ('foo' );
102117 final s = await ref.get ();
103118 expect (s.exists, isTrue);
104119 });
105120
106121 test ('exists returns false' , () async {
122+ final ref = getRef ('exists-not-here' );
107123 final s = await ref.get ();
108124 expect (s.exists, isFalse);
109125 });
110126
111127 test ('hasChild returns false' , () async {
128+ final ref = getRef ('has-child' );
112129 final s = await ref.get ();
113130 expect (s.hasChild ('bar' ), isFalse);
114131 });
115132
116133 test ('hasChild returns true' , () async {
134+ final ref = getRef ('has-no-child' );
117135 await ref.set ({
118136 'foo' : {'bar' : 'baz' },
119137 });
@@ -122,13 +140,15 @@ void setupDataSnapshotTests() {
122140 });
123141
124142 test ('child returns the correct snapshot for lists' , () async {
143+ final ref = getRef ('list-snap' );
125144 await ref.set ([0 , 1 ]);
126145 final s = await ref.get ();
127146 expect (s.child ('1' ), isA <DataSnapshot >());
128147 expect (s.child ('1' ).value, 1 );
129148 });
130149
131150 test ('child returns the correct snapshot' , () async {
151+ final ref = getRef ('child-snap' );
132152 await ref.set ({
133153 'foo' : {'bar' : 'baz' },
134154 });
@@ -138,6 +158,7 @@ void setupDataSnapshotTests() {
138158 });
139159
140160 test ('children returns the children in order' , () async {
161+ final ref = getRef ('children' );
141162 await ref.set ({
142163 'a' : 3 ,
143164 'b' : 2 ,
0 commit comments