-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathwoopra.spec.ts
81 lines (72 loc) · 2.29 KB
/
woopra.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 { Angulartics2Woopra } from './woopra';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
declare var window: any;
describe('Angulartics2Woopra', () => {
let fixture: ComponentFixture<any>;
let woopra: any;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [TestModule],
providers: [Angulartics2Woopra],
});
window.woopra = woopra = {
track: jasmine.createSpy('track'),
identify: jasmine.createSpy('identify'),
};
const provider: Angulartics2Woopra = TestBed.inject(Angulartics2Woopra);
provider.startTracking();
});
it('should track pages', fakeAsync(
inject(
[Angulartics2, Angulartics2Woopra],
(angulartics2: Angulartics2, angulartics2Woopra: Angulartics2Woopra) => {
fixture = createRoot(RootCmp);
angulartics2.pageTrack.next({ path: '/abc' });
advance(fixture);
expect(woopra.track).toHaveBeenCalledWith('pv', { url: '/abc' });
},
),
));
it('should track events', fakeAsync(
inject(
[Angulartics2, Angulartics2Woopra],
(angulartics2: Angulartics2, angulartics2Woopra: Angulartics2Woopra) => {
fixture = createRoot(RootCmp);
angulartics2.eventTrack.next({
action: 'payment',
properties: {
amount: '49.95',
currency: 'USD',
},
});
advance(fixture);
expect(woopra.track).toHaveBeenCalledWith('payment', {
amount: '49.95',
currency: 'USD',
});
},
),
));
it('should set user properties', fakeAsync(
inject(
[Angulartics2, Angulartics2Woopra],
(angulartics2: Angulartics2, angulartics2Woopra: Angulartics2Woopra) => {
fixture = createRoot(RootCmp);
angulartics2.setUserProperties.next({
email: '[email protected]',
name: 'John Doe',
company: 'Test Co',
});
advance(fixture);
expect(woopra.identify).toHaveBeenCalledWith({
email: '[email protected]',
name: 'John Doe',
company: 'Test Co',
});
},
),
));
});