@salesforcedevs/docs-components 0.14.3 → 0.17.0

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/docs-components",
3
- "version": "0.14.3",
3
+ "version": "0.17.0",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -14,5 +14,5 @@
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
- "gitHead": "5f2e8f24d38615ea586617396722792cf8a42f20"
17
+ "gitHead": "b7a26c9e46cee9298b3ebc7cbea85930320b83a0"
18
18
  }
@@ -1,3 +1,4 @@
1
+ import CodeBlock from "dx/codeBlock";
1
2
  import { createRenderComponent } from "utils/tests";
2
3
  import Content from "../content";
3
4
  import * as mockContent from "./mockDocContent";
@@ -34,9 +35,8 @@ describe("doc-content", () => {
34
35
  pageReference: mockPageReference,
35
36
  _isStorybook: false
36
37
  });
37
- const empty_dx_buttons = c_no_buttons.shadowRoot.querySelectorAll(
38
- "dx-button"
39
- );
38
+ const empty_dx_buttons =
39
+ c_no_buttons.shadowRoot.querySelectorAll("dx-button");
40
40
  expect(empty_dx_buttons.length).toEqual(0);
41
41
  });
42
42
 
@@ -52,9 +52,8 @@ describe("doc-content", () => {
52
52
  expect(contentEl).not.toBeNull();
53
53
  const images = component.shadowRoot.querySelectorAll("img");
54
54
  expect(images.length).toEqual(3);
55
- const contentMediaEls = component.shadowRoot.querySelectorAll(
56
- "doc-content-media"
57
- );
55
+ const contentMediaEls =
56
+ component.shadowRoot.querySelectorAll("doc-content-media");
58
57
  expect(contentMediaEls.length).toEqual(0);
59
58
  });
60
59
 
@@ -70,9 +69,8 @@ describe("doc-content", () => {
70
69
  expect(contentEl).not.toBeNull();
71
70
  const images = component.shadowRoot.querySelectorAll("iframe");
72
71
  expect(images.length).toEqual(0);
73
- const contentMediaEls = component.shadowRoot.querySelectorAll(
74
- "doc-content-media"
75
- );
72
+ const contentMediaEls =
73
+ component.shadowRoot.querySelectorAll("doc-content-media");
76
74
  expect(contentMediaEls.length).toEqual(2);
77
75
  contentMediaEls.forEach((contentMedia) => {
78
76
  expect(contentMedia.contentType).toEqual("iframe");
@@ -117,4 +115,198 @@ describe("doc-content", () => {
117
115
  expect(notes[2].querySelector("ol")).not.toBeNull();
118
116
  expect(notes[3].querySelector("dx-code-block")).not.toBeNull();
119
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
+ });
120
312
  });
@@ -313,6 +313,33 @@ const noteWithCodeBlock = `<div class='box message info'>
313
313
  </div>
314
314
  </div>`;
315
315
 
316
+ export const sampleCodeBlockAndNote = `
317
+ <h1 class='helpHead1'>Using the instanceof Keyword</h1>
318
+ <p class="p">If you need to verify at run time whether an object is actually an instance of a particular class, use the
319
+ <samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword.
320
+ The <samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword can only be used to
321
+ verify if the target type in the expression on the right of the keyword is a viable
322
+ alternative for the declared type of the expression on the left.
323
+ </p>
324
+ <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.
325
+ <div class="codeSection apex_code">
326
+ <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>
327
+ </div>
328
+ </div>
329
+ ${noteWithOrderedList}
330
+ <div class="p">
331
+ Follow these steps:
332
+ <ol class="ol enumList">
333
+ <li class="li">Add the data in a .csv file.</li>
334
+ <li class="li">Create a static resource for this file.</li>
335
+ <li class="li">
336
+ Call <samp class="codeph apex_code">Test.loadData</samp> within your test
337
+ method and passing it the sObject type token and the static resource name.
338
+ </li>
339
+ </ol>
340
+ </div>
341
+ `;
342
+
316
343
  export const withNotes = `<div>
317
344
  ${noteWithTable}
318
345
  ${noteWithUnorderedList}
@@ -0,0 +1,81 @@
1
+ export default [
2
+ {
3
+ label: "Getting started",
4
+ name: "started",
5
+ isExpanded: true,
6
+ children: [
7
+ {
8
+ label: "Introduction",
9
+ name: "introduction"
10
+ },
11
+ {
12
+ label: "Getting started",
13
+ name: "started-child"
14
+ },
15
+ {
16
+ label: "Authentication",
17
+ name: "authentication"
18
+ },
19
+ {
20
+ label: "Token",
21
+ name: "token"
22
+ },
23
+ {
24
+ label: "Error",
25
+ name: "error"
26
+ },
27
+ {
28
+ label: "Limits",
29
+ name: "limit"
30
+ },
31
+ {
32
+ label: "Release note",
33
+ name: "release-note"
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ label: "Einstein Vision",
39
+ name: "einstein-vision",
40
+ children: [
41
+ {
42
+ label: "Introduction",
43
+ name: "einstein-introduction"
44
+ },
45
+ {
46
+ label: "Terminology",
47
+ name: "terminology"
48
+ },
49
+ {
50
+ label: "Object detection quickstart for beginner",
51
+ name: "object-quickstart",
52
+ isExpanded: true,
53
+ children: [
54
+ {
55
+ label: "Scenario: this block is intended to show how a large text looks like in the sidebar",
56
+ name: "scenario",
57
+ isExpanded: true,
58
+ children: [
59
+ {
60
+ label: "Scenario A: this block is intended to show how a large text looks like in the sidebar",
61
+ name: "scenario-a"
62
+ },
63
+ {
64
+ label: "Scenario B",
65
+ name: "scenario-b"
66
+ }
67
+ ]
68
+ },
69
+ {
70
+ label: "Prerequisites",
71
+ name: "prerequisites"
72
+ }
73
+ ]
74
+ },
75
+ {
76
+ label: "Best Practices",
77
+ name: "best-practices"
78
+ }
79
+ ]
80
+ }
81
+ ];
@@ -368,3 +368,7 @@ samp,
368
368
  font-family: Menlo, monospace;
369
369
  font-size: 1em;
370
370
  }
371
+
372
+ mark {
373
+ background-color: var(--dx-g-yellow-vibrant-90);
374
+ }
@@ -1,5 +1,6 @@
1
1
  import * as mockDocContent from "./__tests__/mockDocContent";
2
2
  import mockPageReference from "./__tests__/mockPageReference";
3
+ import mockSidebar from "./__tests__/mockSidebar";
3
4
  import { html } from "lit-html";
4
5
 
5
6
  export default {
@@ -106,3 +107,42 @@ PaginationButtons.args = {
106
107
  showPaginationButtons: false,
107
108
  docsData: mockDocContent.withButtons
108
109
  };
110
+
111
+ export const HighlightedTerm = ({ docsData, trees }: any) => html`
112
+ <style>
113
+ .sb-show-main.sb-main-padded {
114
+ padding: 0;
115
+ }
116
+
117
+ .container {
118
+ display: flex;
119
+ }
120
+
121
+ dx-sidebar {
122
+ --dx-c-sidebar-min-height: 100vh;
123
+ margin-right: 16px;
124
+ }
125
+
126
+ doc-content {
127
+ margin: 16px 16px;
128
+ }
129
+ </style>
130
+
131
+ <div class="container">
132
+ <dx-sidebar
133
+ header="Guides"
134
+ trees="${JSON.stringify(trees)}"
135
+ ></dx-sidebar>
136
+ <doc-content
137
+ is-storybook="true"
138
+ page-reference="${JSON.stringify(mockPageReference)}"
139
+ docs-data="${docsData}"
140
+ ></doc-content>
141
+ </div>
142
+ `;
143
+
144
+ HighlightedTerm.args = {
145
+ ...defaultArgs,
146
+ docsData: mockDocContent.sampleCodeBlockAndNote,
147
+ trees: mockSidebar
148
+ };
@@ -1,10 +1,27 @@
1
1
  /* eslint-disable @lwc/lwc/no-inner-html */
2
2
  import { createElement, LightningElement, api, track } from "lwc";
3
- import { DocContent, PageReference } from "../../../../../../../typings/custom";
3
+ import { DocContent, PageReference } from "typings/custom";
4
4
  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 ALLOWED_ELEMENTS = [
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
+ ];
8
25
 
9
26
  const LANGUAGE_MAP: { [key: string]: string } = {
10
27
  js: "javascript"
@@ -15,31 +32,48 @@ export default class Content extends LightningElement {
15
32
  @api pageReference!: PageReference;
16
33
  @api codeBlockType: string = "card";
17
34
  @api showPaginationButtons: boolean = false;
35
+
18
36
  @api
19
37
  set docsData(value) {
20
38
  this._docRendered = false;
21
- this.docContent = value;
39
+ this.docContent = (value && value.trim()) || "";
22
40
  }
41
+
23
42
  get docsData() {
24
43
  return this.docContent;
25
44
  }
26
- _codeBlockTheme: string = "dark";
45
+
27
46
  @api
28
47
  set codeBlockTheme(value) {
29
48
  this._codeBlockTheme = value;
30
49
  }
50
+
31
51
  get codeBlockTheme() {
32
52
  return this._codeBlockTheme;
33
53
  }
34
54
 
35
55
  @track docContent: DocContent = "";
56
+ _codeBlockTheme: string = "dark";
36
57
  _docRendered: boolean = false;
37
58
  originalCodeBlockThemeValue: String = "";
59
+
38
60
  connectedCallback() {
39
61
  this.template.addEventListener(
40
62
  "themechange",
41
63
  this.updateTheme.bind(this) // eslint-disableline no-use-before-define
42
64
  );
65
+
66
+ window.addEventListener(
67
+ "highlightedtermchange",
68
+ this.updateHighlighted
69
+ );
70
+ }
71
+
72
+ disconnectedCallback(): void {
73
+ window.removeEventListener(
74
+ "highlightedtermchange",
75
+ this.updateHighlighted
76
+ );
43
77
  }
44
78
 
45
79
  updateTheme() {
@@ -72,19 +106,17 @@ export default class Content extends LightningElement {
72
106
  // We don't use any tracked field here. The challenge is that
73
107
  // for security reasons you can't pass pure HTML via a class
74
108
  // field to the template. Hence we manipulate the DOM manually.
75
- insertDocHtml() {
76
- const divEl = this.template.querySelector("div");
109
+ insertDocHtml(docContent?: string) {
110
+ const divEl = this.getCleanContainer();
77
111
 
78
112
  // Some simple data mutation to make Prism work on-the-fly with the existing datasource
79
113
  const templateEl = document.createElement("template");
80
- this.docContent = this.docContent.trim();
81
114
  // eslint-disable-next-line no-use-before-define
82
- templateEl.innerHTML = this.docContent;
115
+ templateEl.innerHTML = docContent || this.docContent;
83
116
 
84
117
  // Query the code blocks and create a dx-code-block component that contains the code
85
- const codeBlockEls = templateEl.content.querySelectorAll(
86
- ".codeSection"
87
- );
118
+ const codeBlockEls =
119
+ templateEl.content.querySelectorAll(".codeSection");
88
120
  codeBlockEls.forEach((codeBlockEl) => {
89
121
  codeBlockEl.setAttribute("lwc:dom", "manual");
90
122
  const classList = codeBlockEl.firstChild.classList;
@@ -136,9 +168,8 @@ export default class Content extends LightningElement {
136
168
  });
137
169
 
138
170
  // Modify links to work with any domain, links that start with "#" are excluded
139
- const anchorEls = templateEl.content.querySelectorAll(
140
- "a:not([href^='#'])"
141
- );
171
+ const anchorEls =
172
+ templateEl.content.querySelectorAll("a:not([href^='#'])");
142
173
  anchorEls.forEach((anchorEl) => {
143
174
  if (
144
175
  anchorEl.textContent.includes("Next →") ||
@@ -253,6 +284,15 @@ export default class Content extends LightningElement {
253
284
  }
254
285
  }
255
286
 
287
+ private getCleanContainer(): HTMLElement | null {
288
+ const divEl = this.template.querySelector("div");
289
+ if (divEl?.hasChildNodes()) {
290
+ divEl.removeChild(divEl.firstChild!);
291
+ }
292
+
293
+ return divEl;
294
+ }
295
+
256
296
  isSamePage(reference: PageReference): boolean {
257
297
  return (
258
298
  this.pageReference.contentDocumentId ===
@@ -267,9 +307,8 @@ export default class Content extends LightningElement {
267
307
  event.preventDefault();
268
308
  // eslint-disable-next-line no-use-before-define
269
309
  const target = event.currentTarget.dataset.id;
270
- const [page, docId, deliverable, tempContentDocumentId] = target.split(
271
- "/"
272
- );
310
+ const [page, docId, deliverable, tempContentDocumentId] =
311
+ target.split("/");
273
312
  const [contentDocumentId, hash] = tempContentDocumentId.split("#");
274
313
  const newPageReference = {
275
314
  page: page,
@@ -293,6 +332,14 @@ export default class Content extends LightningElement {
293
332
  }
294
333
  }
295
334
 
335
+ updateHighlighted = (event: any) =>
336
+ highlightTerms(
337
+ Array.from(
338
+ this.template.querySelectorAll(ALLOWED_ELEMENTS.join(","))
339
+ ),
340
+ event.detail
341
+ );
342
+
296
343
  @api
297
344
  public navigateToHash(hash: String) {
298
345
  const splitHash = hash.split("#");
@@ -12,6 +12,7 @@ import {
12
12
  import Dropdown from "dx/dropdown";
13
13
  import { Option } from "typings/custom";
14
14
  import { track } from "dx/instrumentation";
15
+ import { ANALYTICS_INFO } from "utils/headerBase";
15
16
 
16
17
  const EXPECTED_QUERY_TABLET = "(max-width: 980px)";
17
18
  const EXPECTED_QUERY_MOBILE = "(max-width: 880px)";
@@ -22,9 +23,6 @@ jest.mock("dx/instrumentation");
22
23
  const TAG = "doc-header";
23
24
  const render = createRenderComponent(TAG, Header);
24
25
 
25
- const GTM_EVENT_NAME = "custEv_signupStart";
26
- const SIGN_UP_LABEL = "Sign Up";
27
-
28
26
  const assertMediaMatchCalls = () => {
29
27
  expect(window.matchMedia).toBeCalledTimes(3);
30
28
  expect(window.matchMedia).toHaveBeenNthCalledWith(1, EXPECTED_QUERY_MOBILE);
@@ -98,13 +96,12 @@ describe(TAG, () => {
98
96
  const element = render();
99
97
  expect(element.headerHref).toBe("/");
100
98
 
101
- const headerEl: HTMLElement = element.shadowRoot.querySelector(
102
- "header"
103
- );
99
+ const headerEl: HTMLElement =
100
+ element.shadowRoot.querySelector("header");
104
101
  expect(headerEl).not.toBeNull();
105
102
  expect(headerEl.classList).toHaveLength(0);
106
103
 
107
- expect(headerEl.querySelector("dx-feedback-banner")).not.toBeNull();
104
+ expect(headerEl.querySelector("dx-banner")).not.toBeNull();
108
105
 
109
106
  const logo = element.shadowRoot.querySelector("dx-logo");
110
107
  expect(logo).not.toBeNull();
@@ -122,9 +119,8 @@ describe(TAG, () => {
122
119
  element.shadowRoot.querySelector("dx-header-mobile-nav-menu")
123
120
  ).toBeNull();
124
121
 
125
- const homeLink: HTMLAnchorElement = element.shadowRoot.querySelector(
126
- ".home-link"
127
- );
122
+ const homeLink: HTMLAnchorElement =
123
+ element.shadowRoot.querySelector(".home-link");
128
124
  expect(homeLink).not.toBeNull();
129
125
  expect(homeLink.href).toMatch(/\/$/);
130
126
  expect(homeLink.querySelector("dx-icon")).toBeNull();
@@ -150,9 +146,8 @@ describe(TAG, () => {
150
146
  );
151
147
  expect(signUp).not.toBeNull();
152
148
 
153
- const headerNavs: Array<HeaderNav> = element.shadowRoot.querySelectorAll(
154
- "dx-header-nav"
155
- );
149
+ const headerNavs: Array<HeaderNav> =
150
+ element.shadowRoot.querySelectorAll("dx-header-nav");
156
151
  expect(headerNavs).toHaveLength(1);
157
152
  const [globalNav] = headerNavs;
158
153
  expect(globalNav.ariaLabel).toBe("Global Navigation Bar");
@@ -181,9 +176,8 @@ describe(TAG, () => {
181
176
  it("renders with scoped nav items", () => {
182
177
  const element = render(mockPropsEmployees);
183
178
 
184
- const headerNavs: Array<HeaderNav> = element.shadowRoot.querySelectorAll(
185
- "dx-header-nav"
186
- );
179
+ const headerNavs: Array<HeaderNav> =
180
+ element.shadowRoot.querySelectorAll("dx-header-nav");
187
181
  expect(headerNavs).toHaveLength(2);
188
182
  const [globalNav, scopedNav] = headerNavs;
189
183
  expect(globalNav.ariaLabel).toBe("Global Navigation Bar");
@@ -207,9 +201,8 @@ describe(TAG, () => {
207
201
  it("renders the brand icon when a brand has an icon associated", () => {
208
202
  const element = render(mockPropsEmployees);
209
203
 
210
- const brandIcon: Icon = element.shadowRoot.querySelector(
211
- ".brand-icon"
212
- );
204
+ const brandIcon: Icon =
205
+ element.shadowRoot.querySelector(".brand-icon");
213
206
  expect(brandIcon).not.toBeNull();
214
207
  expect(brandIcon.symbol).toBe(mockPropsEmployees.brand);
215
208
  });
@@ -220,9 +213,8 @@ describe(TAG, () => {
220
213
  brand: undefined
221
214
  });
222
215
 
223
- const brandIcon: Icon = element.shadowRoot.querySelector(
224
- ".brand-icon"
225
- );
216
+ const brandIcon: Icon =
217
+ element.shadowRoot.querySelector(".brand-icon");
226
218
  expect(brandIcon).toBeNull();
227
219
  });
228
220
 
@@ -271,9 +263,8 @@ describe(TAG, () => {
271
263
  bailLabel: "test",
272
264
  signupLink: "/"
273
265
  });
274
- const buttons: Array<Button> = element.shadowRoot.querySelectorAll(
275
- "dx-button"
276
- );
266
+ const buttons: Array<Button> =
267
+ element.shadowRoot.querySelectorAll("dx-button");
277
268
 
278
269
  expect(buttons[0].href).toEqual("/");
279
270
  expect(buttons[1].href).toEqual("test");
@@ -285,28 +276,50 @@ describe(TAG, () => {
285
276
  subtitle: mockPropsDevelopers.subtitle,
286
277
  navItems: mockPropsDevelopers.navItems
287
278
  });
288
- const headerSearch = element.shadowRoot.querySelector(
289
- "dx-header-search"
290
- );
279
+ const headerSearch =
280
+ element.shadowRoot.querySelector("dx-header-search");
291
281
 
292
282
  expect(headerSearch).toBeNull();
293
283
  return expect(element).toBeAccessible();
294
284
  });
295
285
 
296
- it("signup button track is beign called", () => {
286
+ it("signup button track is being called", () => {
297
287
  const element = render(mockPropsDevelopers);
298
288
 
299
- const button: HTMLElement = element.shadowRoot.querySelector(
300
- "dx-button"
301
- );
289
+ const button: HTMLElement =
290
+ element.shadowRoot.querySelector("dx-button");
302
291
 
303
292
  button.click();
304
293
 
305
294
  expect(track).toBeCalledTimes(1);
306
- expect(track).toBeCalledWith(button, GTM_EVENT_NAME, {
307
- clickText: SIGN_UP_LABEL
295
+ expect(track).toBeCalledWith(button, "custEv_signupStart", {
296
+ ...ANALYTICS_INFO,
297
+ clickUrl: "/sign-up"
308
298
  });
309
299
  });
300
+
301
+ it("hides signup button when signupLink property is empty", () => {
302
+ const updatedMockPropsDevelopers = {
303
+ ...mockPropsDevelopers,
304
+ signupLink: ""
305
+ };
306
+ const element = render(updatedMockPropsDevelopers);
307
+ const signupButtonContainer: HTMLElement =
308
+ element.shadowRoot.querySelector(".header-login-signup");
309
+ expect(signupButtonContainer).toBeNull();
310
+ });
311
+
312
+ it("hides banner when banner markup is empty", () => {
313
+ const bannerMarkup = "";
314
+ const updatedMockPropsDevelopers = {
315
+ ...mockPropsDevelopers,
316
+ bannerMarkup
317
+ };
318
+ const element = render(updatedMockPropsDevelopers);
319
+ const bannerElement: HTMLElement =
320
+ element.shadowRoot.querySelector("dx-banner");
321
+ expect(bannerElement).toBeNull();
322
+ });
310
323
  });
311
324
 
312
325
  describe("tablet", () => {
@@ -322,9 +335,8 @@ describe(TAG, () => {
322
335
  );
323
336
  expect(button).toBeNull();
324
337
 
325
- const headerSearch = element.shadowRoot.querySelector(
326
- "dx-header-search"
327
- );
338
+ const headerSearch =
339
+ element.shadowRoot.querySelector("dx-header-search");
328
340
  expect(headerSearch).not.toBeNull();
329
341
  expect(headerSearch.mobile).toBe(true);
330
342
 
@@ -360,9 +372,8 @@ describe(TAG, () => {
360
372
  );
361
373
  expect(button).not.toBeNull();
362
374
 
363
- const headerSearch = element.shadowRoot.querySelector(
364
- "dx-header-search"
365
- );
375
+ const headerSearch =
376
+ element.shadowRoot.querySelector("dx-header-search");
366
377
 
367
378
  expect(
368
379
  element.shadowRoot.querySelector(
@@ -32,6 +32,9 @@ export const mockPropsDevelopers = {
32
32
  title: "Salesforce Developers",
33
33
  subtitle: "Apex Developer Guides",
34
34
  languages,
35
+ signupLink: "/sign-up",
36
+ bannerMarkup:
37
+ '<span><a href="https://forms.gle/TdSyKFPHXoBx7seM9" target="blank">Share your feedback</a>about our new site.</span>',
35
38
  ...coveoConfig
36
39
  };
37
40
 
@@ -1,7 +1,10 @@
1
1
  <template>
2
2
  <dx-brand-theme-provider brand={brand}>
3
3
  <header class={className}>
4
- <dx-feedback-banner></dx-feedback-banner>
4
+ <dx-banner
5
+ if:true={bannerMarkup}
6
+ banner-markup={bannerMarkup}
7
+ ></dx-banner>
5
8
  <div class="header_l1">
6
9
  <div if:true={showMenuButton} class="nav_menu-ctas">
7
10
  <dx-button
@@ -101,6 +101,8 @@ const headerStoryGenerator = (
101
101
  bail-label="${args.bailLabel}"
102
102
  brand="${brand}"
103
103
  onclick="headerClick(event)"
104
+ signup-link="${mockProps.signupLink}"
105
+ banner-markup="${mockProps.bannerMarkup}"
104
106
  ></doc-header>`;
105
107
 
106
108
  export const Base = (args: any) => html`
@@ -158,3 +160,31 @@ export const Service = (args: any) =>
158
160
 
159
161
  export const Analytics = (args: any) =>
160
162
  headerStoryGenerator(mockPropsAnalytics, "analytics", args);
163
+
164
+ export const AnalyticsWithoutSignup = (args: any) =>
165
+ headerStoryGenerator(
166
+ { ...mockPropsAnalytics, signupLink:"" },
167
+ "analytics",
168
+ args
169
+ );
170
+
171
+ export const AnalyticsWithCustomBannerText = (args: any) =>
172
+ headerStoryGenerator(
173
+ {
174
+ ...mockPropsMarketing,
175
+ bannerMarkup:
176
+ 'Salesforce Subscription Management API ("the API") is available as a developer preview. The API is not generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All components of the API including request names, parameters, objects, and fields are subject to change or deprecation at any time, with or without notice. Do not use the API with real data or in a production environment.'
177
+ },
178
+ "analytics",
179
+ args
180
+ );
181
+
182
+ export const AnalyticsWithoutBanner = (args: any) =>
183
+ headerStoryGenerator(
184
+ {
185
+ ...mockPropsMarketing,
186
+ bannerMarkup: ""
187
+ },
188
+ "analytics",
189
+ args
190
+ );
@@ -63,7 +63,9 @@ export default class Header extends HeaderBase {
63
63
  }
64
64
 
65
65
  private get showSignup(): boolean {
66
- return (this.tablet && !this.isSearchOpen) || !this.tablet;
66
+ return this.signupLink
67
+ ? (this.tablet && !this.isSearchOpen) || !this.tablet
68
+ : false;
67
69
  }
68
70
 
69
71
  private get hasLanguages(): boolean {