Skip to content

Commit 164a723

Browse files
committed
chore(tests): setup testing for AngularFirestore
1 parent 881be94 commit 164a723

File tree

6 files changed

+22
-61
lines changed

6 files changed

+22
-61
lines changed

karma.conf.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ module.exports = function(config) {
2626

2727
'karma-test-shim.js',
2828
'node_modules/firebase/firebase.js',
29+
'node_modules/firestore/firestore.js',
2930
'dist/packages-dist/bundles/core.umd.{js,map}',
3031
'dist/packages-dist/bundles/auth.umd.{js,map}',
3132
'dist/packages-dist/bundles/database.umd.{js,map}',
33+
'dist/packages-dist/bundles/firestore.umd.{js,map}',
3234
'dist/packages-dist/bundles/test.umd.{js,map}',
3335
],
3436

src/firestore/firestore.spec.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as firebase from 'firebase/app';
55
import { TestBed, inject } from '@angular/core/testing';
66
import { COMMON_CONFIG } from './test-config';
77

8-
describe('AngularFirestore', () => {
8+
fdescribe('AngularFirestore', () => {
99
let app: firebase.app.App;
10-
let db: AngularFirestore;
10+
let afs: AngularFirestore;
1111

1212
beforeEach(() => {
1313
TestBed.configureTestingModule({
@@ -16,9 +16,9 @@ describe('AngularFirestore', () => {
1616
AngularFirestoreModule
1717
]
1818
});
19-
inject([FirebaseApp, AngularFirestore], (_app: firebase.app.App, _db: AngularFirestore) => {
19+
inject([FirebaseApp, AngularFirestore], (_app: firebase.app.App, _afs: AngularFirestore) => {
2020
app = _app;
21-
db = _db;
21+
afs = _afs;
2222
})();
2323
});
2424

@@ -28,4 +28,13 @@ describe('AngularFirestore', () => {
2828
// ref.remove(done);
2929
});
3030

31+
describe('AngularFirestore', () => {
32+
33+
// document
34+
it('should have an initialized Firebase app', () => {
35+
expect(afs.app).toBeDefined();
36+
});
37+
38+
});
39+
3140
});

src/firestore/firestore.ts

+3-56
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import * as firebase from 'firebase/app';
2-
import * as firestore from 'firestore';
32
import 'firestore';
4-
import { Firestore, CollectionReference, Query } from 'firestore';
3+
import { Firestore, CollectionReference, Query, DocumentSnapshot, QuerySnapshot } from 'firestore';
54
import { Observable } from 'rxjs/Observable';
6-
import { Observer } from 'rxjs/Observer';
7-
import { Operator } from 'rxjs/Operator';
8-
import { Subscriber } from 'rxjs/Subscriber';
95
import { Subscription } from 'rxjs/Subscription';
106

117
import { Injectable } from '@angular/core';
@@ -19,7 +15,7 @@ export class AngularFirestore {
1915
this.firestore = app.firestore();
2016
}
2117

22-
collection(path: string, queryFn: (ref: CollectionReference) => Query = ref => ref): Observable<firestore.QuerySnapshot> {
18+
collection(path: string, queryFn: (ref: CollectionReference) => Query = ref => ref): Observable<QuerySnapshot> {
2319
const ref = this.firestore.collection(path);
2420
const query = queryFn(ref);
2521
return new Observable(subscriber => {
@@ -28,60 +24,11 @@ export class AngularFirestore {
2824
});
2925
}
3026

31-
doc(path: string): Observable<firestore.DocumentSnapshot> {
27+
doc(path: string): Observable<DocumentSnapshot> {
3228
const ref = this.firestore.doc(path);
3329
return new Observable(subscriber => {
3430
const unsubscribe = ref.onSnapshot(subscriber);
3531
return new Subscription(unsubscribe);
3632
});
3733
}
38-
39-
}
40-
41-
export class FirestoreDocumentReferenceObservable<T> extends Observable<T> {
42-
constructor(public originalRef: firestore.DocumentReference, subscribe?: <R>(subscriber: Subscriber<R>) => Subscription) {
43-
super(subscribe);
44-
}
45-
46-
lift<T, R>(operator: Operator<T, R>): Observable<R> {
47-
const observable = new FirestoreDocumentReferenceObservable<R>(this.originalRef);
48-
observable.source = this;
49-
observable.operator = operator;
50-
observable.originalRef = this.originalRef;
51-
return observable;
52-
}
53-
}
54-
55-
export class FirestoreCollectionReferenceObservable<T> extends Observable<T> {
56-
constructor(public originalRef: firestore.CollectionReference, public query: firestore.Query, subscribe?: <R>(subscriber: Subscriber<R>) => Subscription) {
57-
super(subscribe);
58-
}
59-
60-
lift<T, R>(operator: Operator<T, R>): Observable<R> {
61-
const observable = new FirestoreCollectionReferenceObservable<R>(this.originalRef, this.query);
62-
observable.source = this;
63-
observable.operator = operator;
64-
observable.query = this.query;
65-
observable.originalRef = this.originalRef;
66-
return observable;
67-
}
6834
}
69-
70-
/**
71-
* collection(path: string, queryFn: (ref: CollectionReference) => Query = ref => ref): Observable<firestore.QuerySnapshot> {
72-
const ref = this.firestore.collection(path);
73-
const query = queryFn(ref);
74-
return new FirestoreCollectionReferenceObservable(ref, query, subscriber => {
75-
const unsubscribe = query.onSnapshot(subscriber.next, subscriber.error, subscriber.complete);
76-
return new Subscription(unsubscribe);
77-
});
78-
}
79-
80-
doc(path: string): Observable<firestore.DocumentSnapshot> {
81-
const ref = this.firestore.doc(path);
82-
return new FirestoreDocumentReferenceObservable(ref, subscriber => {
83-
const unsubscribe = ref.onSnapshot(subscriber.next, subscriber.error, subscriber.complete);
84-
return new Subscription(unsubscribe);
85-
});
86-
}
87-
*/

src/firestore/index.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './firestore.spec';

src/root.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './packages-dist/database/firebase_list_observable.spec';
66
export * from './packages-dist/database/firebase_object_observable.spec';
77
export * from './packages-dist/database/query_observable.spec';
88
export * from './packages-dist/auth/auth.spec';
9+
export * from './packages-dist/firestore/firestore.spec';

tools/build.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const GLOBALS = {
4040
'@angular/core/testing': 'ng.core.testing',
4141
'angularfire2': 'angularfire2',
4242
'angularfire2/auth': 'angularfire2.auth',
43-
'angularfire2/database': 'angularfire2.database'
43+
'angularfire2/database': 'angularfire2.database',
44+
'angularfire2/firestore': 'angularfire2.firestore'
4445
};
4546

4647
// Map of dependency versions across all packages

0 commit comments

Comments
 (0)