@availity/analytics-core 3.1.8 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -3
- package/dist/index.d.ts +80 -0
- package/dist/index.js +289 -0
- package/dist/index.mjs +260 -0
- package/jest.config.js +7 -0
- package/package.json +15 -13
- package/project.json +39 -0
- package/{types → src}/analytics.d.ts +14 -2
- package/{types → src}/dma.d.ts +0 -0
- package/{types → src}/index.d.ts +0 -0
- package/{types → src}/plugin.d.ts +0 -0
- package/{types → src}/splunk.d.ts +0 -0
- package/src/tests/analytics.test.ts +187 -0
- package/src/tests/dma.test.ts +31 -0
- package/src/tests/plugin.test.ts +23 -0
- package/src/tests/splunk.test.ts +68 -0
- package/src/tests/util.test.ts +52 -0
- package/src/util.d.ts +14 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
- package/LICENSE +0 -21
- package/lib/analytics.js +0 -291
- package/lib/dma.js +0 -99
- package/lib/index.js +0 -39
- package/lib/plugin.js +0 -36
- package/lib/splunk.js +0 -52
- package/lib/util.js +0 -79
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/analytics-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Analytics base configuration for sdk-js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"availity",
|
|
@@ -17,24 +17,26 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"author": "Kasey Powers <kasey.powers@availity.com>",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
20
|
+
"browser": "./dist/index.js",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
23
24
|
"scripts": {
|
|
24
|
-
"build": "
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"build": "tsup src/index.js --format esm,cjs --dts",
|
|
26
|
+
"dev": "tsup src/index.js --format esm,cjs --watch --dts",
|
|
27
|
+
"clean": "rm -rf node_modules && rm -rf dist",
|
|
28
|
+
"bundlesize": "bundlesize",
|
|
29
|
+
"publish": "yarn npm publish --tolerate-republish --access public"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
29
|
-
"@babel/runtime": "^7.16.5",
|
|
30
|
-
"core-js": "^3.12.1",
|
|
31
32
|
"yup": "^0.32.9"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@availity/api-axios": "
|
|
35
|
+
"@availity/api-axios": "7.0.2",
|
|
36
|
+
"tsup": "^5.12.8",
|
|
37
|
+
"typescript": "^4.6.4"
|
|
35
38
|
},
|
|
36
39
|
"publishConfig": {
|
|
37
40
|
"access": "public"
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": "packages/analytics-core",
|
|
3
|
+
"projectType": "library",
|
|
4
|
+
"targets": {
|
|
5
|
+
"test": {
|
|
6
|
+
"executor": "@nrwl/jest:jest",
|
|
7
|
+
"outputs": ["coverage/analytics-core"],
|
|
8
|
+
"options": {
|
|
9
|
+
"jestConfig": "packages/analytics-core/jest.config.js",
|
|
10
|
+
"passWithNoTests": true
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"version": {
|
|
14
|
+
"executor": "@jscutlery/semver:version",
|
|
15
|
+
"options": {
|
|
16
|
+
"preset": "angular",
|
|
17
|
+
"commitMessageFormat": "chore(${projectName}): release version ${version} [skip ci]",
|
|
18
|
+
"tagPrefix": "@availity/${projectName}@",
|
|
19
|
+
"baseBranch": "master"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"lint": {
|
|
23
|
+
"executor": "@nrwl/linter:eslint",
|
|
24
|
+
"options": {
|
|
25
|
+
"eslintConfig": ".eslintrc.yaml",
|
|
26
|
+
"lintFilePatterns": ["packages/analytics-core/**/*.{js,ts}"],
|
|
27
|
+
"silent": false,
|
|
28
|
+
"fix": false,
|
|
29
|
+
"cache": true,
|
|
30
|
+
"cacheLocation": "./node_modules/.cache/analytics-core/.eslintcache",
|
|
31
|
+
"maxWarnings": -1,
|
|
32
|
+
"quiet": false,
|
|
33
|
+
"noEslintrc": false,
|
|
34
|
+
"hasTypeAwareRules": true,
|
|
35
|
+
"cacheStrategy": "metadata"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
declare class AvAnalytics {
|
|
4
|
+
plugins: any[];
|
|
5
|
+
|
|
6
|
+
attributePrefix: string;
|
|
7
|
+
|
|
8
|
+
recursive: boolean;
|
|
9
|
+
|
|
10
|
+
pageTracking: boolean;
|
|
11
|
+
|
|
12
|
+
isPageTracking: boolean;
|
|
13
|
+
|
|
14
|
+
hasInit: boolean;
|
|
15
|
+
|
|
4
16
|
constructor(
|
|
5
|
-
plugins: any[],
|
|
17
|
+
plugins: any | any[],
|
|
6
18
|
promise?: PromiseConstructor,
|
|
7
19
|
pageTracking?: boolean,
|
|
8
20
|
autoTrack?: boolean,
|
|
@@ -25,7 +37,7 @@ declare class AvAnalytics {
|
|
|
25
37
|
|
|
26
38
|
init(): void;
|
|
27
39
|
|
|
28
|
-
setPageTracking(value
|
|
40
|
+
setPageTracking(value?: any): void;
|
|
29
41
|
|
|
30
42
|
trackEvent(properties: any): Promise<any[]>;
|
|
31
43
|
|
package/{types → src}/dma.d.ts
RENAMED
|
File without changes
|
package/{types → src}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { AvAnalytics } from '..';
|
|
2
|
+
|
|
3
|
+
type MockPlugin = {
|
|
4
|
+
isEnabled: jest.Mock;
|
|
5
|
+
init: jest.Mock | string;
|
|
6
|
+
trackEvent: jest.Mock | string;
|
|
7
|
+
trackPageView: jest.Mock | string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function makePlugin() {
|
|
11
|
+
return {
|
|
12
|
+
isEnabled: jest.fn(() => true),
|
|
13
|
+
init: jest.fn(),
|
|
14
|
+
trackEvent: jest.fn(),
|
|
15
|
+
trackPageView: jest.fn(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('AvAnalytics', () => {
|
|
20
|
+
let mockAvAnalytics: AvAnalytics;
|
|
21
|
+
|
|
22
|
+
test('AvAnalytics should be defined', () => {
|
|
23
|
+
const plugins = [makePlugin()];
|
|
24
|
+
mockAvAnalytics = new AvAnalytics(plugins, Promise, true);
|
|
25
|
+
expect(mockAvAnalytics).toBeDefined();
|
|
26
|
+
mockAvAnalytics = new AvAnalytics(plugins, Promise);
|
|
27
|
+
expect(mockAvAnalytics).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('AvAnalytics should throw error without plugins or Promise', () => {
|
|
31
|
+
expect(() => {
|
|
32
|
+
// @ts-expect-error: allow error for testing
|
|
33
|
+
mockAvAnalytics = new AvAnalytics();
|
|
34
|
+
}).toThrow('[plugins] and [promise] must be defined');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('AvAnalytics should cast plugins to an array', () => {
|
|
38
|
+
const plugin = makePlugin();
|
|
39
|
+
mockAvAnalytics = new AvAnalytics(plugin, Promise);
|
|
40
|
+
expect(mockAvAnalytics.plugins).toEqual([plugin]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('AvAnalytics should use custom configs', () => {
|
|
44
|
+
mockAvAnalytics = new AvAnalytics([], Promise, true, true, {
|
|
45
|
+
attributePrefix: 'some-attr',
|
|
46
|
+
recursive: true,
|
|
47
|
+
});
|
|
48
|
+
expect(mockAvAnalytics.attributePrefix).toBe('some-attr');
|
|
49
|
+
expect(mockAvAnalytics.recursive).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('setPageTracking', () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
const plugins = [makePlugin()];
|
|
55
|
+
mockAvAnalytics = new AvAnalytics(plugins, Promise);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('passing in argument should change value of pageTracking', () => {
|
|
59
|
+
const initialTracking = true;
|
|
60
|
+
const setPageTracking = !initialTracking;
|
|
61
|
+
|
|
62
|
+
mockAvAnalytics.pageTracking = initialTracking;
|
|
63
|
+
|
|
64
|
+
mockAvAnalytics.setPageTracking(setPageTracking);
|
|
65
|
+
expect(mockAvAnalytics.pageTracking).toBe(setPageTracking);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('with functions defined, will only call if pageTracking is opposite isPageTracking', () => {
|
|
69
|
+
mockAvAnalytics.startPageTracking = jest.fn();
|
|
70
|
+
mockAvAnalytics.stopPageTracking = jest.fn();
|
|
71
|
+
|
|
72
|
+
let testValue = true;
|
|
73
|
+
mockAvAnalytics.pageTracking = testValue;
|
|
74
|
+
mockAvAnalytics.isPageTracking = testValue;
|
|
75
|
+
mockAvAnalytics.setPageTracking();
|
|
76
|
+
expect(mockAvAnalytics.startPageTracking).not.toHaveBeenCalled();
|
|
77
|
+
expect(mockAvAnalytics.stopPageTracking).not.toHaveBeenCalled();
|
|
78
|
+
|
|
79
|
+
testValue = false;
|
|
80
|
+
mockAvAnalytics.pageTracking = testValue;
|
|
81
|
+
mockAvAnalytics.isPageTracking = testValue;
|
|
82
|
+
mockAvAnalytics.setPageTracking();
|
|
83
|
+
expect(mockAvAnalytics.startPageTracking).not.toHaveBeenCalled();
|
|
84
|
+
expect(mockAvAnalytics.stopPageTracking).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('with functions defined, will start/stop tracking based on pageTracking value', () => {
|
|
88
|
+
mockAvAnalytics.startPageTracking = jest.fn();
|
|
89
|
+
mockAvAnalytics.stopPageTracking = jest.fn();
|
|
90
|
+
|
|
91
|
+
let testValue = true;
|
|
92
|
+
mockAvAnalytics.pageTracking = testValue;
|
|
93
|
+
mockAvAnalytics.isPageTracking = !testValue;
|
|
94
|
+
|
|
95
|
+
mockAvAnalytics.setPageTracking();
|
|
96
|
+
expect(mockAvAnalytics.startPageTracking).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(mockAvAnalytics.stopPageTracking).toHaveBeenCalledTimes(0);
|
|
98
|
+
expect(mockAvAnalytics.isPageTracking).toBe(testValue);
|
|
99
|
+
|
|
100
|
+
testValue = false;
|
|
101
|
+
mockAvAnalytics.pageTracking = testValue;
|
|
102
|
+
mockAvAnalytics.isPageTracking = !testValue;
|
|
103
|
+
|
|
104
|
+
mockAvAnalytics.setPageTracking();
|
|
105
|
+
expect(mockAvAnalytics.startPageTracking).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(mockAvAnalytics.stopPageTracking).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(mockAvAnalytics.isPageTracking).toBe(testValue);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('init', () => {
|
|
112
|
+
let plugins: [MockPlugin, MockPlugin];
|
|
113
|
+
beforeEach(() => {
|
|
114
|
+
plugins = [makePlugin(), makePlugin()];
|
|
115
|
+
mockAvAnalytics = new AvAnalytics(plugins, Promise);
|
|
116
|
+
mockAvAnalytics.setPageTracking = jest.fn();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('should call setPageTracking', () => {
|
|
120
|
+
mockAvAnalytics.init();
|
|
121
|
+
expect(mockAvAnalytics.setPageTracking).toHaveBeenCalled();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('should check each plugin is enabled', () => {
|
|
125
|
+
mockAvAnalytics.init();
|
|
126
|
+
for (const plugin of plugins) {
|
|
127
|
+
expect(plugin.isEnabled).toHaveBeenCalled();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('should call init on enabled plugins', () => {
|
|
132
|
+
mockAvAnalytics.init();
|
|
133
|
+
for (const plugin of plugins) {
|
|
134
|
+
expect(plugin.init).toHaveBeenCalledTimes(1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
plugins[0].isEnabled.mockImplementationOnce(() => false);
|
|
138
|
+
mockAvAnalytics.init();
|
|
139
|
+
expect(plugins[0].init).toHaveBeenCalledTimes(1);
|
|
140
|
+
expect(plugins[1].init).toHaveBeenCalledTimes(2);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('should skip plugins without init function', () => {
|
|
144
|
+
plugins[1].init = 'test';
|
|
145
|
+
mockAvAnalytics.init();
|
|
146
|
+
expect(plugins[0].init).toHaveBeenCalled();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('event tracking', () => {
|
|
151
|
+
let plugins: [MockPlugin, MockPlugin, MockPlugin];
|
|
152
|
+
beforeEach(() => {
|
|
153
|
+
plugins = [makePlugin(), makePlugin(), makePlugin()];
|
|
154
|
+
|
|
155
|
+
mockAvAnalytics = new AvAnalytics(plugins, Promise);
|
|
156
|
+
|
|
157
|
+
plugins[0].isEnabled.mockImplementation(() => false);
|
|
158
|
+
plugins[1].trackEvent = 'test';
|
|
159
|
+
plugins[2].trackPageView = 'test';
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('trackEvent should call trackEvent on enabled plugins with properties', async () => {
|
|
163
|
+
const mockProperties = {};
|
|
164
|
+
await mockAvAnalytics.trackEvent(mockProperties);
|
|
165
|
+
|
|
166
|
+
expect(plugins[0].trackEvent).not.toHaveBeenCalled();
|
|
167
|
+
expect(plugins[2].trackEvent).toHaveBeenCalledWith(mockProperties);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('trackEvent should call trackEvent on enabled plugins with url', async () => {
|
|
171
|
+
const mockProperties: { url?: string } = {};
|
|
172
|
+
await mockAvAnalytics.trackEvent(mockProperties);
|
|
173
|
+
|
|
174
|
+
expect(plugins[0].trackEvent).not.toHaveBeenCalled();
|
|
175
|
+
expect(mockProperties.url).toBeDefined();
|
|
176
|
+
expect(plugins[2].trackEvent).toHaveBeenCalledWith(mockProperties);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('trackPageView should call trackPageView on enabled plugins with properties', async () => {
|
|
180
|
+
const mockUrl = 'testProperties';
|
|
181
|
+
await mockAvAnalytics.trackPageView(mockUrl);
|
|
182
|
+
|
|
183
|
+
expect(plugins[0].trackPageView).not.toHaveBeenCalled();
|
|
184
|
+
expect(plugins[1].trackPageView).toHaveBeenCalledWith(mockUrl);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { avLogMessagesApiV2 } from '@availity/api-axios';
|
|
2
|
+
import { AvDmaAnalytics } from '..';
|
|
3
|
+
|
|
4
|
+
jest.mock('@availity/api-axios');
|
|
5
|
+
|
|
6
|
+
describe('AvSplunkAnalytics', () => {
|
|
7
|
+
let mockAvSplunkAnalytics: AvDmaAnalytics;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
avLogMessagesApiV2.sendBeacon = jest.fn();
|
|
11
|
+
// avLogMessagesApiV2.info = jest.fn;
|
|
12
|
+
mockAvSplunkAnalytics = new AvDmaAnalytics(avLogMessagesApiV2);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('AvSplunkAnalytics should be defined', () => {
|
|
16
|
+
expect(mockAvSplunkAnalytics).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('trackEvent should call AvLogMessages.send', () => {
|
|
20
|
+
const level = 'info';
|
|
21
|
+
mockAvSplunkAnalytics.trackEvent({ level, label: 'test' });
|
|
22
|
+
expect(avLogMessagesApiV2.info).toHaveBeenCalledTimes(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('trackEvent should not allow unknown keys', () => {
|
|
26
|
+
const level = 'info';
|
|
27
|
+
expect(() => {
|
|
28
|
+
mockAvSplunkAnalytics.trackEvent({ level, test: 'test' });
|
|
29
|
+
}).toThrow();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AvAnalyticsPlugin } from '..';
|
|
2
|
+
|
|
3
|
+
describe('AvAnalyticsPlugin', () => {
|
|
4
|
+
let mockPlugin: AvAnalyticsPlugin;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
mockPlugin = new AvAnalyticsPlugin();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('AvAnalyticsPlugin should be defined', () => {
|
|
11
|
+
expect(mockPlugin).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should default enabled to true', () => {
|
|
15
|
+
expect(mockPlugin.isEnabled()).toBe(true);
|
|
16
|
+
mockPlugin = new AvAnalyticsPlugin(false);
|
|
17
|
+
expect(mockPlugin.isEnabled()).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('isEnabled should return enabled value', () => {
|
|
21
|
+
expect(mockPlugin.isEnabled()).toBe(mockPlugin.isEnabled());
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AvSplunkAnalytics } from '..';
|
|
2
|
+
|
|
3
|
+
describe('AvSplunkAnalytics', () => {
|
|
4
|
+
let mockLog: { info: () => void; test: () => void };
|
|
5
|
+
let mockAvSplunkAnalytics: AvSplunkAnalytics;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
mockLog = {
|
|
9
|
+
info: jest.fn(),
|
|
10
|
+
test: jest.fn(),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
mockAvSplunkAnalytics = new AvSplunkAnalytics(mockLog);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('AvSplunkAnalytics should be defined', () => {
|
|
17
|
+
expect(mockAvSplunkAnalytics).toBeDefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('trackEvent should call AvLogMessages[level]', () => {
|
|
21
|
+
let level = 'info';
|
|
22
|
+
mockAvSplunkAnalytics.trackEvent({ level });
|
|
23
|
+
expect(mockLog.info).toHaveBeenCalledTimes(1);
|
|
24
|
+
expect(mockLog.test).toHaveBeenCalledTimes(0);
|
|
25
|
+
level = 'test';
|
|
26
|
+
mockAvSplunkAnalytics.trackEvent({ level });
|
|
27
|
+
expect(mockLog.info).toHaveBeenCalledTimes(1);
|
|
28
|
+
expect(mockLog.test).toHaveBeenCalledTimes(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("trackEvent should default level to 'info'", () => {
|
|
32
|
+
mockAvSplunkAnalytics.trackEvent({});
|
|
33
|
+
expect(mockLog.info).toHaveBeenCalledTimes(1);
|
|
34
|
+
expect(mockLog.test).toHaveBeenCalledTimes(0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("trackEvent should default properties.url to location.href or 'N/A'", () => {
|
|
38
|
+
let startingObject: { message: string; url: string; level?: string } = {
|
|
39
|
+
message: 'hello world',
|
|
40
|
+
url: window.location.href || 'N/A',
|
|
41
|
+
};
|
|
42
|
+
const expectedCall = {
|
|
43
|
+
...startingObject,
|
|
44
|
+
url: window.location.href || 'N/A',
|
|
45
|
+
level: 'info',
|
|
46
|
+
};
|
|
47
|
+
mockAvSplunkAnalytics.trackEvent(startingObject);
|
|
48
|
+
expect(mockLog.info).toHaveBeenCalledWith(expectedCall);
|
|
49
|
+
|
|
50
|
+
startingObject = {
|
|
51
|
+
message: 'hello world',
|
|
52
|
+
url: 'testUrl',
|
|
53
|
+
level: 'test',
|
|
54
|
+
};
|
|
55
|
+
mockAvSplunkAnalytics.trackEvent(startingObject);
|
|
56
|
+
expect(mockLog.test).toHaveBeenCalledWith(startingObject);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("trackPageView should call trackEvent with event 'page' and passed in url", () => {
|
|
60
|
+
const testUrl = 'testUrl';
|
|
61
|
+
mockAvSplunkAnalytics.trackEvent = jest.fn();
|
|
62
|
+
mockAvSplunkAnalytics.trackPageView(testUrl);
|
|
63
|
+
expect(mockAvSplunkAnalytics.trackEvent).toHaveBeenCalledWith({
|
|
64
|
+
event: 'page',
|
|
65
|
+
url: testUrl,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
camelCase,
|
|
3
|
+
getComposedPath,
|
|
4
|
+
isLeftClickEvent,
|
|
5
|
+
isModifiedEvent,
|
|
6
|
+
isPluginEnabled,
|
|
7
|
+
isValidEventTypeOnTarget,
|
|
8
|
+
} from '../util';
|
|
9
|
+
|
|
10
|
+
describe('analytics-core utils', () => {
|
|
11
|
+
test('isLeftClickEvent', () => {
|
|
12
|
+
expect(isLeftClickEvent({ button: 0 })).toBeTruthy();
|
|
13
|
+
expect(isLeftClickEvent({ button: 1 })).toBeFalsy();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('isModifiedEvent', () => {
|
|
17
|
+
expect(isModifiedEvent({ metaKey: 1 })).toBeTruthy();
|
|
18
|
+
expect(isModifiedEvent({ altKey: 1 })).toBeTruthy();
|
|
19
|
+
expect(isModifiedEvent({ ctrlKey: 1 })).toBeTruthy();
|
|
20
|
+
expect(isModifiedEvent({ shiftKey: 1 })).toBeTruthy();
|
|
21
|
+
expect(isModifiedEvent({ key: 1 })).toBeFalsy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('isValidEventTypeOnTarget', () => {
|
|
25
|
+
expect(isValidEventTypeOnTarget({ target: { nodeName: 'click' }, type: 'click' })).toBeTruthy();
|
|
26
|
+
expect(isValidEventTypeOnTarget({ target: { nodeName: 'select' }, type: 'click' })).toBeFalsy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('isPluginEnabled', () => {
|
|
30
|
+
expect(isPluginEnabled({ isEnabled: () => true })).toBeTruthy();
|
|
31
|
+
expect(isPluginEnabled({ isEnabled: () => false })).toBeFalsy();
|
|
32
|
+
expect(isPluginEnabled({ isEnabled: true })).toBeTruthy();
|
|
33
|
+
expect(isPluginEnabled({ isEnabled: false })).toBeFalsy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('camelCase', () => {
|
|
37
|
+
expect(camelCase('foo')).toBe('foo');
|
|
38
|
+
expect(camelCase('foo-bar')).toBe('fooBar');
|
|
39
|
+
expect(camelCase('foo-bar-baz')).toBe('fooBarBaz');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('getComposedPath', () => {
|
|
43
|
+
expect(getComposedPath({}).length).toBe(1);
|
|
44
|
+
expect(getComposedPath({ parentNode: {} }).length).toBe(2);
|
|
45
|
+
expect(getComposedPath({ host: {} }).length).toBe(2);
|
|
46
|
+
expect(getComposedPath({ defaultView: {} }).length).toBe(2);
|
|
47
|
+
|
|
48
|
+
const result = '[{"parentNode":{"host":{"defaultView":{}}}},{"host":{"defaultView":{}}},{"defaultView":{}},{}]';
|
|
49
|
+
const nested = getComposedPath({ parentNode: { host: { defaultView: {} } } });
|
|
50
|
+
expect(JSON.stringify(nested)).toEqual(result);
|
|
51
|
+
});
|
|
52
|
+
});
|
package/src/util.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
declare const isLeftClickEvent: (event: any) => boolean;
|
|
3
|
+
|
|
4
|
+
declare const isModifiedEvent: (event: any) => boolean;
|
|
5
|
+
|
|
6
|
+
declare const isValidEventTypeOnTarget: (event: any) => boolean;
|
|
7
|
+
|
|
8
|
+
declare const isPluginEnabled: (plugin: any) => any;
|
|
9
|
+
|
|
10
|
+
declare const camelCase: (str: any) => any;
|
|
11
|
+
|
|
12
|
+
declare const getComposedPath: (node: any) => any;
|
|
13
|
+
|
|
14
|
+
export { isLeftClickEvent, isModifiedEvent, isValidEventTypeOnTarget, isPluginEnabled, camelCase, getComposedPath };
|
package/tsconfig.json
ADDED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2016-present Availity, LLC
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|