@@ -39,25 +39,33 @@ const StargazerSource = {
39
39
error : StargazerActions . failed
40
40
}
41
41
} ,
42
- alwaysFetchUsers ( ) {
43
- return {
44
- remote,
45
- local : ( ) => true ,
46
- loading : StargazerActions . fetchingUsers ,
47
- success : StargazerActions . usersReceived ,
48
- error : StargazerActions . failed ,
49
- shouldFetch : ( ) => true
50
- }
42
+
43
+ alwaysFetchUsers : {
44
+ remote,
45
+ local : ( ) => true ,
46
+ loading : StargazerActions . fetchingUsers ,
47
+ success : StargazerActions . usersReceived ,
48
+ error : StargazerActions . failed ,
49
+ shouldFetch : ( ) => true
51
50
} ,
52
- neverFetchUsers ( ) {
53
- return {
54
- remote,
55
- local : ( ) => false ,
56
- loading : StargazerActions . fetchingUsers ,
57
- success : StargazerActions . usersReceived ,
58
- error : StargazerActions . failed ,
59
- shouldFetch : ( ) => false
60
- }
51
+
52
+ neverFetchUsers : {
53
+ remote,
54
+ local : ( ) => false ,
55
+ loading : StargazerActions . fetchingUsers ,
56
+ success : StargazerActions . usersReceived ,
57
+ error : StargazerActions . failed ,
58
+ shouldFetch : ( ) => false
59
+ } ,
60
+
61
+ fetchRepos : {
62
+ remote ( ) {
63
+ return new Promise ( ( resolve , reject ) => {
64
+ setTimeout ( ( ) => resolve ( 'TESTTEST' ) , 200 )
65
+ } )
66
+ } ,
67
+ success : StargazerActions . usersReceived ,
68
+ error : StargazerActions . failed
61
69
}
62
70
}
63
71
@@ -165,7 +173,6 @@ export default {
165
173
count ( )
166
174
test ( )
167
175
assert . ok ( local . calledOnce )
168
- assert . notOk ( StargazerStore . hasError ( ) , 'no errors' )
169
176
assert . notOk ( StargazerStore . isLoading ( ) )
170
177
assert ( remote . callCount === 0 )
171
178
done ( )
@@ -185,7 +192,6 @@ export default {
185
192
assert ( state . users . length === 0 )
186
193
} else if ( spy . callCount === 2 ) {
187
194
assert . match ( state . errorMessage , / t h i n g s b r o k e / )
188
- assert . ok ( StargazerStore . hasError ( ) , 'we have an error' )
189
195
count ( )
190
196
test ( )
191
197
assert . notOk ( StargazerStore . isLoading ( ) )
@@ -210,5 +216,56 @@ export default {
210
216
assert . notOk ( StargazerStore . isLoading ( ) )
211
217
assert ( remote . callCount === 0 )
212
218
} ,
219
+
220
+ 'multiple loads' ( done ) {
221
+ const unsub = StargazerStore . listen ( ( state ) => {
222
+ if ( state . users === 'TESTTEST' ) {
223
+ assert . notOk ( StargazerStore . isLoading ( ) )
224
+ unsub ( )
225
+ done ( )
226
+ } else {
227
+ assert . ok ( StargazerStore . isLoading ( ) )
228
+ }
229
+ } )
230
+
231
+ StargazerStore . fetchUsers ( )
232
+ StargazerStore . fetchRepos ( )
233
+ assert . ok ( StargazerStore . isLoading ( ) )
234
+ } ,
235
+
236
+ 'as a function' ( ) {
237
+ const FauxSource = sinon . stub ( ) . returns ( { } )
238
+
239
+ @datasource ( FauxSource )
240
+ class FauxStore {
241
+ static displayName = 'FauxStore'
242
+ }
243
+
244
+ const store = alt . createStore ( FauxStore )
245
+
246
+ assert ( FauxSource . firstCall . args [ 0 ] === alt )
247
+ assert . isFunction ( store . isLoading )
248
+ } ,
249
+
250
+ 'as an object' ( ) {
251
+ const actions = alt . generateActions ( 'test' )
252
+
253
+ const PojoSource = {
254
+ justTesting : {
255
+ success : actions . test ,
256
+ error : actions . test ,
257
+ }
258
+ }
259
+
260
+ @datasource ( PojoSource )
261
+ class MyStore {
262
+ static displayName = 'MyStore'
263
+ }
264
+
265
+ const store = alt . createStore ( MyStore )
266
+
267
+ assert . isFunction ( store . justTesting )
268
+ assert . isFunction ( store . isLoading )
269
+ } ,
213
270
}
214
271
}
0 commit comments