@salesforcedevs/dx-components 0.18.7 → 0.18.11

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.18.7",
3
+ "version": "0.18.11",
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": "c73d2695e7f99b7909dec767f606c7ad05c8ef09"
32
+ "gitHead": "ecf0f25f4c6927eb21118122f3b15884c198a287"
33
33
  }
@@ -69,8 +69,10 @@ export default class SidebarSearch extends LightningElement {
69
69
 
70
70
  @api
71
71
  setInputValue(searchTerm: string) {
72
- this.value = searchTerm || "";
73
- this.handleValueChange(true);
72
+ if (searchTerm !== this.value) {
73
+ this.value = searchTerm || "";
74
+ this.handleValueChange(true);
75
+ }
74
76
  }
75
77
 
76
78
  private _coveoAdvancedQueryConfig!: { [key: string]: any };
@@ -283,23 +285,17 @@ export default class SidebarSearch extends LightningElement {
283
285
  }: Result): SidebarSearchResult => {
284
286
  // discussion about this normalization here: https://salesforce-internal.slack.com/archives/C020S6784JX/p1639506238376600
285
287
 
286
- const isNestedGuide = clickUri.includes("/guide/");
287
- const isGuide = clickUri.endsWith("/guide") || isNestedGuide;
288
- const isReference = clickUri.endsWith("/reference");
289
- const isApex = !!sfhtml_url__c;
290
-
291
288
  let pathname;
292
- if (isApex) {
289
+ if (sfhtml_url__c) {
293
290
  pathname = `/docs/${sfhtml_url__c}`;
294
291
  } else {
292
+ const isNestedGuide = clickUri.includes("/guide/");
295
293
  const url = new URL(clickUri);
296
294
  const extension = isNestedGuide ? ".html" : "";
297
295
  pathname = `${url.pathname}${extension}`;
298
296
  }
299
297
 
300
- const query =
301
- isGuide || isReference || isApex ? `?q=${this.value}` : "";
302
- const href = `${pathname}${query}`;
298
+ const href = `${pathname}?q=${this.value}`;
303
299
 
304
300
  return {
305
301
  title,
@@ -4,7 +4,7 @@ import { createRenderComponent } from "utils/tests";
4
4
  const TAG = "dx-sidebar-search-result";
5
5
  const render = createRenderComponent(TAG, SidebarSearchResult);
6
6
 
7
- const PROPS = {
7
+ const MOCK_RESULT = {
8
8
  description: "test description here",
9
9
  descriptionHighlights: [{ length: 5, offset: 5 }],
10
10
  href: "/test",
@@ -13,24 +13,65 @@ const PROPS = {
13
13
  titleHighlights: [{ length: 5, offset: 5 }]
14
14
  };
15
15
 
16
+ const MOCK_RESULT_2 = {
17
+ description:
18
+ "Auth.MyDomainLoginDiscoveryHandler to show a custom error message on the My Domain login page ... Auth.LoginDiscoveryHandler to show an error message on the Experience Cloud site login page",
19
+ descriptionHighlights: [
20
+ { length: 4, offset: 0 },
21
+ { length: 4, offset: 98 }
22
+ ],
23
+ href: "/test",
24
+ selected: false,
25
+ title: "Auth Exceptions | Apex Reference Guide | Salesforce Developers",
26
+ titleHighlights: [{ length: 4, offset: 0 }]
27
+ };
28
+
16
29
  describe(TAG, () => {
17
30
  it("renders a result with the correct highlighted content", () => {
18
- const element = render(PROPS);
31
+ const element = render(MOCK_RESULT);
19
32
 
33
+ const title = element.shadowRoot.querySelector(".title");
20
34
  const titleBolds = element.shadowRoot.querySelectorAll(".title .bold");
21
- expect(titleBolds.length).toEqual(1);
35
+ expect(title.textContent).toEqual(MOCK_RESULT.title);
36
+ expect(titleBolds.length).toEqual(MOCK_RESULT.titleHighlights.length);
22
37
  expect(titleBolds[0].textContent).toEqual("title");
23
38
 
39
+ const description = element.shadowRoot.querySelector(".description");
24
40
  const descriptionBolds =
25
41
  element.shadowRoot.querySelectorAll(".description .bold");
26
- expect(descriptionBolds.length).toEqual(1);
42
+ expect(description.textContent).toEqual(MOCK_RESULT.description);
43
+ expect(descriptionBolds.length).toEqual(
44
+ MOCK_RESULT.descriptionHighlights.length
45
+ );
27
46
  expect(descriptionBolds[0].textContent).toEqual("descr");
28
47
 
29
48
  return expect(element).toBeAccessible();
30
49
  });
31
50
 
51
+ it("renders another result variant with the correct highlighted content", () => {
52
+ const element = render(MOCK_RESULT_2);
53
+
54
+ const title = element.shadowRoot.querySelector(".title");
55
+ const titleBolds = element.shadowRoot.querySelectorAll(".title .bold");
56
+ expect(title.textContent).toEqual(MOCK_RESULT_2.title);
57
+ expect(titleBolds.length).toEqual(MOCK_RESULT_2.titleHighlights.length);
58
+ expect(titleBolds[0].textContent).toEqual("Auth");
59
+
60
+ const description = element.shadowRoot.querySelector(".description");
61
+ const descriptionBolds =
62
+ element.shadowRoot.querySelectorAll(".description .bold");
63
+ expect(description.textContent).toEqual(MOCK_RESULT_2.description);
64
+ expect(descriptionBolds.length).toEqual(
65
+ MOCK_RESULT_2.descriptionHighlights.length
66
+ );
67
+ expect(descriptionBolds[0].textContent).toEqual("Auth");
68
+ expect(descriptionBolds[1].textContent).toEqual("Auth");
69
+
70
+ return expect(element).toBeAccessible();
71
+ });
72
+
32
73
  it("renders a result as selected when specified", () => {
33
- const element = render({ ...PROPS, selected: true });
74
+ const element = render({ ...MOCK_RESULT, selected: true });
34
75
 
35
76
  const selected = element.shadowRoot.querySelector(
36
77
  ".sidebar-item-selected"
@@ -42,7 +83,7 @@ describe(TAG, () => {
42
83
 
43
84
  it("doesn't add bold class when there is no highlighted term", () => {
44
85
  const element = render({
45
- ...PROPS,
86
+ ...MOCK_RESULT,
46
87
  descriptionHighlights: [],
47
88
  titleHighlights: []
48
89
  });
@@ -13,7 +13,7 @@ const toChunks = (value: string, highlights: CoveoHighlights) => {
13
13
  }
14
14
 
15
15
  let endIndex = 0;
16
- return highlights.reduce((acc, { length, offset }) => {
16
+ return highlights.reduce((acc, { length, offset }, i) => {
17
17
  const plainValue = value.slice(endIndex, offset);
18
18
  const plainChunk = {
19
19
  value: plainValue,
@@ -28,9 +28,23 @@ const toChunks = (value: string, highlights: CoveoHighlights) => {
28
28
  id: offset
29
29
  };
30
30
 
31
- return plainValue.length > 0
32
- ? [...acc, plainChunk, boldChunk]
33
- : [...acc, boldChunk];
31
+ let chunks =
32
+ plainValue.length > 0
33
+ ? [...acc, plainChunk, boldChunk]
34
+ : [...acc, boldChunk];
35
+
36
+ const remaining = value.slice(endIndex);
37
+ if (remaining.length > 0 && highlights.length - 1 === i) {
38
+ chunks = [
39
+ ...chunks,
40
+ {
41
+ value: remaining,
42
+ id: value.length
43
+ }
44
+ ];
45
+ }
46
+
47
+ return chunks;
34
48
  }, []);
35
49
  };
36
50