1
1
import { AngularFireModule , FirebaseApp } from '@angular/fire' ;
2
2
import { AngularFirestore , AngularFirestoreCollectionGroup , AngularFirestoreModule , SETTINGS } from '../public_api' ;
3
3
import { Query , QueryGroupFn } from '../interfaces' ;
4
- import { BehaviorSubject , Subscription } from 'rxjs' ;
4
+ import { BehaviorSubject } from 'rxjs' ;
5
5
import { skip , switchMap , take } from 'rxjs/operators' ;
6
- import { inject , TestBed } from '@angular/core/testing' ;
6
+ import { TestBed } from '@angular/core/testing' ;
7
7
import { COMMON_CONFIG } from '../../test-config' ;
8
8
import 'firebase/firestore' ;
9
9
@@ -23,7 +23,6 @@ async function collectionHarness(afs: AngularFirestore, items: number, queryGrou
23
23
describe ( 'AngularFirestoreCollectionGroup' , ( ) => {
24
24
let app : FirebaseApp ;
25
25
let afs : AngularFirestore ;
26
- let sub : Subscription ;
27
26
28
27
beforeEach ( ( ) => {
29
28
TestBed . configureTestingModule ( {
@@ -35,10 +34,9 @@ describe('AngularFirestoreCollectionGroup', () => {
35
34
{ provide : SETTINGS , useValue : { host : 'localhost:8080' , ssl : false } }
36
35
]
37
36
} ) ;
38
- inject ( [ FirebaseApp , AngularFirestore ] , ( _app : FirebaseApp , _afs : AngularFirestore ) => {
39
- app = _app ;
40
- afs = _afs ;
41
- } ) ( ) ;
37
+
38
+ app = TestBed . inject ( FirebaseApp ) ;
39
+ afs = TestBed . inject ( AngularFirestore ) ;
42
40
} ) ;
43
41
44
42
afterEach ( ( ) => {
@@ -49,7 +47,7 @@ describe('AngularFirestoreCollectionGroup', () => {
49
47
50
48
it ( 'should get unwrapped snapshot' , async ( done : any ) => {
51
49
const ITEMS = 4 ;
52
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
50
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
53
51
54
52
const sub = stocks . valueChanges ( ) . subscribe ( data => {
55
53
// unsub immediately as we will be deleting data at the bottom
@@ -73,9 +71,10 @@ describe('AngularFirestoreCollectionGroup', () => {
73
71
74
72
it ( 'should handle multiple subscriptions (hot)' , async ( done : any ) => {
75
73
const ITEMS = 4 ;
76
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
74
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
77
75
const changes = stocks . valueChanges ( ) ;
78
- const sub = changes . subscribe ( ( ) => { } ) . add (
76
+ const sub = changes . subscribe ( ( ) => {
77
+ } ) . add (
79
78
changes . pipe ( take ( 1 ) ) . subscribe ( data => {
80
79
expect ( data . length ) . toEqual ( ITEMS ) ;
81
80
sub . unsubscribe ( ) ;
@@ -87,10 +86,11 @@ describe('AngularFirestoreCollectionGroup', () => {
87
86
88
87
it ( 'should handle multiple subscriptions (warm)' , async ( done : any ) => {
89
88
const ITEMS = 4 ;
90
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
89
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
91
90
const changes = stocks . valueChanges ( ) ;
92
- changes . pipe ( take ( 1 ) ) . subscribe ( ( ) => { } ) . add ( ( ) => {
93
- const sub = changes . pipe ( take ( 1 ) ) . subscribe ( data => {
91
+ changes . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
92
+ } ) . add ( ( ) => {
93
+ changes . pipe ( take ( 1 ) ) . subscribe ( data => {
94
94
expect ( data . length ) . toEqual ( ITEMS ) ;
95
95
} ) . add ( ( ) => {
96
96
deleteThemAll ( names , ref ) . then ( done ) . catch ( done . fail ) ;
@@ -101,8 +101,8 @@ describe('AngularFirestoreCollectionGroup', () => {
101
101
it ( 'should handle dynamic queries that return empty sets' , async ( done ) => {
102
102
const ITEMS = 10 ;
103
103
let count = 0 ;
104
- const firstIndex = 0 ;
105
- const pricefilter$ = new BehaviorSubject < number | null > ( null ) ;
104
+
105
+ const pricefilter$ = new BehaviorSubject < number | null > ( null ) ;
106
106
const randomCollectionName = randomName ( afs . firestore ) ;
107
107
const ref = afs . firestore . collection ( `${ randomCollectionName } ` ) ;
108
108
const names = await createRandomStocks ( afs . firestore , ref , ITEMS ) ;
@@ -131,14 +131,13 @@ describe('AngularFirestoreCollectionGroup', () => {
131
131
it ( 'should listen to all snapshotChanges() by default' , async ( done ) => {
132
132
const ITEMS = 10 ;
133
133
let count = 0 ;
134
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
134
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
135
135
const sub = stocks . snapshotChanges ( ) . subscribe ( data => {
136
- const ids = data . map ( d => d . payload . doc . id ) ;
137
136
count = count + 1 ;
138
137
// the first time should all be 'added'
139
138
if ( count === 1 ) {
140
139
// make an update
141
- ref . doc ( names [ 0 ] ) . update ( { price : 2 } ) ;
140
+ ref . doc ( names [ 0 ] ) . update ( { price : 2 } ) ;
142
141
}
143
142
// on the second round, make sure the array is still the same
144
143
// length but the updated item is now modified
@@ -154,9 +153,10 @@ describe('AngularFirestoreCollectionGroup', () => {
154
153
155
154
it ( 'should handle multiple subscriptions (hot)' , async ( done : any ) => {
156
155
const ITEMS = 4 ;
157
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
156
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
158
157
const changes = stocks . snapshotChanges ( ) ;
159
- const sub = changes . subscribe ( ( ) => { } ) . add (
158
+ const sub = changes . subscribe ( ( ) => {
159
+ } ) . add (
160
160
changes . pipe ( take ( 1 ) ) . subscribe ( data => {
161
161
expect ( data . length ) . toEqual ( ITEMS ) ;
162
162
sub . unsubscribe ( ) ;
@@ -168,10 +168,11 @@ describe('AngularFirestoreCollectionGroup', () => {
168
168
169
169
it ( 'should handle multiple subscriptions (warm)' , async ( done : any ) => {
170
170
const ITEMS = 4 ;
171
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
171
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
172
172
const changes = stocks . snapshotChanges ( ) ;
173
- changes . pipe ( take ( 1 ) ) . subscribe ( ( ) => { } ) . add ( ( ) => {
174
- const sub = changes . pipe ( take ( 1 ) ) . subscribe ( data => {
173
+ changes . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
174
+ } ) . add ( ( ) => {
175
+ changes . pipe ( take ( 1 ) ) . subscribe ( data => {
175
176
expect ( data . length ) . toEqual ( ITEMS ) ;
176
177
} ) . add ( ( ) => {
177
178
deleteThemAll ( names , ref ) . then ( done ) . catch ( done . fail ) ;
@@ -183,7 +184,7 @@ describe('AngularFirestoreCollectionGroup', () => {
183
184
const ITEMS = 10 ;
184
185
let count = 0 ;
185
186
let firstIndex = 0 ;
186
- const { randomCollectionName , ref, stocks, names } =
187
+ const { ref, stocks, names } =
187
188
await collectionHarness ( afs , ITEMS , ref => ref . orderBy ( 'price' , 'desc' ) ) ;
188
189
const sub = stocks . snapshotChanges ( ) . subscribe ( data => {
189
190
count = count + 1 ;
@@ -208,7 +209,7 @@ describe('AngularFirestoreCollectionGroup', () => {
208
209
209
210
it ( 'should be able to filter snapshotChanges() types - modified' , async ( done ) => {
210
211
const ITEMS = 10 ;
211
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
212
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
212
213
213
214
const sub = stocks . snapshotChanges ( [ 'modified' ] ) . pipe ( skip ( 1 ) ) . subscribe ( data => {
214
215
sub . unsubscribe ( ) ;
@@ -224,7 +225,9 @@ describe('AngularFirestoreCollectionGroup', () => {
224
225
225
226
it ( 'should be able to filter snapshotChanges() types - added' , async ( done ) => {
226
227
const ITEMS = 10 ;
227
- let { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
228
+ const harness = await collectionHarness ( afs , ITEMS ) ;
229
+ const { randomCollectionName, ref, stocks } = harness ;
230
+ let { names } = harness ;
228
231
const nextId = ref . doc ( 'a' ) . id ;
229
232
230
233
const sub = stocks . snapshotChanges ( [ 'added' ] ) . pipe ( skip ( 1 ) ) . subscribe ( data => {
@@ -265,20 +268,24 @@ describe('AngularFirestoreCollectionGroup', () => {
265
268
266
269
it ( 'should be able to filter snapshotChanges() types - added/modified' , async ( done ) => {
267
270
const ITEMS = 10 ;
268
- let { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
271
+
272
+ const harness = await collectionHarness ( afs , ITEMS ) ;
273
+ const { ref, stocks } = harness ;
274
+ let { names } = harness ;
275
+
269
276
const nextId = ref . doc ( 'a' ) . id ;
270
277
let count = 0 ;
271
278
272
- const sub = stocks . snapshotChanges ( [ 'added' , 'modified' ] ) . pipe ( skip ( 1 ) , take ( 2 ) ) . subscribe ( data => {
279
+ stocks . snapshotChanges ( [ 'added' , 'modified' ] ) . pipe ( skip ( 1 ) , take ( 2 ) ) . subscribe ( data => {
273
280
count += 1 ;
274
- if ( count == 1 ) {
281
+ if ( count === 1 ) {
275
282
const change = data . filter ( x => x . payload . doc . id === nextId ) [ 0 ] ;
276
283
expect ( data . length ) . toEqual ( ITEMS + 1 ) ;
277
284
expect ( change . payload . doc . data ( ) . price ) . toEqual ( 2 ) ;
278
285
expect ( change . type ) . toEqual ( 'added' ) ;
279
286
delayUpdate ( ref , names [ 0 ] , { price : 2 } ) ;
280
287
}
281
- if ( count == 2 ) {
288
+ if ( count === 2 ) {
282
289
const change = data . filter ( x => x . payload . doc . id === names [ 0 ] ) [ 0 ] ;
283
290
expect ( data . length ) . toEqual ( ITEMS + 1 ) ;
284
291
expect ( change . payload . doc . data ( ) . price ) . toEqual ( 2 ) ;
@@ -294,7 +301,7 @@ describe('AngularFirestoreCollectionGroup', () => {
294
301
295
302
it ( 'should be able to filter snapshotChanges() types - removed' , async ( done ) => {
296
303
const ITEMS = 10 ;
297
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
304
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
298
305
299
306
const sub = stocks . snapshotChanges ( [ 'added' , 'removed' ] ) . pipe ( skip ( 1 ) ) . subscribe ( data => {
300
307
sub . unsubscribe ( ) ;
@@ -314,7 +321,7 @@ describe('AngularFirestoreCollectionGroup', () => {
314
321
315
322
it ( 'should get stateChanges() updates' , async ( done : any ) => {
316
323
const ITEMS = 10 ;
317
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
324
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
318
325
319
326
const sub = stocks . stateChanges ( ) . subscribe ( data => {
320
327
// unsub immediately as we will be deleting data at the bottom
@@ -337,11 +344,11 @@ describe('AngularFirestoreCollectionGroup', () => {
337
344
it ( 'should listen to all stateChanges() by default' , async ( done ) => {
338
345
const ITEMS = 10 ;
339
346
let count = 0 ;
340
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
341
- const sub = stocks . stateChanges ( ) . subscribe ( data => {
347
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
348
+ stocks . stateChanges ( ) . subscribe ( data => {
342
349
count = count + 1 ;
343
350
if ( count === 1 ) {
344
- ref . doc ( names [ 0 ] ) . update ( { price : 2 } ) ;
351
+ ref . doc ( names [ 0 ] ) . update ( { price : 2 } ) ;
345
352
}
346
353
if ( count === 2 ) {
347
354
expect ( data . length ) . toEqual ( 1 ) ;
@@ -353,9 +360,10 @@ describe('AngularFirestoreCollectionGroup', () => {
353
360
354
361
it ( 'should handle multiple subscriptions (hot)' , async ( done : any ) => {
355
362
const ITEMS = 4 ;
356
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
363
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
357
364
const changes = stocks . stateChanges ( ) ;
358
- const sub = changes . subscribe ( ( ) => { } ) . add (
365
+ const sub = changes . subscribe ( ( ) => {
366
+ } ) . add (
359
367
changes . pipe ( take ( 1 ) ) . subscribe ( data => {
360
368
expect ( data . length ) . toEqual ( ITEMS ) ;
361
369
sub . unsubscribe ( ) ;
@@ -367,10 +375,11 @@ describe('AngularFirestoreCollectionGroup', () => {
367
375
368
376
it ( 'should handle multiple subscriptions (warm)' , async ( done : any ) => {
369
377
const ITEMS = 4 ;
370
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
378
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
371
379
const changes = stocks . stateChanges ( ) ;
372
- changes . pipe ( take ( 1 ) ) . subscribe ( ( ) => { } ) . add ( ( ) => {
373
- const sub = changes . pipe ( take ( 1 ) ) . subscribe ( data => {
380
+ changes . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
381
+ } ) . add ( ( ) => {
382
+ changes . pipe ( take ( 1 ) ) . subscribe ( data => {
374
383
expect ( data . length ) . toEqual ( ITEMS ) ;
375
384
} ) . add ( ( ) => {
376
385
deleteThemAll ( names , ref ) . then ( done ) . catch ( done . fail ) ;
@@ -380,8 +389,7 @@ describe('AngularFirestoreCollectionGroup', () => {
380
389
381
390
it ( 'should be able to filter stateChanges() types - modified' , async ( done ) => {
382
391
const ITEMS = 10 ;
383
- const count = 0 ;
384
- const { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
392
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
385
393
386
394
const sub = stocks . stateChanges ( [ 'modified' ] ) . subscribe ( data => {
387
395
sub . unsubscribe ( ) ;
@@ -397,8 +405,11 @@ describe('AngularFirestoreCollectionGroup', () => {
397
405
398
406
it ( 'should be able to filter stateChanges() types - added' , async ( done ) => {
399
407
const ITEMS = 10 ;
400
- const count = 0 ;
401
- let { randomCollectionName, ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
408
+
409
+ const harness = await collectionHarness ( afs , ITEMS ) ;
410
+ const { ref, stocks } = harness ;
411
+ let { names } = harness ;
412
+
402
413
403
414
const sub = stocks . stateChanges ( [ 'added' ] ) . pipe ( skip ( 1 ) ) . subscribe ( data => {
404
415
sub . unsubscribe ( ) ;
@@ -416,7 +427,7 @@ describe('AngularFirestoreCollectionGroup', () => {
416
427
417
428
it ( 'should be able to filter stateChanges() types - removed' , async ( done ) => {
418
429
const ITEMS = 10 ;
419
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
430
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
420
431
421
432
const sub = stocks . stateChanges ( [ 'removed' ] ) . subscribe ( data => {
422
433
sub . unsubscribe ( ) ;
@@ -434,11 +445,11 @@ describe('AngularFirestoreCollectionGroup', () => {
434
445
it ( 'should listen to all events for auditTrail() by default' , async ( done ) => {
435
446
const ITEMS = 10 ;
436
447
let count = 0 ;
437
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
448
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
438
449
const sub = stocks . auditTrail ( ) . subscribe ( data => {
439
450
count = count + 1 ;
440
451
if ( count === 1 ) {
441
- ref . doc ( names [ 0 ] ) . update ( { price : 2 } ) ;
452
+ ref . doc ( names [ 0 ] ) . update ( { price : 2 } ) ;
442
453
}
443
454
if ( count === 2 ) {
444
455
sub . unsubscribe ( ) ;
@@ -451,7 +462,7 @@ describe('AngularFirestoreCollectionGroup', () => {
451
462
452
463
it ( 'should be able to filter auditTrail() types - removed' , async ( done ) => {
453
464
const ITEMS = 10 ;
454
- const { randomCollectionName , ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
465
+ const { ref, stocks, names } = await collectionHarness ( afs , ITEMS ) ;
455
466
456
467
const sub = stocks . auditTrail ( [ 'removed' ] ) . subscribe ( data => {
457
468
sub . unsubscribe ( ) ;
0 commit comments