forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonClick.test.ts
More file actions
168 lines (138 loc) · 5.03 KB
/
Copy pathbuttonClick.test.ts
File metadata and controls
168 lines (138 loc) · 5.03 KB
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
import F from 'lodash/fp';
import { fetchResults } from '../micro';
import { pageSetup } from './helpers';
const loadUrlAndWait = async (url: string) => {
await browser.url(url);
await browser.waitUntil(async () => (await $('#init').getText()) === 'true', {
timeout: 5000,
timeoutMsg: 'expected init after 5s',
});
};
describe('Snowplow Micro integration', () => {
const browserName = 'browserName' in browser.capabilities && browser.capabilities.browserName;
if (browserName === 'internet explorer') {
fit('Skip IE', () => {});
return;
}
let eventMethods = ['get', 'post', 'beacon'];
let log: Array<any> = [];
let testIdentifier = '';
const logContains = (ev: unknown) => F.some(F.isMatch(ev as object), log);
type Button = {
label: string;
id?: string;
classes?: Array<string>;
name?: string;
};
const makeEvent = (button: Button, method: string) => {
return {
event: {
event: 'unstruct',
app_id: 'button-click-tracking-' + testIdentifier,
page_url: `http://snowplow-js-tracker.local:8080/button-click-tracking.html?eventMethod=${method}`,
unstruct_event: {
data: {
schema: 'iglu:com.snowplowanalytics.snowplow/button_click/jsonschema/1-0-0',
data: button,
},
},
},
};
};
const logContainsButtonClick = (event: any) => {
expect(logContains(event)).toBe(true);
};
const nButtons = 7;
beforeAll(async () => {
testIdentifier = await pageSetup();
const runClicks = async (method: string) => {
await loadUrlAndWait('/button-click-tracking.html?eventMethod=' + method);
for (let i = 1; i < nButtons; i++) {
await (await $(`#button${i}`)).click();
await browser.pause(50);
}
// Dynamic button
await (await $('#addDynamic')).click();
await browser.pause(500);
await (await $('#button7')).click();
await browser.pause(500);
// Nested child
await (await $('#button-child')).click();
await browser.pause(500);
// ShadowDOM
await (await $('#shadow')).shadow$('button').click();
await browser.pause(500);
// Disable/enable
await (await $('#disable')).click();
await browser.pause(500);
await (await $('#disabled-click')).click();
await browser.pause(500);
await (await $('#enable')).click();
await browser.pause(500);
await (await $('#enabled-click')).click();
await browser.pause(500);
await (await $('#set-multiple-configs')).click();
await browser.pause(500);
await (await $('#final-config')).click();
await browser.pause(500);
};
for (let method of eventMethods) {
await runClicks(method);
await browser.pause(6000);
}
log = await browser.call(async () => await fetchResults());
});
eventMethods.forEach((method) => {
it('should get button1', () => {
const ev = makeEvent({ id: 'button1', label: 'TestButton' }, method);
logContainsButtonClick(ev);
});
it('should get button2', () => {
const ev = makeEvent({ id: 'button2', label: 'TestButtonWithClass', classes: ['test-class'] }, method);
logContainsButtonClick(ev);
});
it('should get button3', () => {
const ev = makeEvent(
{ id: 'button3', label: 'TestButtonWithClasses', classes: ['test-class', 'test-class2'] },
method
);
logContainsButtonClick(ev);
});
it('should get button4', () => {
const ev = makeEvent({ id: 'button4', label: 'TestWithName', name: 'testName' }, method);
logContainsButtonClick(ev);
});
it('should get button5', () => {
const ev = makeEvent({ id: 'button5', label: 'DataLabel' }, method);
logContainsButtonClick(ev);
});
it('should get button6', () => {
const ev = makeEvent({ id: 'button6', label: 'TestInputButton' }, method);
logContainsButtonClick(ev);
});
it('should get button7 after it is added dynamically', async () => {
const ev = makeEvent({ id: 'button7', label: 'TestDynamicButton-' + method }, method);
logContainsButtonClick(ev);
});
it('should get button when click was on a child element', async () => {
const ev = makeEvent({ label: 'TestChildren' }, method);
logContainsButtonClick(ev);
});
it('should get button when click was in a shadow dom', async () => {
const ev = makeEvent({ label: 'Shadow' }, method);
logContainsButtonClick(ev);
});
it('should not get disabled-click', () => {
const ev = makeEvent({ id: 'disabled-click', label: 'DisabledClick' }, method);
expect(logContains(ev)).toBe(false);
});
it('should get enabled-click', () => {
const ev = makeEvent({ id: 'enabled-click', label: 'EnabledClick' }, method);
logContainsButtonClick(ev);
});
it('should get `final-config` as it is the last config set', () => {
const ev = makeEvent({ id: 'final-config', classes: ['final-config'], label: 'Final Config' }, method);
logContainsButtonClick(ev);
});
});
});