-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathindex.test.js
135 lines (115 loc) · 3.4 KB
/
index.test.js
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
'use strict';
var Analytics = require('@segment/analytics.js-core').constructor;
var integration = require('@segment/analytics.js-integration');
var sandbox = require('@segment/clear-env');
var tester = require('@segment/analytics.js-integration-tester');
var Appcues = require('../lib/').Integration;
describe('Appcues', function() {
var appcues;
var analytics;
var options = {
appcuesId: '1663',
domain: '//fast.appcues.net/'
};
// Disable AMD for these browser tests.
var _define = window.define;
beforeEach(function() {
analytics = new Analytics();
appcues = new Appcues(options);
analytics.use(Appcues);
analytics.use(tester);
analytics.add(appcues);
window.define = undefined;
});
afterEach(function() {
analytics.restore();
analytics.reset();
sandbox();
window.define = _define;
});
after(function() {
appcues.reset();
});
it('should have the right settings', function() {
analytics.compare(
Appcues,
integration('Appcues')
.global('Appcues')
.option('appcuesId', '')
.option('domain', '')
);
});
describe('before loading', function() {
beforeEach(function() {
analytics.stub(appcues, 'load');
});
afterEach(function() {
appcues.reset();
});
describe('#initialize', function() {
it('should call #load', function() {
analytics.initialize();
analytics.called(appcues.load);
});
});
});
describe('loading', function() {
it('should load', function(done) {
analytics.load(appcues, done);
});
});
describe('after loading', function() {
beforeEach(function(done) {
analytics.once('ready', done);
analytics.initialize();
});
describe('#page', function() {
beforeEach(function() {
analytics.stub(window.Appcues, 'page');
});
it('should call Appcues.page', function() {
analytics.page('some page', { someAttr: true });
analytics.called(window.Appcues.page, 'some page');
// No way to assert an argument "match", and analytics.page includes
// other properties automatically, so manually checking the second
// arg to Appcues.page includes the `someAttr` value.
analytics.assert(window.Appcues.page.args[0][1].someAttr === true);
});
});
describe('#track', function() {
beforeEach(function() {
analytics.stub(window.Appcues, 'track');
});
it('should send name and attributes', function() {
analytics.track('some event', { someAttr: true });
analytics.called(window.Appcues.track, 'some event', {
someAttr: true
});
});
});
describe('#identify', function() {
beforeEach(function() {
analytics.stub(window.Appcues, 'identify');
});
it('should send and id and traits', function() {
analytics.identify('id', { trait: true });
analytics.called(window.Appcues.identify, 'id', {
id: 'id',
trait: true
});
});
});
describe('#group', function() {
beforeEach(function() {
analytics.stub(window.Appcues, 'group');
});
it('should send an id and group name', function() {
analytics.group('id', { groupName: 'group-1' });
analytics.called(window.Appcues.group, 'id', {
groupName: 'group-1',
id: 'id'
});
});
});
});
});