@salesforcedevs/docs-components 0.26.0 → 0.26.3-alpha.1

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.
Files changed (49) hide show
  1. package/lwc.config.json +1 -0
  2. package/package.json +2 -6
  3. package/src/modules/doc/content/content.ts +0 -35
  4. package/src/modules/doc/header/header.ts +1 -1
  5. package/src/modules/doc/heading/heading.css +54 -0
  6. package/src/modules/doc/heading/heading.html +14 -0
  7. package/src/modules/doc/heading/heading.ts +65 -0
  8. package/src/modules/doc/headingContent/headingContent.css +55 -0
  9. package/src/modules/doc/headingContent/headingContent.html +19 -0
  10. package/src/modules/doc/headingContent/headingContent.ts +42 -0
  11. package/LICENSE +0 -12
  12. package/src/modules/doc/content/__tests__/content.test.ts +0 -312
  13. package/src/modules/doc/content/__tests__/mockDocContent.ts +0 -348
  14. package/src/modules/doc/content/__tests__/mockPageReference.ts +0 -8
  15. package/src/modules/doc/content/__tests__/mockSidebar.ts +0 -81
  16. package/src/modules/doc/content/content.stories.ts +0 -148
  17. package/src/modules/doc/contentCallout/__tests__/contentCallout.test.ts +0 -80
  18. package/src/modules/doc/contentCallout/__tests__/mockProps.ts +0 -14
  19. package/src/modules/doc/contentCallout/contentCallout.stories.ts +0 -29
  20. package/src/modules/doc/contentMedia/__tests__/contentMedia.test.ts +0 -93
  21. package/src/modules/doc/contentMedia/contentMedia.stories.ts +0 -113
  22. package/src/modules/doc/header/__tests__/coveoConfig.ts +0 -6
  23. package/src/modules/doc/header/__tests__/header.test.ts +0 -437
  24. package/src/modules/doc/header/__tests__/mockNavDevelopers.ts +0 -427
  25. package/src/modules/doc/header/__tests__/mockNavs.ts +0 -115
  26. package/src/modules/doc/header/__tests__/mockProps.ts +0 -152
  27. package/src/modules/doc/header/header.stories.ts +0 -190
  28. package/src/modules/doc/headingAnchor/__tests__/headingAnchor.test.ts +0 -110
  29. package/src/modules/doc/headingAnchor/headingAnchor.stories.ts +0 -33
  30. package/src/modules/doc/nav/__tests__/mockAvailableLanguages.ts +0 -8
  31. package/src/modules/doc/nav/__tests__/mockAvailableVersions.ts +0 -122
  32. package/src/modules/doc/nav/__tests__/mockPageReference.ts +0 -8
  33. package/src/modules/doc/nav/__tests__/mockPdfUrl.ts +0 -1
  34. package/src/modules/doc/nav/__tests__/mockSelectedLanguage.ts +0 -8
  35. package/src/modules/doc/nav/__tests__/mockSelectedVersion.ts +0 -8
  36. package/src/modules/doc/nav/__tests__/mockToc.ts +0 -146
  37. package/src/modules/doc/nav/__tests__/nav.test.ts +0 -57
  38. package/src/modules/doc/phase/__tests__/mockProps.ts +0 -13
  39. package/src/modules/doc/phase/__tests__/phase.test.ts +0 -58
  40. package/src/modules/doc/phase/phase.stories.ts +0 -12
  41. package/src/modules/doc/toc/__tests__/mockPageReference.ts +0 -8
  42. package/src/modules/doc/toc/__tests__/mockToc.ts +0 -146
  43. package/src/modules/doc/toc/__tests__/toc.test.ts +0 -29
  44. package/src/modules/doc/toolbar/__tests__/mockAvailableLanguages.ts +0 -8
  45. package/src/modules/doc/toolbar/__tests__/mockAvailableVersions.ts +0 -122
  46. package/src/modules/doc/toolbar/__tests__/mockPdfUrl.ts +0 -1
  47. package/src/modules/doc/toolbar/__tests__/mockSelectedLanguage.ts +0 -8
  48. package/src/modules/doc/toolbar/__tests__/mockSelectedVersion.ts +0 -8
  49. package/src/modules/doc/toolbar/__tests__/toolbar.test.ts +0 -44
package/lwc.config.json CHANGED
@@ -8,6 +8,7 @@
8
8
  "doc/contentMedia",
9
9
  "doc/content",
10
10
  "doc/header",
11
+ "doc/heading",
11
12
  "doc/headingAnchor",
12
13
  "doc/phase"
13
14
  ]
package/package.json CHANGED
@@ -1,18 +1,14 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "0.26.0",
3
+ "version": "0.26.3-alpha.1",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "engines": {
8
8
  "node": ">= 14.x"
9
9
  },
10
- "files": [
11
- "src/modules",
12
- "lwc.config.json"
13
- ],
14
10
  "publishConfig": {
15
11
  "access": "public"
16
12
  },
17
- "gitHead": "e3cf39d3be484acbf9bae459659f6e65f1f932cf"
13
+ "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
18
14
  }
@@ -5,23 +5,6 @@ import ContentCallout from "doc/contentCallout";
5
5
  import CodeBlock from "dx/codeBlock";
6
6
  import ContentMedia from "doc/contentMedia";
7
7
  import Button from "dx/button";
8
- import { highlightTerms } from "utils/highlight";
9
-
10
- const HIGHLIGHTABLE_SELECTOR = [
11
- "p",
12
- ".p",
13
- ".shortdesc",
14
- "h1",
15
- "h2",
16
- "h3",
17
- "h4",
18
- "h5",
19
- "h6",
20
- "li",
21
- "dl",
22
- "th",
23
- "td"
24
- ].join(",");
25
8
 
26
9
  const LANGUAGE_MAP: { [key: string]: string } = {
27
10
  js: "javascript"
@@ -62,18 +45,6 @@ export default class Content extends LightningElement {
62
45
  "themechange",
63
46
  this.updateTheme.bind(this) // eslint-disableline no-use-before-define
64
47
  );
65
-
66
- window.addEventListener(
67
- "highlightedtermchange",
68
- this.updateHighlighted
69
- );
70
- }
71
-
72
- disconnectedCallback(): void {
73
- window.removeEventListener(
74
- "highlightedtermchange",
75
- this.updateHighlighted
76
- );
77
48
  }
78
49
 
79
50
  updateTheme() {
@@ -339,12 +310,6 @@ export default class Content extends LightningElement {
339
310
  }
340
311
  }
341
312
 
342
- updateHighlighted = (event: any) =>
343
- highlightTerms(
344
- this.template.querySelectorAll(HIGHLIGHTABLE_SELECTOR),
345
- event.detail
346
- );
347
-
348
313
  @api
349
314
  public navigateToHash(hash: String) {
350
315
  const splitHash = hash.split("#");
@@ -1,7 +1,7 @@
1
1
  import { api } from "lwc";
2
2
  import cx from "classnames";
3
3
  import type { Option } from "typings/custom";
4
- import { HeaderBase } from "utils-internal/headerBase";
4
+ import { HeaderBase } from "base-elements/headerBase";
5
5
  import { toJson } from "utils/normalizers";
6
6
  import get from "lodash.get";
7
7
 
@@ -0,0 +1,54 @@
1
+ h1,
2
+ h2,
3
+ h3,
4
+ h4,
5
+ h5,
6
+ h6 {
7
+ color: var(--dx-g-blue-vibrant-20);
8
+ font-family: var(--dx-g-font-display);
9
+ font-weight: var(--dx-g-font-demi);
10
+ }
11
+
12
+ .display-3 {
13
+ margin: 0 0 24px 0;
14
+ font-size: var(--dx-g-text-3xl);
15
+ letter-spacing: -0.85px;
16
+ line-height: var(--dx-g-text-4xl);
17
+ }
18
+
19
+ .display-3 doc-heading-content {
20
+ --doc-c-heading-anchor-button-bottom: 8px;
21
+ }
22
+
23
+ .display-4 {
24
+ margin: var(--dx-g-spacing-xl) 0 var(--dx-g-spacing-md) 0;
25
+ font-size: var(--dx-g-text-xl);
26
+ letter-spacing: -0.1px;
27
+ line-height: var(--dx-g-spacing-lg);
28
+ }
29
+
30
+ .display-4 doc-heading-content {
31
+ --doc-c-heading-anchor-button-bottom: -3px;
32
+ }
33
+
34
+ .display-5 {
35
+ margin: var(--dx-g-spacing-lg) 0 var(--dx-g-spacing-md) 0;
36
+ font-size: var(--dx-g-text-lg);
37
+ letter-spacing: -0.1px;
38
+ line-height: var(--dx-g-spacing-lg);
39
+ }
40
+
41
+ .display-5 doc-heading-content {
42
+ --doc-c-heading-anchor-button-bottom: -4px;
43
+ }
44
+
45
+ .display-6 {
46
+ margin: var(--dx-g-spacing-md) 0 var(--dx-g-spacing-sm) 0;
47
+ font-size: var(--dx-g-text-base);
48
+ letter-spacing: 0;
49
+ line-height: var(--dx-g-spacing-mlg);
50
+ }
51
+
52
+ .display-6 doc-heading-content {
53
+ --doc-c-heading-anchor-button-bottom: -6px;
54
+ }
@@ -0,0 +1,14 @@
1
+ <template>
2
+ <h1 class={className} if:true={isAriaLevelOne}>
3
+ <doc-heading-content title={title} hash={hash}></doc-heading-content>
4
+ </h1>
5
+ <h2 class={className} if:true={isAriaLevelTwo}>
6
+ <doc-heading-content title={title} hash={hash}></doc-heading-content>
7
+ </h2>
8
+ <h3 class={className} if:true={isAriaLevelThree}>
9
+ <doc-heading-content title={title} hash={hash}></doc-heading-content>
10
+ </h3>
11
+ <h4 class={className} if:true={isAriaLevelFour}>
12
+ <doc-heading-content title={title} hash={hash}></doc-heading-content>
13
+ </h4>
14
+ </template>
@@ -0,0 +1,65 @@
1
+ import { LightningElement, api } from "lwc";
2
+
3
+ export const displayLevels = ["3", "4", "5", "6"];
4
+
5
+ export const ariaLevels = ["1", "2", "3", "4"];
6
+
7
+ export const ariaDisplayLevels: { [key: string]: string } = {
8
+ "1": "3",
9
+ "2": "4",
10
+ "3": "5",
11
+ "4": "6"
12
+ };
13
+
14
+ export default class Heading extends LightningElement {
15
+ @api title: string = "";
16
+ @api hash: string | null = null;
17
+
18
+ @api
19
+ private get ariaLevel(): string {
20
+ return this._ariaLevel || "2";
21
+ }
22
+ private set ariaLevel(value: string | null) {
23
+ if (value && !ariaLevels.includes(value)) {
24
+ console.error(`Invalid aria-level: "${value}"`);
25
+ return;
26
+ }
27
+ if (value) {
28
+ this._ariaLevel = value;
29
+ }
30
+ }
31
+
32
+ @api
33
+ private get displayLevel(): string {
34
+ return this._displayLevel || ariaDisplayLevels[this.ariaLevel];
35
+ }
36
+ private set displayLevel(value: string | null) {
37
+ if (value && !displayLevels.includes(value)) {
38
+ console.error(`Invalid display-level: "${value}"`);
39
+ value = null;
40
+ }
41
+ if (value) {
42
+ this._displayLevel = value;
43
+ }
44
+ }
45
+
46
+ private _ariaLevel: string | null = null;
47
+ private _displayLevel: string | null = null;
48
+
49
+ private get isAriaLevelOne(): boolean {
50
+ return this.ariaLevel === "1";
51
+ }
52
+ private get isAriaLevelTwo(): boolean {
53
+ return this.ariaLevel === "2";
54
+ }
55
+ private get isAriaLevelThree(): boolean {
56
+ return this.ariaLevel === "3";
57
+ }
58
+ private get isAriaLevelFour(): boolean {
59
+ return this.ariaLevel === "4";
60
+ }
61
+
62
+ private get className(): string {
63
+ return `display-${this.displayLevel}`;
64
+ }
65
+ }
@@ -0,0 +1,55 @@
1
+ @import "helpers/reset";
2
+
3
+ :host {
4
+ --doc-c-heading-anchor-button-bottom: 0;
5
+ --doc-c-heading-anchor-icon-size: 18px;
6
+ --button-size: var(--dx-g-spacing-xl);
7
+ }
8
+
9
+ dx-tooltip {
10
+ line-height: var(--button-size);
11
+ }
12
+
13
+ .button-container {
14
+ height: 100%;
15
+ margin-right: calc(var(--dx-g-spacing-xl) - 4px);
16
+ position: relative;
17
+ }
18
+
19
+ button {
20
+ position: absolute;
21
+ bottom: var(--doc-c-heading-anchor-button-bottom);
22
+ left: 0;
23
+ opacity: 0;
24
+ color: rgb(11, 92, 171);
25
+ display: flex;
26
+ justify-content: center;
27
+ align-items: center;
28
+ height: var(--button-size);
29
+ width: var(--button-size);
30
+ border-radius: 4px;
31
+ }
32
+
33
+ dx-icon {
34
+ --dx-c-icon-size: var(--doc-c-heading-anchor-icon-size);
35
+ }
36
+
37
+ span:last-of-type {
38
+ padding-right: var(--dx-g-spacing-xs);
39
+ }
40
+
41
+ .nowrap {
42
+ white-space: nowrap;
43
+ }
44
+
45
+ button:focus {
46
+ box-shadow: 0 0 0 2px rgb(11 92 171);
47
+ }
48
+
49
+ button:focus,
50
+ button:hover,
51
+ span:hover dx-tooltip button,
52
+ span:hover ~ span dx-tooltip button {
53
+ opacity: 1;
54
+ outline: none;
55
+ }
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <template if:false={hash}>{title}</template>
3
+ <template if:true={hash}>
4
+ <template if:true={needsSpace}>
5
+ <span>{titleToWrap}</span>
6
+ <span>&#32;</span>
7
+ </template>
8
+ <span class="nowrap">
9
+ {titleNoWrap}&nbsp;
10
+ <dx-tooltip placement="top" label={label}>
11
+ <span class="button-container">
12
+ <button onclick={copy} aria-label="copy">
13
+ <dx-icon size="override" symbol="link"></dx-icon>
14
+ </button>
15
+ </span>
16
+ </dx-tooltip>
17
+ </span>
18
+ </template>
19
+ </template>
@@ -0,0 +1,42 @@
1
+ import { LightningElement, api } from "lwc";
2
+
3
+ export default class HeadingContent extends LightningElement {
4
+ @api title: string = "";
5
+ @api hash: string | null = null;
6
+
7
+ label: string = "Copy link to clipboard";
8
+ timeout: number | null = null;
9
+
10
+ private get titleToWrap(): string {
11
+ return this.title.substring(0, this.title.lastIndexOf(" "));
12
+ }
13
+
14
+ private get needsSpace(): boolean {
15
+ return this.titleToWrap.length > 0;
16
+ }
17
+
18
+ private get titleNoWrap(): string {
19
+ return this.title.substring(this.title.lastIndexOf(" ") + 1);
20
+ }
21
+
22
+ private async copy() {
23
+ if (this.timeout) {
24
+ window.clearTimeout(this.timeout);
25
+ }
26
+
27
+ this.label = "Copied";
28
+ this.timeout = window.setTimeout(() => {
29
+ this.label = "Copy link to clipboard";
30
+ }, 2000);
31
+
32
+ try {
33
+ if (this.title && this.hash) {
34
+ const [hostUrl] = window.location.href.split("#");
35
+ const url = `${hostUrl}#${this.hash}`;
36
+ await navigator.clipboard.writeText(url);
37
+ }
38
+ } catch (error) {
39
+ console.error(error);
40
+ }
41
+ }
42
+ }
package/LICENSE DELETED
@@ -1,12 +0,0 @@
1
- Copyright (c) 2020, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,312 +0,0 @@
1
- import CodeBlock from "dx/codeBlock";
2
- import { createRenderComponent } from "utils-internal/tests";
3
- import Content from "../content";
4
- import * as mockContent from "./mockDocContent";
5
- import mockPageReference from "./mockPageReference";
6
-
7
- const TAG = "doc-content";
8
- const render = createRenderComponent(TAG, Content);
9
-
10
- describe("doc-content", () => {
11
- it("renders the content", () => {
12
- const component = render({
13
- docsData: mockContent.content,
14
- pageReference: mockPageReference,
15
- _isStorybook: false
16
- });
17
- const contentEl = component.shadowRoot.querySelector(
18
- '[data-name="content"]'
19
- );
20
- expect(contentEl).not.toBeNull();
21
- });
22
-
23
- it("renders both with and wothout pagination buttons", () => {
24
- const c_buttons = render({
25
- docsData: mockContent.withButtons,
26
- pageReference: mockPageReference,
27
- showPaginationButtons: true,
28
- _isStorybook: false
29
- });
30
- const dx_buttons = c_buttons.shadowRoot.querySelectorAll("dx-button");
31
- expect(dx_buttons.length).toEqual(2);
32
-
33
- const c_no_buttons = render({
34
- docsData: mockContent.withButtons,
35
- pageReference: mockPageReference,
36
- _isStorybook: false
37
- });
38
- const empty_dx_buttons =
39
- c_no_buttons.shadowRoot.querySelectorAll("dx-button");
40
- expect(empty_dx_buttons.length).toEqual(0);
41
- });
42
-
43
- it("swaps out images", () => {
44
- const component = render({
45
- docsData: mockContent.withImages,
46
- pageReference: mockPageReference,
47
- _isStorybook: false
48
- });
49
- const contentEl = component.shadowRoot.querySelector(
50
- '[data-name="content"]'
51
- );
52
- expect(contentEl).not.toBeNull();
53
- const images = component.shadowRoot.querySelectorAll("img");
54
- expect(images.length).toEqual(3);
55
- const contentMediaEls =
56
- component.shadowRoot.querySelectorAll("doc-content-media");
57
- expect(contentMediaEls.length).toEqual(0);
58
- });
59
-
60
- it("swaps out iframes", () => {
61
- const component = render({
62
- docsData: mockContent.withVideos,
63
- pageReference: mockPageReference,
64
- _isStorybook: false
65
- });
66
- const contentEl = component.shadowRoot.querySelector(
67
- '[data-name="content"]'
68
- );
69
- expect(contentEl).not.toBeNull();
70
- const images = component.shadowRoot.querySelectorAll("iframe");
71
- expect(images.length).toEqual(0);
72
- const contentMediaEls =
73
- component.shadowRoot.querySelectorAll("doc-content-media");
74
- expect(contentMediaEls.length).toEqual(2);
75
- contentMediaEls.forEach((contentMedia) => {
76
- expect(contentMedia.contentType).toEqual("iframe");
77
- expect(contentMedia.mediaTitle).not.toBeUndefined();
78
- expect(contentMedia.contentSrc).toMatch(
79
- "https://play.vidyard.com/"
80
- );
81
- });
82
- });
83
-
84
- it("swaps out notes", () => {
85
- const component = render({
86
- docsData: mockContent.withNotes,
87
- pageReference: mockPageReference,
88
- _isStorybook: false
89
- });
90
- const contentEl = component.shadowRoot.querySelector(
91
- '[data-name="content"]'
92
- );
93
- expect(contentEl).not.toBeNull();
94
- const notes = component.shadowRoot.querySelectorAll(".message");
95
- expect(notes).toHaveLength(4);
96
- notes.forEach((note) => {
97
- const noteHeader = note.querySelector("doc-content-callout");
98
- expect(noteHeader).not.toBeNull();
99
- });
100
- });
101
-
102
- it("includes tables, lists, and code blocks in notes", () => {
103
- const component = render({
104
- docsData: mockContent.withNotes,
105
- pageReference: mockPageReference,
106
- _isStorybook: false
107
- });
108
- const contentEl = component.shadowRoot.querySelector(
109
- '[data-name="content"]'
110
- );
111
- expect(contentEl).not.toBeNull();
112
- const notes = component.shadowRoot.querySelectorAll(".message");
113
- expect(notes[0].querySelector("table")).not.toBeNull();
114
- expect(notes[1].querySelector("ul")).not.toBeNull();
115
- expect(notes[2].querySelector("ol")).not.toBeNull();
116
- expect(notes[3].querySelector("dx-code-block")).not.toBeNull();
117
- });
118
-
119
- it("highlights text that matches search criteria", () => {
120
- const component = render({
121
- docsData: mockContent.content,
122
- pageReference: mockPageReference,
123
- isStorybook: true
124
- });
125
-
126
- const contentEl = component.shadowRoot.querySelector(
127
- '[data-name="content"]'
128
- );
129
-
130
- expect(contentEl.querySelectorAll("mark")).toHaveLength(0);
131
-
132
- contentEl.dispatchEvent(
133
- new CustomEvent("highlightedtermchange", {
134
- detail: "apex",
135
- composed: true,
136
- bubbles: true
137
- })
138
- );
139
-
140
- expect(contentEl.querySelectorAll("mark")).toHaveLength(14);
141
- });
142
-
143
- it("doesn't highlight elements that contains dx/docs components", () => {
144
- const searchTerm = "customreport";
145
-
146
- const component = render({
147
- docsData: mockContent.sampleCodeBlockAndNote,
148
- pageReference: mockPageReference,
149
- isStorybook: true
150
- });
151
-
152
- const contentEl = component.shadowRoot.querySelector(
153
- '[data-name="content"]'
154
- );
155
-
156
- expect(contentEl.querySelectorAll("mark")).toHaveLength(0);
157
-
158
- contentEl.dispatchEvent(
159
- new CustomEvent("highlightedtermchange", {
160
- detail: searchTerm,
161
- composed: true,
162
- bubbles: true
163
- })
164
- );
165
-
166
- const marks: Array<HTMLElement> = contentEl.querySelectorAll("mark");
167
-
168
- expect(marks).toHaveLength(0);
169
-
170
- const code: CodeBlock = contentEl.querySelector("dx-code-block");
171
- expect(code).not.toBeNull();
172
- expect(code.codeBlock).toBeTruthy();
173
- expect(contentEl.querySelector("doc-content-callout")).not.toBeNull();
174
- });
175
-
176
- it("doesn't highlight terms separated by html tags", () => {
177
- const searchTerm = "loadData within";
178
-
179
- const component = render({
180
- docsData: mockContent.sampleCodeBlockAndNote,
181
- pageReference: mockPageReference,
182
- isStorybook: true
183
- });
184
-
185
- const contentEl = component.shadowRoot.querySelector(
186
- '[data-name="content"]'
187
- );
188
-
189
- contentEl.dispatchEvent(
190
- new CustomEvent("highlightedtermchange", {
191
- detail: searchTerm,
192
- composed: true,
193
- bubbles: true
194
- })
195
- );
196
-
197
- const marks: Array<HTMLElement> =
198
- component.shadowRoot.querySelectorAll("mark");
199
- expect(marks).toHaveLength(0);
200
- });
201
-
202
- it("escapes regex especial characters", () => {
203
- const searchTerm = "used.+";
204
-
205
- const component = render({
206
- docsData: mockContent.sampleCodeBlockAndNote,
207
- pageReference: mockPageReference,
208
- isStorybook: true
209
- });
210
-
211
- const contentEl = component.shadowRoot.querySelector(
212
- '[data-name="content"]'
213
- );
214
-
215
- contentEl.dispatchEvent(
216
- new CustomEvent("highlightedtermchange", {
217
- detail: searchTerm,
218
- composed: true,
219
- bubbles: true
220
- })
221
- );
222
-
223
- const marks: Array<HTMLElement> =
224
- component.shadowRoot.querySelectorAll("mark");
225
- expect(marks).toHaveLength(0);
226
- });
227
-
228
- it("cleans previous search result before searching for a new term", () => {
229
- const firstSearch = "verify";
230
- const secondSearch = "sObject";
231
-
232
- const component = render({
233
- docsData: mockContent.sampleCodeBlockAndNote,
234
- pageReference: mockPageReference,
235
- isStorybook: true
236
- });
237
-
238
- const contentEl = component.shadowRoot.querySelector(
239
- '[data-name="content"]'
240
- );
241
-
242
- contentEl.dispatchEvent(
243
- new CustomEvent("highlightedtermchange", {
244
- detail: firstSearch,
245
- composed: true,
246
- bubbles: true
247
- })
248
- );
249
-
250
- const firstMarks: Array<HTMLElement> =
251
- component.shadowRoot.querySelectorAll("mark");
252
- expect(firstMarks).toHaveLength(2);
253
- firstMarks.forEach(({ textContent }) =>
254
- expect(textContent).toBe(firstSearch)
255
- );
256
-
257
- contentEl.dispatchEvent(
258
- new CustomEvent("highlightedtermchange", {
259
- detail: secondSearch,
260
- composed: true,
261
- bubbles: true
262
- })
263
- );
264
-
265
- const secondMarks: Array<HTMLElement> =
266
- component.shadowRoot.querySelectorAll("mark");
267
- expect(secondMarks).toHaveLength(1);
268
- secondMarks.forEach(({ textContent }) =>
269
- expect(textContent).toBe(secondSearch)
270
- );
271
- });
272
-
273
- it("cleans all marks if the search term is empty string", () => {
274
- const firstSearch = "verify";
275
- const secondSearch = "";
276
-
277
- const component = render({
278
- docsData: mockContent.sampleCodeBlockAndNote,
279
- pageReference: mockPageReference,
280
- isStorybook: true
281
- });
282
-
283
- const contentEl = component.shadowRoot.querySelector(
284
- '[data-name="content"]'
285
- );
286
-
287
- contentEl.dispatchEvent(
288
- new CustomEvent("highlightedtermchange", {
289
- detail: firstSearch,
290
- composed: true,
291
- bubbles: true
292
- })
293
- );
294
-
295
- const firstMarks: Array<HTMLElement> =
296
- component.shadowRoot.querySelectorAll("mark");
297
- expect(firstMarks).toHaveLength(2);
298
- firstMarks.forEach(({ textContent }) =>
299
- expect(textContent).toBe(firstSearch)
300
- );
301
-
302
- contentEl.dispatchEvent(
303
- new CustomEvent("highlightedtermchange", {
304
- detail: secondSearch,
305
- composed: true,
306
- bubbles: true
307
- })
308
- );
309
-
310
- expect(component.shadowRoot.querySelectorAll("mark")).toHaveLength(0);
311
- });
312
- });