@salesforcedevs/dx-components 0.16.2 → 0.16.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"@types/debounce": "^1.2.0",
|
|
30
30
|
"@types/lodash.get": "^4.4.6"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "82ca0f75d4bdd801e08aab4af8ab0f6aec92a6cb"
|
|
33
33
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import DropdownOption from "dx/dropdownOption";
|
|
2
2
|
import { createRenderComponent } from "utils/tests";
|
|
3
3
|
import { MOCK_BUTTON_PROPS, MOCK_LINK_PROPS } from "./mockProps";
|
|
4
|
+
import * as instrumentation from "dx/instrumentation";
|
|
4
5
|
|
|
5
6
|
const TAG = "dx-dropdown-option";
|
|
6
7
|
const render = createRenderComponent(TAG, DropdownOption);
|
|
@@ -13,6 +14,10 @@ const appendToMenu = (element: HTMLElement) => {
|
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
describe(TAG, () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.clearAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
16
21
|
it("renders a button by default", () => {
|
|
17
22
|
const component = render(MOCK_BUTTON_PROPS);
|
|
18
23
|
expect(component.shadowRoot.querySelector("button")).not.toBeNull();
|
|
@@ -23,8 +28,8 @@ describe(TAG, () => {
|
|
|
23
28
|
|
|
24
29
|
it("renders the correct label, description, and img", () => {
|
|
25
30
|
const component = render(MOCK_BUTTON_PROPS);
|
|
26
|
-
const label =
|
|
27
|
-
.textContent;
|
|
31
|
+
const label =
|
|
32
|
+
component.shadowRoot.querySelector(".option_label").textContent;
|
|
28
33
|
expect(label).toEqual(MOCK_BUTTON_PROPS.option.label);
|
|
29
34
|
|
|
30
35
|
const description = component.shadowRoot.querySelector(
|
|
@@ -79,4 +84,29 @@ describe(TAG, () => {
|
|
|
79
84
|
|
|
80
85
|
expect(onClickMock).toBeCalled();
|
|
81
86
|
});
|
|
87
|
+
|
|
88
|
+
it("fires analytics when given an analytics event", () => {
|
|
89
|
+
const track = jest.spyOn(instrumentation, "track");
|
|
90
|
+
|
|
91
|
+
const component = render({
|
|
92
|
+
...MOCK_BUTTON_PROPS,
|
|
93
|
+
analyticsEvent: "mock"
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const option = component.shadowRoot.querySelector(".option");
|
|
97
|
+
option.click();
|
|
98
|
+
|
|
99
|
+
expect(track).toHaveBeenCalledTimes(1);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("doesn't fire analytics when not given an analytics event", () => {
|
|
103
|
+
const track = jest.spyOn(instrumentation, "track");
|
|
104
|
+
|
|
105
|
+
const component = render(MOCK_BUTTON_PROPS);
|
|
106
|
+
|
|
107
|
+
const option = component.shadowRoot.querySelector(".option");
|
|
108
|
+
option.click();
|
|
109
|
+
|
|
110
|
+
expect(track).not.toHaveBeenCalled();
|
|
111
|
+
});
|
|
82
112
|
});
|
|
@@ -8,6 +8,7 @@ export default class DropdownOption extends LightningElement {
|
|
|
8
8
|
@api keyValue!: string;
|
|
9
9
|
@api active: boolean = false;
|
|
10
10
|
@api navItemLabel: String | null = null;
|
|
11
|
+
@api analyticsEvent: string | null = null;
|
|
11
12
|
|
|
12
13
|
@api focus() {
|
|
13
14
|
const option = this.template.querySelector(".option");
|
|
@@ -26,11 +27,13 @@ export default class DropdownOption extends LightningElement {
|
|
|
26
27
|
new CustomEvent("select", { detail: this.keyValue })
|
|
27
28
|
);
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
if (this.analyticsEvent && e.currentTarget) {
|
|
31
|
+
track(e.currentTarget, this.analyticsEvent, {
|
|
32
|
+
navHeading: this.navItemLabel || undefined,
|
|
33
|
+
navSubHeading: this.option.label || undefined,
|
|
34
|
+
clickText: this.keyValue || undefined,
|
|
35
|
+
pageLocation: window.location.pathname || undefined
|
|
36
|
+
});
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
}
|