@guardian/ophan-tracker-js 2.2.2 → 2.2.3
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import clickPathCapture, {
|
|
2
|
-
import transmit from '../transmit.js';
|
|
1
|
+
import clickPathCapture, { getContainingComponent, validAncestorAnchorElement } from '../click-path-capture.js';
|
|
3
2
|
import ophan from '../core.js';
|
|
3
|
+
import transmit from '../transmit.js';
|
|
4
4
|
const { getDataLinkNames } = clickPathCapture;
|
|
5
5
|
describe('click-path-capture.js', () => {
|
|
6
|
-
|
|
6
|
+
beforeEach(() => {
|
|
7
7
|
document.body.innerHTML = `
|
|
8
8
|
<div data-component="component1">
|
|
9
9
|
<div id="testElement4">
|
|
@@ -35,6 +35,19 @@ describe('click-path-capture.js', () => {
|
|
|
35
35
|
const element = document.createElement('div');
|
|
36
36
|
expect(getContainingComponent(element)).toBeNull();
|
|
37
37
|
});
|
|
38
|
+
test('should return the closest ancestor element with data-component attribute', () => {
|
|
39
|
+
document.body.innerHTML = `
|
|
40
|
+
<div data-component="outer-component">
|
|
41
|
+
<div data-component="nested-component">
|
|
42
|
+
<a href="#" data-link-name="link1" id="link1">
|
|
43
|
+
<span id="testElement1"></span>
|
|
44
|
+
</a>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
`;
|
|
48
|
+
const element = document.getElementById('testElement1');
|
|
49
|
+
expect(getContainingComponent(element)).toBe("nested-component");
|
|
50
|
+
});
|
|
38
51
|
});
|
|
39
52
|
describe('getDataLinkNames', () => {
|
|
40
53
|
test('should collect data-link-name attributes from ancestors', () => {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -42,7 +42,7 @@ You can see example usage of the library on theguardian.com [here](https://githu
|
|
|
42
42
|
|
|
43
43
|
### Usage with Typescript
|
|
44
44
|
|
|
45
|
-
Refer to the type definitions within the library for the structure of valid tracking events. The `ophan.record()` function accepts a type of `EventPayload` found [here]("
|
|
45
|
+
Refer to the type definitions within the library for the structure of valid tracking events. The `ophan.record()` function accepts a type of `EventPayload` found [here]("https://github.com/guardian/ophan/blob/main/tracker-js/src/types/event.ts#L90").
|
|
46
46
|
|
|
47
47
|
#### Example Usage
|
|
48
48
|
|