-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathmixpanel.spec.ts
169 lines (154 loc) · 4.91 KB
/
mixpanel.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { fakeAsync, inject, ComponentFixture, TestBed } from '@angular/core/testing';
import { advance, createRoot, RootCmp, TestModule } from '../../test.mocks';
import { Angulartics2 } from '../../angulartics2-core';
import { Angulartics2Mixpanel } from './mixpanel';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
declare var window: any;
describe('Angulartics2Mixpanel', () => {
let fixture: ComponentFixture<any>;
let mixpanel: any;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [TestModule],
providers: [Angulartics2Mixpanel],
});
window.mixpanel = mixpanel = {
track: jasmine.createSpy('track'),
identify: jasmine.createSpy('identify'),
people: {
set: jasmine.createSpy('people.set'),
set_once: jasmine.createSpy('people.set_once'),
},
register: jasmine.createSpy('register'),
register_once: jasmine.createSpy('register_once'),
alias: jasmine.createSpy('alias'),
};
const provider: Angulartics2Mixpanel = TestBed.inject(Angulartics2Mixpanel);
provider.startTracking();
});
it('should track pages', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.pageTrack.next({ path: '/abc' });
advance(fixture);
expect(mixpanel.track).toHaveBeenCalledWith('Page Viewed', {
page: '/abc',
});
},
),
));
it('should track events', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.eventTrack.next({
action: 'do',
properties: { category: 'cat' },
});
advance(fixture);
expect(mixpanel.track).toHaveBeenCalledWith('do', { category: 'cat' });
},
),
));
it('should set username', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.setUsername.next('testUser');
advance(fixture);
expect(mixpanel.identify).toHaveBeenCalledWith('testUser');
},
),
));
it('should set user properties', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.setUserProperties.next({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
advance(fixture);
expect(mixpanel.people.set).toHaveBeenCalledWith({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
},
),
));
it('should set user properties once', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.setUserPropertiesOnce.next({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
advance(fixture);
expect(mixpanel.people.set_once).toHaveBeenCalledWith({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
},
),
));
it('should set super properties', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.setSuperProperties.next({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
advance(fixture);
expect(mixpanel.register).toHaveBeenCalledWith({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
},
),
));
it('should set super properties once', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.setSuperPropertiesOnce.next({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
advance(fixture);
expect(mixpanel.register_once).toHaveBeenCalledWith({
userId: '1',
firstName: 'John',
lastName: 'Doe',
});
},
),
));
it('should set alias', fakeAsync(
inject(
[Angulartics2, Angulartics2Mixpanel],
(angulartics2: Angulartics2, angulartics2Mixpanel: Angulartics2Mixpanel) => {
fixture = createRoot(RootCmp);
angulartics2.setAlias.next('testAlias');
advance(fixture);
expect(mixpanel.alias).toHaveBeenCalledWith('testAlias');
},
),
));
});