Skip to content

Commit dd0efb1

Browse files
committed
Bumping the tests
1 parent 73413e8 commit dd0efb1

File tree

3 files changed

+266
-386
lines changed

3 files changed

+266
-386
lines changed

src/analytics/analytics.spec.ts

Lines changed: 29 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,86 @@
1-
import { User } from 'firebase/app';
2-
import { Observable, Subject } from 'rxjs'
1+
import { ReflectiveInjector, Provider } from '@angular/core';
32
import { TestBed, inject } from '@angular/core/testing';
43
import { FirebaseApp, FirebaseOptionsToken, AngularFireModule, FirebaseNameOrConfigToken } from '@angular/fire';
5-
import { AngularFireAuth, AngularFireAuthModule } from '@angular/fire/auth';
4+
import { AngularFireAnalytics, AngularFireAnalyticsModule, AUTOMATICALLY_SET_CURRENT_SCREEN, AUTOMATICALLY_LOG_SCREEN_VIEWS, ANALYTICS_COLLECTION_ENABLED, AUTOMATICALLY_TRACK_USER_IDENTIFIER, APP_VERSION, APP_NAME } from '@angular/fire/analytics';
65
import { COMMON_CONFIG } from './test-config';
7-
import { take, skip } from 'rxjs/operators';
86

9-
function authTake(auth: Observable<any>, count: number): Observable<any> {
10-
return take.call(auth, 1);
11-
}
127

13-
function authSkip(auth: Observable<any>, count: number): Observable<any> {
14-
return skip.call(auth, 1);
15-
}
16-
17-
const firebaseUser = <User> {
18-
uid: '12345',
19-
providerData: [{ displayName: 'jeffbcrossyface' }]
20-
};
21-
22-
describe('AngularFireAuth', () => {
8+
describe('AngularFireAnalytics', () => {
239
let app: FirebaseApp;
24-
let afAuth: AngularFireAuth;
25-
let authSpy: jasmine.Spy;
26-
let mockAuthState: Subject<User>;
10+
let analytics: AngularFireAnalytics;
2711

2812
beforeEach(() => {
2913
TestBed.configureTestingModule({
3014
imports: [
3115
AngularFireModule.initializeApp(COMMON_CONFIG),
32-
AngularFireAuthModule
16+
AngularFireAnalyticsModule
3317
]
3418
});
35-
inject([FirebaseApp, AngularFireAuth], (app_: FirebaseApp, _auth: AngularFireAuth) => {
19+
inject([FirebaseApp, AngularFireAnalytics], (app_: FirebaseApp, _analytics: AngularFireAnalytics) => {
3620
app = app_;
37-
afAuth = _auth;
21+
analytics = _analytics;
3822
})();
39-
40-
mockAuthState = new Subject<User>();
41-
spyOn(afAuth, 'authState').and.returnValue(mockAuthState);
42-
spyOn(afAuth, 'idToken').and.returnValue(mockAuthState);
43-
afAuth.authState = mockAuthState as Observable<User>;
44-
afAuth.idToken = mockAuthState as Observable<User>;
4523
});
4624

4725
afterEach(done => {
48-
afAuth.auth.app.delete().then(done, done.fail);
49-
});
50-
51-
describe('Zones', () => {
52-
it('should call operators and subscriber in the same zone as when service was initialized', (done) => {
53-
// Initialize the app outside of the zone, to mimick real life behavior.
54-
let ngZone = Zone.current.fork({
55-
name: 'ngZone'
56-
});
57-
ngZone.run(() => {
58-
const subs = [
59-
afAuth.authState.subscribe(user => {
60-
expect(Zone.current.name).toBe('ngZone');
61-
done();
62-
}, done.fail),
63-
afAuth.authState.subscribe(user => {
64-
expect(Zone.current.name).toBe('ngZone');
65-
done();
66-
}, done.fail)
67-
];
68-
mockAuthState.next(firebaseUser);
69-
subs.forEach(s => s.unsubscribe());
70-
});
71-
});
26+
app.delete();
27+
done();
7228
});
7329

7430
it('should be exist', () => {
75-
expect(afAuth instanceof AngularFireAuth).toBe(true);
31+
expect(analytics instanceof AngularFireAnalytics).toBe(true);
7632
});
7733

78-
it('should have the Firebase Auth instance', () => {
79-
expect(afAuth.auth).toBeDefined();
80-
});
81-
82-
it('should have an initialized Firebase app', () => {
83-
expect(afAuth.auth.app).toBeDefined();
84-
expect(afAuth.auth.app).toEqual(app);
85-
});
86-
87-
it('should emit auth updates through authState', (done: any) => {
88-
let count = 0;
89-
90-
// Check that the first value is null and second is the auth user
91-
const subs = afAuth.authState.subscribe(user => {
92-
if (count === 0) {
93-
expect(user).toBe(null!);
94-
count = count + 1;
95-
mockAuthState.next(firebaseUser);
96-
} else {
97-
expect(user).toEqual(firebaseUser);
98-
subs.unsubscribe();
99-
done();
100-
}
101-
}, done, done.fail);
102-
mockAuthState.next(null!);
103-
});
104-
105-
it('should emit auth updates through idToken', (done: any) => {
106-
let count = 0;
107-
108-
// Check that the first value is null and second is the auth user
109-
const subs = afAuth.idToken.subscribe(user => {
110-
if (count === 0) {
111-
expect(user).toBe(null!);
112-
count = count + 1;
113-
mockAuthState.next(firebaseUser);
114-
} else {
115-
expect(user).toEqual(firebaseUser);
116-
subs.unsubscribe();
117-
done();
118-
}
119-
}, done, done.fail);
120-
mockAuthState.next(null!);
34+
it('should have the Firebase Functions instance', () => {
35+
expect(analytics.analytics).toBeDefined();
12136
});
12237

12338
});
12439

12540
const FIREBASE_APP_NAME_TOO = (Math.random() + 1).toString(36).substring(7);
12641

127-
describe('AngularFireAuth with different app', () => {
42+
describe('AngularFireAnalytics with different app', () => {
12843
let app: FirebaseApp;
129-
let afAuth: AngularFireAuth;
44+
let analytics: AngularFireAnalytics;
13045

13146
beforeEach(() => {
13247
TestBed.configureTestingModule({
13348
imports: [
13449
AngularFireModule.initializeApp(COMMON_CONFIG),
135-
AngularFireAuthModule
50+
AngularFireAnalyticsModule
13651
],
13752
providers: [
13853
{ provide: FirebaseNameOrConfigToken, useValue: FIREBASE_APP_NAME_TOO },
139-
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG }
54+
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG },
55+
{ provide: AUTOMATICALLY_SET_CURRENT_SCREEN, useValue: true }
56+
{ provide: AUTOMATICALLY_LOG_SCREEN_VIEWS, useValue: true },
57+
{ provide: ANALYTICS_COLLECTION_ENABLED, useValue: true },
58+
{ provide: AUTOMATICALLY_TRACK_USER_IDENTIFIER, useValue: true },
59+
{ provide: APP_VERSION, useValue: '0.0' },
60+
{ provide: APP_NAME, useValue: 'Test App!' }
14061
]
14162
});
142-
inject([FirebaseApp, AngularFireAuth], (app_: FirebaseApp, _afAuth: AngularFireAuth) => {
63+
inject([FirebaseApp, AngularFireAnalytics], (app_: FirebaseApp, _analytics: AngularFireAnalytics) => {
14364
app = app_;
144-
afAuth = _afAuth;
65+
analytics = _analytics;
14566
})();
14667
});
14768

14869
afterEach(done => {
149-
app.delete().then(done, done.fail);
70+
app.delete();
71+
done();
15072
});
15173

15274
describe('<constructor>', () => {
15375

15476
it('should be an AngularFireAuth type', () => {
155-
expect(afAuth instanceof AngularFireAuth).toEqual(true);
77+
expect(analytics instanceof AngularFireAnalytics).toEqual(true);
15678
});
15779

158-
it('should have an initialized Firebase app', () => {
159-
expect(afAuth.auth.app).toBeDefined();
160-
expect(afAuth.auth.app).toEqual(app);
80+
it('should have the Firebase Functions instance', () => {
81+
expect(analytics.analytics).toBeDefined();
16182
});
16283

163-
it('should have an initialized Firebase app instance member', () => {
164-
expect(afAuth.auth.app.name).toEqual(FIREBASE_APP_NAME_TOO);
165-
});
16684
});
16785

16886
});
Lines changed: 25 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,81 @@
1-
import { User } from 'firebase/app';
2-
import { Observable, Subject } from 'rxjs'
1+
import { ReflectiveInjector, Provider } from '@angular/core';
32
import { TestBed, inject } from '@angular/core/testing';
43
import { FirebaseApp, FirebaseOptionsToken, AngularFireModule, FirebaseNameOrConfigToken } from '@angular/fire';
5-
import { AngularFireAuth, AngularFireAuthModule } from '@angular/fire/auth';
4+
import { AngularFireRemoteConfig, AngularFireRemoteConfigModule, REMOTE_CONFIG_SETTINGS, DEFAULT_CONFIG } from '@angular/fire/remote-config';
65
import { COMMON_CONFIG } from './test-config';
7-
import { take, skip } from 'rxjs/operators';
86

9-
function authTake(auth: Observable<any>, count: number): Observable<any> {
10-
return take.call(auth, 1);
11-
}
12-
13-
function authSkip(auth: Observable<any>, count: number): Observable<any> {
14-
return skip.call(auth, 1);
15-
}
16-
17-
const firebaseUser = <User> {
18-
uid: '12345',
19-
providerData: [{ displayName: 'jeffbcrossyface' }]
20-
};
21-
22-
describe('AngularFireAuth', () => {
7+
describe('AngularFireRemoteConfig', () => {
238
let app: FirebaseApp;
24-
let afAuth: AngularFireAuth;
25-
let authSpy: jasmine.Spy;
26-
let mockAuthState: Subject<User>;
9+
let rc: AngularFireRemoteConfig;
2710

2811
beforeEach(() => {
2912
TestBed.configureTestingModule({
3013
imports: [
3114
AngularFireModule.initializeApp(COMMON_CONFIG),
32-
AngularFireAuthModule
15+
AngularFireRemoteConfigModule
3316
]
3417
});
35-
inject([FirebaseApp, AngularFireAuth], (app_: FirebaseApp, _auth: AngularFireAuth) => {
18+
inject([FirebaseApp, AngularFireRemoteConfig], (app_: FirebaseApp, _rc: AngularFireRemoteConfig) => {
3619
app = app_;
37-
afAuth = _auth;
20+
rc = _rc;
3821
})();
39-
40-
mockAuthState = new Subject<User>();
41-
spyOn(afAuth, 'authState').and.returnValue(mockAuthState);
42-
spyOn(afAuth, 'idToken').and.returnValue(mockAuthState);
43-
afAuth.authState = mockAuthState as Observable<User>;
44-
afAuth.idToken = mockAuthState as Observable<User>;
4522
});
4623

4724
afterEach(done => {
48-
afAuth.auth.app.delete().then(done, done.fail);
49-
});
50-
51-
describe('Zones', () => {
52-
it('should call operators and subscriber in the same zone as when service was initialized', (done) => {
53-
// Initialize the app outside of the zone, to mimick real life behavior.
54-
let ngZone = Zone.current.fork({
55-
name: 'ngZone'
56-
});
57-
ngZone.run(() => {
58-
const subs = [
59-
afAuth.authState.subscribe(user => {
60-
expect(Zone.current.name).toBe('ngZone');
61-
done();
62-
}, done.fail),
63-
afAuth.authState.subscribe(user => {
64-
expect(Zone.current.name).toBe('ngZone');
65-
done();
66-
}, done.fail)
67-
];
68-
mockAuthState.next(firebaseUser);
69-
subs.forEach(s => s.unsubscribe());
70-
});
71-
});
25+
app.delete();
26+
done();
7227
});
7328

7429
it('should be exist', () => {
75-
expect(afAuth instanceof AngularFireAuth).toBe(true);
76-
});
77-
78-
it('should have the Firebase Auth instance', () => {
79-
expect(afAuth.auth).toBeDefined();
80-
});
81-
82-
it('should have an initialized Firebase app', () => {
83-
expect(afAuth.auth.app).toBeDefined();
84-
expect(afAuth.auth.app).toEqual(app);
85-
});
86-
87-
it('should emit auth updates through authState', (done: any) => {
88-
let count = 0;
89-
90-
// Check that the first value is null and second is the auth user
91-
const subs = afAuth.authState.subscribe(user => {
92-
if (count === 0) {
93-
expect(user).toBe(null!);
94-
count = count + 1;
95-
mockAuthState.next(firebaseUser);
96-
} else {
97-
expect(user).toEqual(firebaseUser);
98-
subs.unsubscribe();
99-
done();
100-
}
101-
}, done, done.fail);
102-
mockAuthState.next(null!);
30+
expect(rc instanceof AngularFireRemoteConfig).toBe(true);
10331
});
10432

105-
it('should emit auth updates through idToken', (done: any) => {
106-
let count = 0;
107-
108-
// Check that the first value is null and second is the auth user
109-
const subs = afAuth.idToken.subscribe(user => {
110-
if (count === 0) {
111-
expect(user).toBe(null!);
112-
count = count + 1;
113-
mockAuthState.next(firebaseUser);
114-
} else {
115-
expect(user).toEqual(firebaseUser);
116-
subs.unsubscribe();
117-
done();
118-
}
119-
}, done, done.fail);
120-
mockAuthState.next(null!);
33+
it('should have the Firebase Functions instance', () => {
34+
expect(rc.remoteConfig).toBeDefined();
12135
});
12236

12337
});
12438

12539
const FIREBASE_APP_NAME_TOO = (Math.random() + 1).toString(36).substring(7);
12640

127-
describe('AngularFireAuth with different app', () => {
41+
describe('AngularFireRemoteConfig with different app', () => {
12842
let app: FirebaseApp;
129-
let afAuth: AngularFireAuth;
43+
let rc: AngularFireRemoteConfig;
13044

13145
beforeEach(() => {
13246
TestBed.configureTestingModule({
13347
imports: [
13448
AngularFireModule.initializeApp(COMMON_CONFIG),
135-
AngularFireAuthModule
49+
AngularFireRemoteConfigModule
13650
],
13751
providers: [
13852
{ provide: FirebaseNameOrConfigToken, useValue: FIREBASE_APP_NAME_TOO },
139-
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG }
53+
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG },
54+
{ provide: REMOTE_CONFIG_SETTINGS, useValue: {} },
55+
{ provide: DEFAULT_CONFIG, useValue: {} }
14056
]
14157
});
142-
inject([FirebaseApp, AngularFireAuth], (app_: FirebaseApp, _afAuth: AngularFireAuth) => {
58+
inject([FirebaseApp, AngularFireRemoteConfig], (app_: FirebaseApp, _rc: AngularFireRemoteConfig) => {
14359
app = app_;
144-
afAuth = _afAuth;
60+
rc = _rc;
14561
})();
14662
});
14763

14864
afterEach(done => {
149-
app.delete().then(done, done.fail);
65+
app.delete();
66+
done();
15067
});
15168

15269
describe('<constructor>', () => {
15370

15471
it('should be an AngularFireAuth type', () => {
155-
expect(afAuth instanceof AngularFireAuth).toEqual(true);
72+
expect(rc instanceof AngularFireRemoteConfig).toEqual(true);
15673
});
15774

158-
it('should have an initialized Firebase app', () => {
159-
expect(afAuth.auth.app).toBeDefined();
160-
expect(afAuth.auth.app).toEqual(app);
75+
it('should have the Firebase Functions instance', () => {
76+
expect(rc.remoteConfig).toBeDefined();
16177
});
16278

163-
it('should have an initialized Firebase app instance member', () => {
164-
expect(afAuth.auth.app.name).toEqual(FIREBASE_APP_NAME_TOO);
165-
});
16679
});
16780

16881
});

0 commit comments

Comments
 (0)