@salesforcedevs/dx-components 0.10.1-alpha.115 → 0.10.1-alpha.119
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 +1 -1
- package/src/modules/dx/lazy/lazy.ts +0 -7
- package/src/modules/dx/sidebar/__tests__/mockDocContent.ts +48 -0
- package/src/modules/dx/sidebar/__tests__/mockPageReference.ts +8 -0
- package/src/modules/dx/sidebar/sidebar.ts +7 -0
- package/src/modules/dx/sidebarSearch/__tests__/{preloadedState.ts → mockPreloadedState.ts} +0 -0
- package/src/modules/dx/sidebarSearch/__tests__/sidebarSearch.test.ts +91 -14
- package/src/modules/dx/sidebarSearch/sidebarSearch.ts +86 -77
- package/src/modules/utils/highlight/__tests__/highlight.test.ts +154 -0
- package/src/modules/utils/highlight/highlight.ts +2 -1
- package/src/modules/utils/jest/jest.ts +35 -0
- package/src/modules/utils/tests/tests.ts +18 -11
package/package.json
CHANGED
|
@@ -2,13 +2,6 @@ import { LightningElement, api } from "lwc";
|
|
|
2
2
|
|
|
3
3
|
import { LazyMode } from "typings/custom";
|
|
4
4
|
|
|
5
|
-
declare global {
|
|
6
|
-
interface Window {
|
|
7
|
-
requestIdleCallback: any;
|
|
8
|
-
cancelIdleCallback: any;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
5
|
/**
|
|
13
6
|
* Defines a fallback for BackgroundTasksAPI for browsers that doesn't support it.
|
|
14
7
|
* Currently BackgroundTasksAPI is supported by all major browsers
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const noteWithOrderedList = `<div class='box message info'>
|
|
2
|
+
<h4 class='mbs'>Note with ordered list</h4>
|
|
3
|
+
<ol class='ol enumList'>
|
|
4
|
+
<li class='li'>From Setup, enter <kbd class='ph userinput'>Apex Classes</kbd> in the <span
|
|
5
|
+
class='keyword parmname'>Quick
|
|
6
|
+
Find</span> box, then select <strong class='ph uicontrol'>Apex Classes</strong>.</li>
|
|
7
|
+
|
|
8
|
+
<li class='li'>Click <strong class='ph uicontrol'>Edit</strong> next to SiteRegisterController.</li>
|
|
9
|
+
|
|
10
|
+
<li class='li'>Find the <samp class='codeph apex_code'><span class='keyword'>private</span> <span
|
|
11
|
+
class='keyword'>static</span> Id PORTAL_ACCOUNT_ID =
|
|
12
|
+
<span class='string'>'<Account_ID>'</span>;</samp> line and insert the ID for the account that
|
|
13
|
+
you want
|
|
14
|
+
to
|
|
15
|
+
associate with new users. The line should look similar to
|
|
16
|
+
this:
|
|
17
|
+
</li>
|
|
18
|
+
|
|
19
|
+
<li class='li'>Click <strong class='ph uicontrol'>Save</strong>.</li>
|
|
20
|
+
</ol>
|
|
21
|
+
</div>`;
|
|
22
|
+
|
|
23
|
+
export const sampleCodeBlockAndNote = `
|
|
24
|
+
<h1 class='helpHead1'>Using the instanceof Keyword</h1>
|
|
25
|
+
<p class="p">If you need to verify at run time whether an object is actually an instance of a particular class, use the
|
|
26
|
+
<samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword.
|
|
27
|
+
The <samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword can only be used to
|
|
28
|
+
verify if the target type in the expression on the right of the keyword is a viable
|
|
29
|
+
alternative for the declared type of the expression on the left.
|
|
30
|
+
</p>
|
|
31
|
+
<div class="p">You could add the following check to the <samp class="codeph apex_code">Report</samp>class in the <a class="xref" href="atlas.en-us.apexcode.meta/apexcode/apex_classes_casting.htm" title="In general, all type information is available at run time. This means that Apex enables casting, that is, a data type of one class can be assigned to a data type of another class, but only if one class is a subclass of the other class. Use casting when you want to convert an object from one data type to another.">classes and casting example</a> before you cast the item back into a <samp class="codeph apex_code">CustomReport</samp> object.
|
|
32
|
+
<div class="codeSection apex_code">
|
|
33
|
+
<pre class="codeblock brush:apex">If (Reports.get(0) <span class="statement">instanceof</span> CustomReport) {\n <span class="onelineComment">// Can safely cast it back to a custom report object</span>\n CustomReport c = (CustomReport) Reports.get(0);\n} Else {\n <span class="onelineComment">// Do something with the non-custom-report.</span>\n}</pre>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
${noteWithOrderedList}
|
|
37
|
+
<div class="p">
|
|
38
|
+
Follow these steps:
|
|
39
|
+
<ol class="ol enumList">
|
|
40
|
+
<li class="li">Add the data in a .csv file.</li>
|
|
41
|
+
<li class="li">Create a static resource for this file.</li>
|
|
42
|
+
<li class="li">
|
|
43
|
+
Call <samp class="codeph apex_code">Test.loadData</samp> within your test
|
|
44
|
+
method and passing it the sObject type token and the static resource name.
|
|
45
|
+
</li>
|
|
46
|
+
</ol>
|
|
47
|
+
</div>
|
|
48
|
+
`;
|
|
@@ -44,6 +44,13 @@ export default class Sidebar extends LightningElement {
|
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
@api
|
|
48
|
+
setInputValue(searchTerm: string) {
|
|
49
|
+
this.template
|
|
50
|
+
.querySelector("dx-sidebar-search")
|
|
51
|
+
.setInputValue(searchTerm);
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
private expanded: boolean = true;
|
|
48
55
|
private _toggleHovered: boolean = false;
|
|
49
56
|
private _value?: string = undefined;
|
|
File without changes
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { createElement } from "lwc";
|
|
1
2
|
import SidebarSearch from "dx/sidebarSearch";
|
|
2
|
-
import { createRenderComponent } from "utils/tests";
|
|
3
|
-
import { coveoXMLDocsConfig } from "utils/coveo";
|
|
3
|
+
import { createRenderComponent, renderLightningElement } from "utils/tests";
|
|
4
|
+
import { coveoXMLDocsConfig } from "utils/coveo";
|
|
5
|
+
import { mockQueryParameter, unmockQueryParameter } from "utils/jest";
|
|
6
|
+
import mockPreloadedState from "./mockPreloadedState";
|
|
7
|
+
import { SESSION_KEY } from "../sidebarSearch";
|
|
4
8
|
|
|
5
9
|
const TAG = "dx-sidebar-search";
|
|
6
10
|
const render = createRenderComponent(TAG, SidebarSearch);
|
|
@@ -8,18 +12,9 @@ const render = createRenderComponent(TAG, SidebarSearch);
|
|
|
8
12
|
const PROPS = coveoXMLDocsConfig;
|
|
9
13
|
const QUERY = "test";
|
|
10
14
|
|
|
11
|
-
const mockQuery = (q: string): void => {
|
|
12
|
-
global.window = Object.create(window);
|
|
13
|
-
const url = `http://dummy.com?q="${q}"`;
|
|
14
|
-
Object.defineProperty(window, "location", {
|
|
15
|
-
value: {
|
|
16
|
-
href: url,
|
|
17
|
-
search: `?q=${q}`
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
15
|
describe(TAG, () => {
|
|
16
|
+
afterEach(unmockQueryParameter);
|
|
17
|
+
|
|
23
18
|
it("renders with the correct initial empty query", () => {
|
|
24
19
|
const element = render(PROPS);
|
|
25
20
|
|
|
@@ -31,7 +26,7 @@ describe(TAG, () => {
|
|
|
31
26
|
});
|
|
32
27
|
|
|
33
28
|
it("renders with the correct initial query", () => {
|
|
34
|
-
|
|
29
|
+
mockQueryParameter(QUERY);
|
|
35
30
|
|
|
36
31
|
const element = render(PROPS);
|
|
37
32
|
|
|
@@ -41,4 +36,86 @@ describe(TAG, () => {
|
|
|
41
36
|
|
|
42
37
|
return expect(element).toBeAccessible();
|
|
43
38
|
});
|
|
39
|
+
|
|
40
|
+
it("correctly consumes a valid session storage object", () => {
|
|
41
|
+
mockQueryParameter(mockPreloadedState.query.q);
|
|
42
|
+
|
|
43
|
+
window.sessionStorage.setItem(
|
|
44
|
+
SESSION_KEY,
|
|
45
|
+
JSON.stringify(mockPreloadedState)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const mockOnChange = jest.fn();
|
|
49
|
+
|
|
50
|
+
const element = render(PROPS);
|
|
51
|
+
element.addEventListener("change", mockOnChange);
|
|
52
|
+
|
|
53
|
+
return Promise.resolve().then(() => {
|
|
54
|
+
expect(mockOnChange).toHaveBeenCalledTimes(1);
|
|
55
|
+
|
|
56
|
+
expect(element).toBeAccessible();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("highlighting", () => {
|
|
61
|
+
afterEach(unmockQueryParameter);
|
|
62
|
+
|
|
63
|
+
it("triggers on initial render when a search value exists", () => {
|
|
64
|
+
mockQueryParameter(QUERY);
|
|
65
|
+
const element = createElement(TAG, { is: SidebarSearch });
|
|
66
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
67
|
+
renderLightningElement(element, PROPS);
|
|
68
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
|
69
|
+
expect.objectContaining({
|
|
70
|
+
type: "highlightedtermchange",
|
|
71
|
+
detail: QUERY
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("does not trigger on initial render when a search value does not exist", () => {
|
|
77
|
+
const element = createElement(TAG, { is: SidebarSearch });
|
|
78
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
79
|
+
renderLightningElement(element, PROPS);
|
|
80
|
+
expect(dispatchEventSpy).not.toHaveBeenCalledWith(
|
|
81
|
+
expect.objectContaining({ type: "highlightedtermchange" })
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("triggers on input change with non-empty value", () => {
|
|
86
|
+
const element = render(PROPS);
|
|
87
|
+
const dxInput = element.shadowRoot.querySelector("dx-input");
|
|
88
|
+
const inputEl = dxInput.shadowRoot.querySelector("input");
|
|
89
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
90
|
+
|
|
91
|
+
inputEl.focus();
|
|
92
|
+
inputEl.value = QUERY;
|
|
93
|
+
inputEl.dispatchEvent(new KeyboardEvent("input"));
|
|
94
|
+
|
|
95
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
|
96
|
+
expect.objectContaining({
|
|
97
|
+
type: "highlightedtermchange",
|
|
98
|
+
detail: QUERY
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("triggers on input change with empty value", () => {
|
|
104
|
+
const element = render(PROPS);
|
|
105
|
+
const dxInput = element.shadowRoot.querySelector("dx-input");
|
|
106
|
+
const inputEl = dxInput.shadowRoot.querySelector("input");
|
|
107
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
108
|
+
|
|
109
|
+
inputEl.focus();
|
|
110
|
+
inputEl.value = "";
|
|
111
|
+
inputEl.dispatchEvent(new KeyboardEvent("input"));
|
|
112
|
+
|
|
113
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
|
114
|
+
expect.objectContaining({
|
|
115
|
+
type: "highlightedtermchange",
|
|
116
|
+
detail: ""
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
44
121
|
});
|
|
@@ -18,7 +18,7 @@ import { RecentSearches } from "utils/recentSearches";
|
|
|
18
18
|
import { toJson } from "utils/normalizers";
|
|
19
19
|
import { Option, PopoverRequestCloseType } from "typings/custom";
|
|
20
20
|
|
|
21
|
-
const SESSION_KEY = "dx-sidebar-search-state";
|
|
21
|
+
export const SESSION_KEY = "dx-sidebar-search-state";
|
|
22
22
|
|
|
23
23
|
const DEFAULT_RESULT_COUNT = 20;
|
|
24
24
|
const SEARCH_DEBOUNCE_DELAY = 780;
|
|
@@ -42,12 +42,17 @@ export default class SidebarSearch extends LightningElement {
|
|
|
42
42
|
|
|
43
43
|
@api
|
|
44
44
|
public fetchMoreResults() {
|
|
45
|
-
if (this.resultList?.moreResultsAvailable) {
|
|
45
|
+
if (this.resultList?.state?.moreResultsAvailable) {
|
|
46
46
|
this.fetchingMoreResults = true;
|
|
47
47
|
this.resultList.fetchMoreResults();
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
@api
|
|
52
|
+
setInputValue(searchTerm: string) {
|
|
53
|
+
this.value = searchTerm || "";
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
private _coveoAdvancedQueryConfig!: object;
|
|
52
57
|
private dropdownRequestedOpen: boolean = false;
|
|
53
58
|
private recentSearches: Option[] = [];
|
|
@@ -58,6 +63,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
58
63
|
private value?: string = "";
|
|
59
64
|
private engine: SearchEngine | null = null;
|
|
60
65
|
private fetchingMoreResults: boolean = false;
|
|
66
|
+
private didRender = false;
|
|
61
67
|
|
|
62
68
|
private get hasCorrectCoveoConfig(): boolean {
|
|
63
69
|
const coveoConfigurations = [
|
|
@@ -78,24 +84,22 @@ export default class SidebarSearch extends LightningElement {
|
|
|
78
84
|
this.dropdownRequestedOpen &&
|
|
79
85
|
this.recentSearches &&
|
|
80
86
|
this.recentSearches.length > 0 &&
|
|
81
|
-
this.
|
|
87
|
+
!this.value
|
|
82
88
|
);
|
|
83
89
|
}
|
|
84
90
|
|
|
85
|
-
private get isValueEmpty(): boolean {
|
|
86
|
-
return !this.value || this.value === "";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
91
|
constructor() {
|
|
90
92
|
super();
|
|
91
93
|
|
|
92
94
|
this.updateRecentSearches();
|
|
93
95
|
this.value = getSidebarSearchParams() || "";
|
|
94
|
-
this.initializeUserSession();
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
renderedCallback() {
|
|
99
|
+
// in prod some of the attributes seem to arrive later, so I put this coveo startup flow here
|
|
98
100
|
if (this.hasCorrectCoveoConfig && !this.engine) {
|
|
101
|
+
console.log("coveo config is good");
|
|
102
|
+
this.initializeUserSession();
|
|
99
103
|
this.initializeCoveo();
|
|
100
104
|
} else if (!this.hasCorrectCoveoConfig) {
|
|
101
105
|
console.error(
|
|
@@ -108,6 +112,14 @@ export default class SidebarSearch extends LightningElement {
|
|
|
108
112
|
}
|
|
109
113
|
);
|
|
110
114
|
}
|
|
115
|
+
|
|
116
|
+
// If this is the first render and there is a search value, trigger
|
|
117
|
+
// term highlighting
|
|
118
|
+
if (!this.didRender && this.value) {
|
|
119
|
+
this.dispatchHighlightedTermChange();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.didRender = true;
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
private initializeUserSession() {
|
|
@@ -115,41 +127,53 @@ export default class SidebarSearch extends LightningElement {
|
|
|
115
127
|
if (!stringified) {
|
|
116
128
|
return;
|
|
117
129
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const json = JSON.parse(stringified);
|
|
133
|
+
const hasSameConfig =
|
|
134
|
+
json.coveoAdvancedQueryConfig ===
|
|
135
|
+
JSON.stringify(this.coveoAdvancedQueryConfig);
|
|
136
|
+
console.log(
|
|
137
|
+
json.coveoAdvancedQueryConfig,
|
|
138
|
+
this.coveoAdvancedQueryConfig,
|
|
139
|
+
hasSameConfig
|
|
140
|
+
);
|
|
141
|
+
const hasSameQuery = json?.state?.query?.q === this.value;
|
|
142
|
+
if (hasSameConfig && hasSameQuery) {
|
|
143
|
+
console.log(
|
|
144
|
+
"valid session storage found for value =",
|
|
145
|
+
this.value
|
|
146
|
+
);
|
|
147
|
+
this.preloadedState = json?.state;
|
|
148
|
+
}
|
|
149
|
+
} catch (_) {
|
|
150
|
+
// Swallow error; no parseable preloaded state
|
|
151
|
+
// TODO: might want to clear sessionStorage, alert user(?), etc.
|
|
122
152
|
}
|
|
123
153
|
}
|
|
124
154
|
|
|
125
|
-
private initializeCoveo =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
155
|
+
private initializeCoveo = () => {
|
|
156
|
+
try {
|
|
157
|
+
this.engine = buildSearchEngine({
|
|
158
|
+
organizationId: this.coveoOrganizationId,
|
|
159
|
+
publicAccessToken: this.coveoPublicAccessToken,
|
|
160
|
+
searchHub: this.coveoSearchHub,
|
|
161
|
+
preloadedState: this.preloadedState
|
|
162
|
+
});
|
|
163
|
+
} catch (ex) {
|
|
164
|
+
console.error(`Coveo engine failed to initialize (${ex})`);
|
|
165
|
+
}
|
|
132
166
|
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
|
|
136
|
-
|
|
167
|
+
if (!this.engine) {
|
|
168
|
+
console.error("Coveo engine failed to initialize!");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
137
171
|
|
|
138
172
|
if (this.preloadedState) {
|
|
139
173
|
const actions = loadQueryActions(this.engine);
|
|
140
174
|
this.engine.dispatch(actions.updateQuery({ q: this.value || "" }));
|
|
141
175
|
}
|
|
142
176
|
|
|
143
|
-
console.log(
|
|
144
|
-
"initialized engine directly after query dispatch",
|
|
145
|
-
this.engine,
|
|
146
|
-
this.engine?.state?.query?.q
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
if (!this.engine) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
177
|
this.resultList = buildResultList(this.engine, {
|
|
154
178
|
options: { fieldsToInclude: ["sfhtml_url__c"] }
|
|
155
179
|
});
|
|
@@ -168,21 +192,16 @@ export default class SidebarSearch extends LightningElement {
|
|
|
168
192
|
|
|
169
193
|
this.resultList?.subscribe(this.onResultListChange);
|
|
170
194
|
|
|
171
|
-
|
|
172
|
-
"initialized engine after sub classes created",
|
|
173
|
-
this.engine
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
if (!this.isValueEmpty) {
|
|
195
|
+
if (this.value) {
|
|
177
196
|
this.dispatchHighlightedTermChange();
|
|
178
197
|
}
|
|
179
198
|
|
|
180
|
-
if (!this.preloadedState
|
|
181
|
-
this.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
if (!this.preloadedState) {
|
|
200
|
+
if (this.value) {
|
|
201
|
+
this.submitSearch();
|
|
202
|
+
} else {
|
|
203
|
+
this.dispatchOnLoading(false);
|
|
204
|
+
}
|
|
186
205
|
}
|
|
187
206
|
};
|
|
188
207
|
|
|
@@ -194,28 +213,21 @@ export default class SidebarSearch extends LightningElement {
|
|
|
194
213
|
const { isLoading, firstSearchExecuted, results } =
|
|
195
214
|
this.resultList.state;
|
|
196
215
|
|
|
197
|
-
|
|
198
|
-
isLoading,
|
|
199
|
-
firstSearchExecuted,
|
|
200
|
-
results
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
if ((!firstSearchExecuted && !isLoading) || this.isValueEmpty) {
|
|
216
|
+
if ((!firstSearchExecuted && !isLoading) || !this.value) {
|
|
204
217
|
// coveo search is firing off some unwanted payloads on startup
|
|
205
218
|
console.log(
|
|
206
219
|
"returning in results list change",
|
|
207
220
|
this.value,
|
|
208
|
-
this.isValueEmpty,
|
|
209
221
|
!firstSearchExecuted && !isLoading
|
|
210
222
|
);
|
|
211
223
|
return;
|
|
212
224
|
}
|
|
213
225
|
|
|
214
226
|
if (!isLoading) {
|
|
227
|
+
console.log("dispatching on change event");
|
|
215
228
|
this.dispatchOnChangeEvent(results);
|
|
216
229
|
}
|
|
217
230
|
|
|
218
|
-
console.log("is fetching more results", this.fetchingMoreResults);
|
|
219
231
|
if (!this.fetchingMoreResults) {
|
|
220
232
|
this.dispatchOnLoading(isLoading);
|
|
221
233
|
}
|
|
@@ -269,10 +281,13 @@ export default class SidebarSearch extends LightningElement {
|
|
|
269
281
|
};
|
|
270
282
|
|
|
271
283
|
private updateSessionStorage() {
|
|
272
|
-
console.log("updating session storage"
|
|
284
|
+
console.log("updating session storage");
|
|
273
285
|
window.sessionStorage.setItem(
|
|
274
286
|
SESSION_KEY,
|
|
275
|
-
JSON.stringify(
|
|
287
|
+
JSON.stringify({
|
|
288
|
+
coveoAdvancedQueryConfig: this.coveoAdvancedQueryConfig,
|
|
289
|
+
state: this.engine?.state
|
|
290
|
+
})
|
|
276
291
|
);
|
|
277
292
|
}
|
|
278
293
|
|
|
@@ -289,6 +304,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
289
304
|
}
|
|
290
305
|
|
|
291
306
|
private dispatchOnLoading(loading: boolean) {
|
|
307
|
+
console.log("dispatching onloading", loading);
|
|
292
308
|
this.dispatchEvent(new CustomEvent("loading", { detail: loading }));
|
|
293
309
|
}
|
|
294
310
|
|
|
@@ -310,18 +326,14 @@ export default class SidebarSearch extends LightningElement {
|
|
|
310
326
|
})
|
|
311
327
|
));
|
|
312
328
|
|
|
313
|
-
private
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (this.value) {
|
|
322
|
-
queryParams.set("q", this.value);
|
|
323
|
-
}
|
|
324
|
-
window.history.pushState({}, "", `?${queryParams.toString()}${hash}`);
|
|
329
|
+
private dispatchSidebarSearchChange(searchTerm: string | undefined): void {
|
|
330
|
+
this.dispatchEvent(
|
|
331
|
+
new CustomEvent("sidebarsearchchange", {
|
|
332
|
+
detail: searchTerm ?? "",
|
|
333
|
+
bubbles: true,
|
|
334
|
+
composed: true
|
|
335
|
+
})
|
|
336
|
+
);
|
|
325
337
|
}
|
|
326
338
|
|
|
327
339
|
private submitSearch = debounce(() => {
|
|
@@ -353,15 +365,12 @@ export default class SidebarSearch extends LightningElement {
|
|
|
353
365
|
private onInputChange(e: CustomEvent) {
|
|
354
366
|
this.value = e.detail;
|
|
355
367
|
|
|
356
|
-
if (
|
|
368
|
+
if (this.value) {
|
|
357
369
|
this.dispatchOnLoading(true);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (this.isValueEmpty) {
|
|
370
|
+
if (this.searchBox) {
|
|
371
|
+
this.submitSearch();
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
365
374
|
// coveo's reaction to an empty value triggers a return of results
|
|
366
375
|
// bootlegging our own ux here`
|
|
367
376
|
this.dispatchOnLoading(false);
|
|
@@ -369,7 +378,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
369
378
|
}
|
|
370
379
|
|
|
371
380
|
this.dispatchHighlightedTermChange();
|
|
372
|
-
this.
|
|
381
|
+
this.dispatchSidebarSearchChange(this.value);
|
|
373
382
|
}
|
|
374
383
|
|
|
375
384
|
private onInputFocus() {
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { createElement } from "lwc";
|
|
2
|
+
import CodeBlock from "dx/codeBlock";
|
|
3
|
+
import { highlightTerms } from "utils/highlight";
|
|
4
|
+
|
|
5
|
+
const mockContent = `<div><a name='apex_dev_guide'><!-- --></a><h1 class='helpHead1'>Apex Developer Guide</h1><div class='shortdesc'>Salesforce has changed the way organizations do business by moving enterprise
|
|
6
|
+
applications that were traditionally client-server-based into the Lightning Platform, an
|
|
7
|
+
on-demand, multitenant Web environment. This environment enables you to run and customize
|
|
8
|
+
applications, such as Salesforce Automation and Service & Support, and build new custom
|
|
9
|
+
applications based on particular business needs. </div><div id='sfdc:seealso' class='related-links'>
|
|
10
|
+
<ul class='ullinks'>
|
|
11
|
+
<li class='link ulchildlink'>
|
|
12
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_intro_get_started.htm'>Getting Started with Apex</a></strong><br>
|
|
13
|
+
Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Lightning Platform server, in conjunction with calls to the API.</li>
|
|
14
|
+
<li class='link ulchildlink'>
|
|
15
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_writing.htm'>Writing Apex</a></strong><br>
|
|
16
|
+
Apex is like Java for Salesforce. It enables you to add and interact with data in the Lightning Platform persistence layer. It uses classes, data types, variables, and if-else statements. You can make it execute based on a condition, or have a block of code execute repeatedly.</li>
|
|
17
|
+
<li class='link ulchildlink'>
|
|
18
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_running.htm'>Running Apex</a></strong><br>
|
|
19
|
+
You can access many features of the Salesforce user interface programmatically in Apex, and you can integrate with external SOAP and REST Web services. You can run Apex code using a variety of mechanisms. Apex code runs in atomic transactions. </li>
|
|
20
|
+
<li class='link ulchildlink'>
|
|
21
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_debug_test_deploy.htm'>Debugging, Testing, and Deploying Apex</a></strong><br>
|
|
22
|
+
Develop your Apex code in a sandbox and debug it with the Developer Console and debug logs. Unit-test your code, then distribute it to customers using packages.</li>
|
|
23
|
+
<li class='link ulchildlink'>
|
|
24
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_reference.htm'>Apex Language Reference</a></strong><br>
|
|
25
|
+
This Apex reference goes into detail about DML statements and the built-in Apex classes and interfaces.</li>
|
|
26
|
+
<li class='link ulchildlink'>
|
|
27
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_appendices.htm'>Appendices</a></strong><br>
|
|
28
|
+
</li>
|
|
29
|
+
<li class='link ulchildlink'>
|
|
30
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/glossary_apex.htm'>Glossary</a></strong><br>
|
|
31
|
+
</li>
|
|
32
|
+
</ul>
|
|
33
|
+
</div><!--DRC 228.7--></div>`;
|
|
34
|
+
|
|
35
|
+
const allowedTags = [
|
|
36
|
+
"p",
|
|
37
|
+
".p",
|
|
38
|
+
".shortdesc",
|
|
39
|
+
"h1",
|
|
40
|
+
"h2",
|
|
41
|
+
"h3",
|
|
42
|
+
"h4",
|
|
43
|
+
"h5",
|
|
44
|
+
"h6",
|
|
45
|
+
"li",
|
|
46
|
+
"dl",
|
|
47
|
+
"th",
|
|
48
|
+
"td"
|
|
49
|
+
];
|
|
50
|
+
const container = document.createElement("div");
|
|
51
|
+
|
|
52
|
+
describe("highlight utility", () => {
|
|
53
|
+
afterEach(() => (container.innerHTML = ""));
|
|
54
|
+
|
|
55
|
+
it("highlights text that matches search criteria", () => {
|
|
56
|
+
container.innerHTML = mockContent;
|
|
57
|
+
highlightTerms(
|
|
58
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
59
|
+
"apex"
|
|
60
|
+
);
|
|
61
|
+
expect(container.querySelectorAll("mark")).toHaveLength(14);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("doesn't highlight elements that contains dx/docs components", () => {
|
|
65
|
+
const searchTerm = "customreport";
|
|
66
|
+
const codeBlock = createElement("dx-code-block", { is: CodeBlock });
|
|
67
|
+
Object.assign(codeBlock, {
|
|
68
|
+
codeBlock: searchTerm,
|
|
69
|
+
language: "text"
|
|
70
|
+
// title: "",
|
|
71
|
+
// variant: "card"
|
|
72
|
+
});
|
|
73
|
+
container.appendChild(document.createElement("p"));
|
|
74
|
+
container.firstElementChild?.appendChild(codeBlock);
|
|
75
|
+
highlightTerms(
|
|
76
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
77
|
+
searchTerm
|
|
78
|
+
);
|
|
79
|
+
expect(container.querySelectorAll("mark")).toHaveLength(0);
|
|
80
|
+
expect(codeBlock.shadowRoot.innerHTML).toMatch(searchTerm); // sanity check
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("doesn't highlight terms separated by html tags", () => {
|
|
84
|
+
container.innerHTML = "<p>loadData<span>within</span></p>";
|
|
85
|
+
highlightTerms(
|
|
86
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
87
|
+
"loadDatawithin"
|
|
88
|
+
);
|
|
89
|
+
expect(container.querySelectorAll("mark")).toHaveLength(0);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("escapes regex especial characters", () => {
|
|
93
|
+
container.innerHTML = mockContent;
|
|
94
|
+
highlightTerms(
|
|
95
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
96
|
+
"apex.+"
|
|
97
|
+
);
|
|
98
|
+
expect(container.querySelectorAll("mark")).toHaveLength(0);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("cleans previous search result before searching for a new term", () => {
|
|
102
|
+
const firstSearch = "apex";
|
|
103
|
+
const secondSearch = "salesforce";
|
|
104
|
+
|
|
105
|
+
container.innerHTML = mockContent;
|
|
106
|
+
|
|
107
|
+
highlightTerms(
|
|
108
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
109
|
+
firstSearch
|
|
110
|
+
);
|
|
111
|
+
const firstMarks = container.querySelectorAll("mark");
|
|
112
|
+
expect(firstMarks).toHaveLength(14);
|
|
113
|
+
firstMarks.forEach(({ textContent }) =>
|
|
114
|
+
expect(textContent?.toLowerCase()).toBe(firstSearch)
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
highlightTerms(
|
|
118
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
119
|
+
secondSearch
|
|
120
|
+
);
|
|
121
|
+
const secondMarks = container.querySelectorAll("mark");
|
|
122
|
+
expect(secondMarks).toHaveLength(4);
|
|
123
|
+
secondMarks.forEach(({ textContent }) =>
|
|
124
|
+
expect(textContent?.toLowerCase()).toBe(secondSearch)
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("cleans all marks if the search term is empty string", () => {
|
|
129
|
+
const firstSearch = "apex";
|
|
130
|
+
const secondSearch = "";
|
|
131
|
+
|
|
132
|
+
container.innerHTML = mockContent;
|
|
133
|
+
|
|
134
|
+
highlightTerms(
|
|
135
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
136
|
+
firstSearch
|
|
137
|
+
);
|
|
138
|
+
const firstMarks = container.querySelectorAll("mark");
|
|
139
|
+
expect(firstMarks).toHaveLength(14);
|
|
140
|
+
firstMarks.forEach(({ textContent }) =>
|
|
141
|
+
expect(textContent?.toLowerCase()).toBe(firstSearch)
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
highlightTerms(
|
|
145
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
146
|
+
secondSearch
|
|
147
|
+
);
|
|
148
|
+
const secondMarks = container.querySelectorAll("mark");
|
|
149
|
+
expect(secondMarks).toHaveLength(0);
|
|
150
|
+
secondMarks.forEach(({ textContent }) =>
|
|
151
|
+
expect(textContent?.toLowerCase()).toBe(secondSearch)
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -3,7 +3,8 @@ import { createSearchRegExp } from "utils/regexps";
|
|
|
3
3
|
const MARK_TAGS = /<\/?mark>/gi;
|
|
4
4
|
|
|
5
5
|
export const highlightTerms = (
|
|
6
|
-
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
elements: NodeListOf<Element>,
|
|
7
8
|
searchTerm: string
|
|
8
9
|
): void => {
|
|
9
10
|
searchTerm = searchTerm.trim();
|
|
@@ -21,3 +21,38 @@ export const createMediaMock = (
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const matchMediaMock = createMediaMock();
|
|
24
|
+
|
|
25
|
+
export const mockLocalStorage = function () {
|
|
26
|
+
let store: { [key: string]: string } = {};
|
|
27
|
+
return {
|
|
28
|
+
getItem: function (key: string) {
|
|
29
|
+
return store[key] || null;
|
|
30
|
+
},
|
|
31
|
+
setItem: function (key: string, value: string) {
|
|
32
|
+
store[key] = value.toString();
|
|
33
|
+
},
|
|
34
|
+
removeItem: function (key: string) {
|
|
35
|
+
delete store[key];
|
|
36
|
+
},
|
|
37
|
+
clear: function () {
|
|
38
|
+
store = {};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const mockQueryParameter = (q: string): void => {
|
|
44
|
+
global.window = Object.create(window);
|
|
45
|
+
const search = q ? `?q=${q}` : "";
|
|
46
|
+
const href = `http://dummy.com${search}`;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
delete window.location.value;
|
|
49
|
+
Object.defineProperty(window, "location", {
|
|
50
|
+
value: {
|
|
51
|
+
href,
|
|
52
|
+
search
|
|
53
|
+
},
|
|
54
|
+
writable: true
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const unmockQueryParameter = () => mockQueryParameter("");
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { createElement, LightningElement } from "lwc";
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.assign(component, properties);
|
|
12
|
-
document.body.appendChild(component);
|
|
13
|
-
return component;
|
|
3
|
+
export const renderLightningElement = (
|
|
4
|
+
element: LightningElement,
|
|
5
|
+
properties = {}
|
|
6
|
+
) => {
|
|
7
|
+
Object.assign(element, properties);
|
|
8
|
+
document.body.appendChild(element as unknown as Node);
|
|
9
|
+
return element;
|
|
14
10
|
};
|
|
15
11
|
|
|
12
|
+
export const createRenderComponent =
|
|
13
|
+
(tag: string, LWC: new () => LightningElement) =>
|
|
14
|
+
(properties = {}) => {
|
|
15
|
+
const component = createElement(tag, {
|
|
16
|
+
is: LWC
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
renderLightningElement(component, properties);
|
|
20
|
+
return component;
|
|
21
|
+
};
|
|
22
|
+
|
|
16
23
|
export const mockSlottedElement = <T extends HTMLElement>(
|
|
17
24
|
element: any,
|
|
18
25
|
elementType = "button",
|