forked from angulartics/angulartics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.spec.ts
81 lines (72 loc) · 2.9 KB
/
launch.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { fakeAsync, inject, ComponentFixture, TestBed } from '@angular/core/testing';
import { Angulartics2 } from '../../angulartics2-core';
import { advance, createRoot, RootCmp, TestModule } from '../../test.mocks';
import { Angulartics2LaunchByAdobe } from './launch';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
declare var window: any;
describe('Angulartics2LaunchByAdobe', () => {
let _satellite: any;
let fixture: ComponentFixture<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [TestModule],
providers: [Angulartics2LaunchByAdobe],
});
window.console = jasmine.createSpyObj('console', ['warn', 'log']);
});
describe('on init', () => {
beforeEach(() => {
window.console = jasmine.createSpyObj('console', ['warn', 'log']);
window._satellite = undefined;
});
it('should complain if Launch is not found', fakeAsync(
inject([Angulartics2LaunchByAdobe], (angulartics2Launch: Angulartics2LaunchByAdobe) => {
angulartics2Launch.startTracking();
fixture = createRoot(RootCmp);
advance(fixture);
expect(console.warn).toHaveBeenCalled();
}),
));
});
describe('while active', () => {
beforeEach(() => {
window._satellite = _satellite = {};
_satellite.track = (eventID: string, payload: any) => {
_satellite.output = {
eventID,
payload,
};
};
_satellite.output = null;
const provider: Angulartics2LaunchByAdobe = TestBed.inject(Angulartics2LaunchByAdobe);
provider.startTracking();
});
it('should track pages', fakeAsync(
inject([Angulartics2, Angulartics2LaunchByAdobe], (angulartics2: Angulartics2) => {
fixture = createRoot(RootCmp);
angulartics2.pageTrack.next({ path: '/abc' });
advance(fixture);
expect(Object.keys(_satellite.output)).toEqual(['eventID', 'payload']);
expect(_satellite.output.eventID).toEqual('pageTrack');
expect(Object.keys(_satellite.output.payload)).toEqual(['path']);
expect(_satellite.output.payload.path).toEqual('/abc');
}),
));
it('should track events', fakeAsync(
inject([Angulartics2, Angulartics2LaunchByAdobe], (angulartics2: Angulartics2) => {
fixture = createRoot(RootCmp);
angulartics2.eventTrack.next({
action: 'do',
properties: { category: 'cat' },
});
advance(fixture);
expect(Object.keys(_satellite.output)).toEqual(['eventID', 'payload']);
expect(_satellite.output.eventID).toEqual('eventTrack');
expect(Object.keys(_satellite.output.payload)).toEqual(['action', 'eventProperties']);
expect(_satellite.output.payload.action).toEqual('do');
expect(Object.keys(_satellite.output.payload.eventProperties)).toEqual(['category']);
expect(_satellite.output.payload.eventProperties.category).toEqual('cat');
}),
));
});
});