@availity/analytics-core 3.1.2 → 3.1.6
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 +38 -0
- package/README.md +8 -2
- package/lib/analytics.js +10 -2
- package/lib/dma.js +5 -1
- package/lib/util.js +7 -1
- package/package.json +28 -10
- package/src/analytics.js +1 -1
- package/src/util.js +1 -1
- package/types/analytics.d.ts +3 -1
- package/types/dma.d.ts +2 -0
- package/types/plugin.d.ts +1 -0
- package/types/splunk.d.ts +2 -0
- package/src/tests/analytics.test.js +0 -184
- package/src/tests/dma.test.js +0 -31
- package/src/tests/plugin.test.js +0 -22
- package/src/tests/splunk.test.js +0 -68
- package/src/tests/util.test.js +0 -53
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.1.6](https://github.com/availity/sdk-js/compare/@availity/analytics-core@3.1.5...@availity/analytics-core@3.1.6) (2021-12-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @availity/analytics-core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 3.1.5 (2021-12-01)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **analytics-core:** recursive getComposedPath calls should be spread ([e39d180](https://github.com/Availity/sdk-js/commit/e39d180d7a0a348b52367bea8a87e6e9b0a98252))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 3.1.4 (2021-11-16)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **analytics-core:** update types and error msg ([8c03422](https://github.com/Availity/sdk-js/commit/8c03422b8ced4c60738616905ce98b1523663f83))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## [3.1.3](https://github.com/Availity/sdk-js/compare/@availity/analytics-core@3.1.2...@availity/analytics-core@3.1.3) (2021-10-29)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package @availity/analytics-core
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
6
44
|
## [3.1.2](https://github.com/Availity/sdk-js/compare/@availity/analytics-core@3.1.1...@availity/analytics-core@3.1.2) (2021-10-22)
|
|
7
45
|
|
|
8
46
|
**Note:** Version bump only for package @availity/analytics-core
|
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @availity/analytics-core
|
|
2
|
+
|
|
3
|
+
> analytics package for tracking user behavior on the dom
|
|
2
4
|
|
|
3
5
|
[](https://www.npmjs.com/package/@availity/analytics-core)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/analytics-core)
|
|
7
|
+
[](https://github.com/Availity/sdk-js/blob/master/packages/analytics-core/package.json)
|
|
4
8
|
|
|
5
9
|
## Install
|
|
6
10
|
|
|
@@ -16,4 +20,6 @@ npm install @availity/analytics-core
|
|
|
16
20
|
yarn add @availity/analytics-core
|
|
17
21
|
```
|
|
18
22
|
|
|
19
|
-
##
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
Check out more documentation at [availity.github.io](https://availity.github.io/sdk-js/resources/analytics)
|
package/lib/analytics.js
CHANGED
|
@@ -15,10 +15,18 @@ require("core-js/modules/es.object.keys.js");
|
|
|
15
15
|
|
|
16
16
|
require("core-js/modules/es.array.filter.js");
|
|
17
17
|
|
|
18
|
+
require("core-js/modules/esnext.async-iterator.filter.js");
|
|
19
|
+
|
|
20
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
21
|
+
|
|
22
|
+
require("core-js/modules/esnext.iterator.filter.js");
|
|
23
|
+
|
|
18
24
|
require("core-js/modules/es.function.name.js");
|
|
19
25
|
|
|
20
26
|
require("core-js/modules/es.array.slice.js");
|
|
21
27
|
|
|
28
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
29
|
+
|
|
22
30
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
23
31
|
|
|
24
32
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
@@ -227,7 +235,7 @@ var AvAnalytics = function AvAnalytics(plugins) {
|
|
|
227
235
|
|
|
228
236
|
this.trackPageView = function (url) {
|
|
229
237
|
// hashchanges are an object so we want to grab the new url from it
|
|
230
|
-
if (
|
|
238
|
+
if ((0, _typeof2["default"])(url) === 'object') {
|
|
231
239
|
url = url.newURL;
|
|
232
240
|
}
|
|
233
241
|
|
|
@@ -257,7 +265,7 @@ var AvAnalytics = function AvAnalytics(plugins) {
|
|
|
257
265
|
// if plugins or promise are undefined,
|
|
258
266
|
// or if either is skipped and pageTracking boolean is used in their place
|
|
259
267
|
if (!plugins || !promise) {
|
|
260
|
-
throw new Error('[plugins]
|
|
268
|
+
throw new Error('[plugins] and [promise] must be defined');
|
|
261
269
|
}
|
|
262
270
|
|
|
263
271
|
this.plugins = Array.isArray(plugins) ? plugins : [plugins];
|
package/lib/dma.js
CHANGED
|
@@ -10,12 +10,16 @@ require("core-js/modules/es.weak-map.js");
|
|
|
10
10
|
|
|
11
11
|
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
12
12
|
|
|
13
|
+
require("core-js/modules/esnext.weak-map.emplace.js");
|
|
14
|
+
|
|
13
15
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
14
16
|
|
|
15
17
|
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
16
18
|
|
|
17
19
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
18
20
|
|
|
21
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
22
|
+
|
|
19
23
|
Object.defineProperty(exports, "__esModule", {
|
|
20
24
|
value: true
|
|
21
25
|
});
|
|
@@ -35,7 +39,7 @@ var _plugin = _interopRequireDefault(require("./plugin"));
|
|
|
35
39
|
|
|
36
40
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
37
41
|
|
|
38
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
42
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
39
43
|
|
|
40
44
|
var schema = yup.object().shape({
|
|
41
45
|
level: yup.string().optional(),
|
package/lib/util.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
require("core-js/modules/es.regexp.exec");
|
|
4
6
|
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7,8 +9,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
9
|
});
|
|
8
10
|
exports.isValidEventTypeOnTarget = exports.isPluginEnabled = exports.isModifiedEvent = exports.isLeftClickEvent = exports.getComposedPath = exports.camelCase = void 0;
|
|
9
11
|
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
10
14
|
require("core-js/modules/es.string.replace.js");
|
|
11
15
|
|
|
16
|
+
require("core-js/modules/es.array.concat.js");
|
|
17
|
+
|
|
12
18
|
var isLeftClickEvent = function isLeftClickEvent(event) {
|
|
13
19
|
return event.button === 0;
|
|
14
20
|
};
|
|
@@ -64,7 +70,7 @@ var getComposedPath = function getComposedPath(node) {
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
if (parent !== undefined) {
|
|
67
|
-
return [node, getComposedPath(parent)
|
|
73
|
+
return [node].concat((0, _toConsumableArray2["default"])(getComposedPath(parent)));
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
return [node];
|
package/package.json
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/analytics-core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "Analytics base configuration for sdk-js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"availity",
|
|
7
|
+
"analytics"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://availity.github.io/sdk-js/resources/analytics",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/availity/sdk-js/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/availity/sdk-js.git",
|
|
16
|
+
"directory": "packages/analytics-core"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Kasey Powers <kasey.powers@availity.com>",
|
|
5
20
|
"main": "lib/index.js",
|
|
6
21
|
"module": "src/index.js",
|
|
7
22
|
"types": "types/index.d.ts",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "yarn clean && yarn transpile",
|
|
25
|
+
"clean": "rimraf ./lib",
|
|
26
|
+
"transpile": "babel --root-mode upward src -d lib --ignore **/*.test.js"
|
|
12
27
|
},
|
|
13
|
-
"gitHead": "a247c20c27816eb3e3b68b983d12631a6cadd72b",
|
|
14
28
|
"dependencies": {
|
|
15
|
-
"@babel/runtime": "^7.
|
|
29
|
+
"@babel/runtime": "^7.16.5",
|
|
16
30
|
"core-js": "^3.12.1",
|
|
17
|
-
"yup": "^0.
|
|
31
|
+
"yup": "^0.32.9"
|
|
18
32
|
},
|
|
19
33
|
"devDependencies": {
|
|
20
|
-
"@availity/api-axios": "^6.0.
|
|
21
|
-
}
|
|
34
|
+
"@availity/api-axios": "^6.0.6"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "1c3e8c8045b16fc5111f941d863600f0a97cdbff"
|
|
22
40
|
}
|
package/src/analytics.js
CHANGED
|
@@ -12,7 +12,7 @@ export default class AvAnalytics {
|
|
|
12
12
|
// if plugins or promise are undefined,
|
|
13
13
|
// or if either is skipped and pageTracking boolean is used in their place
|
|
14
14
|
if (!plugins || !promise) {
|
|
15
|
-
throw new Error('[plugins]
|
|
15
|
+
throw new Error('[plugins] and [promise] must be defined');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
this.plugins = Array.isArray(plugins) ? plugins : [plugins];
|
package/src/util.js
CHANGED
package/types/analytics.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
3
|
declare class AvAnalytics {
|
|
2
4
|
constructor(
|
|
3
5
|
plugins: any[],
|
|
@@ -27,7 +29,7 @@ declare class AvAnalytics {
|
|
|
27
29
|
|
|
28
30
|
trackEvent(properties: any): Promise<any[]>;
|
|
29
31
|
|
|
30
|
-
trackPageView(url
|
|
32
|
+
trackPageView(url?: string): Promise<any[]>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export default AvAnalytics;
|
package/types/dma.d.ts
CHANGED
package/types/plugin.d.ts
CHANGED
package/types/splunk.d.ts
CHANGED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { AvAnalytics } from '..';
|
|
2
|
-
|
|
3
|
-
function makePlugin() {
|
|
4
|
-
return {
|
|
5
|
-
isEnabled: jest.fn(() => true),
|
|
6
|
-
init: jest.fn(),
|
|
7
|
-
trackEvent: jest.fn(),
|
|
8
|
-
trackPageView: jest.fn(),
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe('AvAnalytics', () => {
|
|
13
|
-
let mockAvAnalytics;
|
|
14
|
-
|
|
15
|
-
test('AvAnalytics should be defined', () => {
|
|
16
|
-
const plugins = [makePlugin()];
|
|
17
|
-
mockAvAnalytics = new AvAnalytics(plugins, Promise, true);
|
|
18
|
-
expect(mockAvAnalytics).toBeDefined();
|
|
19
|
-
mockAvAnalytics = new AvAnalytics(plugins, Promise);
|
|
20
|
-
expect(mockAvAnalytics).toBeDefined();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('AvAnalytics should throw error without plugins or Promise', () => {
|
|
24
|
-
expect(() => {
|
|
25
|
-
mockAvAnalytics = new AvAnalytics();
|
|
26
|
-
}).toThrow('[plugins], and [promise] must be defined');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('AvAnalytics should cast plugins to an array', () => {
|
|
30
|
-
const plugin = makePlugin();
|
|
31
|
-
mockAvAnalytics = new AvAnalytics(plugin, Promise);
|
|
32
|
-
expect(mockAvAnalytics.plugins).toEqual([plugin]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('AvAnalytics should use custom configs', () => {
|
|
36
|
-
mockAvAnalytics = new AvAnalytics([], Promise, true, true, {
|
|
37
|
-
attributePrefix: 'some-attr',
|
|
38
|
-
recursive: true,
|
|
39
|
-
});
|
|
40
|
-
expect(mockAvAnalytics.attributePrefix).toBe('some-attr');
|
|
41
|
-
expect(mockAvAnalytics.recursive).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('setPageTracking', () => {
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
const plugins = [makePlugin()];
|
|
47
|
-
mockAvAnalytics = new AvAnalytics(plugins, Promise);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('passing in argument should change value of pageTracking', () => {
|
|
51
|
-
const initialTracking = true;
|
|
52
|
-
const setPageTracking = !initialTracking;
|
|
53
|
-
|
|
54
|
-
mockAvAnalytics.pageTracking = initialTracking;
|
|
55
|
-
|
|
56
|
-
mockAvAnalytics.setPageTracking(setPageTracking);
|
|
57
|
-
expect(mockAvAnalytics.pageTracking).toBe(setPageTracking);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('isPageTracking will not change without start/stop pageTracking functions defined', () => {
|
|
61
|
-
mockAvAnalytics.startPageTracking = undefined;
|
|
62
|
-
mockAvAnalytics.setPageTracking(true);
|
|
63
|
-
expect(mockAvAnalytics.isPageTracking).toBe(false);
|
|
64
|
-
mockAvAnalytics.setPageTracking(false);
|
|
65
|
-
expect(mockAvAnalytics.isPageTracking).toBe(false);
|
|
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;
|
|
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;
|
|
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
|
-
expect(plugins[0].trackEvent).not.toHaveBeenCalled();
|
|
166
|
-
expect(plugins[2].trackEvent).toHaveBeenCalledWith(mockProperties);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test('trackEvent should call trackEvent on enabled plugins with url', async () => {
|
|
170
|
-
const mockProperties = {};
|
|
171
|
-
await mockAvAnalytics.trackEvent(mockProperties);
|
|
172
|
-
expect(plugins[0].trackEvent).not.toHaveBeenCalled();
|
|
173
|
-
expect(mockProperties.url).toBeDefined();
|
|
174
|
-
expect(plugins[2].trackEvent).toHaveBeenCalledWith(mockProperties);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('trackPageView should call trackPageView on enabled plugins with properties', async () => {
|
|
178
|
-
const mockUrl = 'testProperties';
|
|
179
|
-
await mockAvAnalytics.trackPageView(mockUrl);
|
|
180
|
-
expect(plugins[0].trackPageView).not.toHaveBeenCalled();
|
|
181
|
-
expect(plugins[1].trackPageView).toHaveBeenCalledWith(mockUrl);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
package/src/tests/dma.test.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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;
|
|
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
|
-
});
|
package/src/tests/plugin.test.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AvAnalyticsPlugin } from '..';
|
|
2
|
-
|
|
3
|
-
describe('AvAnalyticsPlugin', () => {
|
|
4
|
-
let mockPlugin;
|
|
5
|
-
|
|
6
|
-
test('AvAnalyticsPlugin should be defined', () => {
|
|
7
|
-
mockPlugin = new AvAnalyticsPlugin();
|
|
8
|
-
expect(mockPlugin).toBeDefined();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('should default enabled to true', () => {
|
|
12
|
-
mockPlugin = new AvAnalyticsPlugin();
|
|
13
|
-
expect(mockPlugin.enabled).toBe(true);
|
|
14
|
-
mockPlugin = new AvAnalyticsPlugin(false);
|
|
15
|
-
expect(mockPlugin.enabled).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('isEnabled should return enabled value', () => {
|
|
19
|
-
mockPlugin = new AvAnalyticsPlugin();
|
|
20
|
-
expect(mockPlugin.isEnabled()).toBe(mockPlugin.enabled);
|
|
21
|
-
});
|
|
22
|
-
});
|
package/src/tests/splunk.test.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { AvSplunkAnalytics } from '..';
|
|
2
|
-
|
|
3
|
-
describe('AvSplunkAnalytics', () => {
|
|
4
|
-
let mockLog;
|
|
5
|
-
let mockAvSplunkAnalytics;
|
|
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 = {
|
|
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
|
-
});
|
package/src/tests/util.test.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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 =
|
|
49
|
-
'[{"parentNode":{"host":{"defaultView":{}}}},[{"host":{"defaultView":{}}},[{"defaultView":{}},[{}]]]]';
|
|
50
|
-
const nested = getComposedPath({ parentNode: { host: { defaultView: {} } } });
|
|
51
|
-
expect(JSON.stringify(nested)).toEqual(result);
|
|
52
|
-
});
|
|
53
|
-
});
|