@salesforcedevs/dx-components 0.10.1-alpha.96 → 0.10.1-alpha.97

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.
@@ -39,4 +39,17 @@ describe(TAG, () => {
39
39
 
40
40
  return expect(element).toBeAccessible();
41
41
  });
42
+
43
+ it("doesn't add bold class when there is no highlighted term", () => {
44
+ const element = render({
45
+ ...PROPS,
46
+ descriptionHighlights: [],
47
+ titleHighlights: []
48
+ });
49
+
50
+ const selected = element.shadowRoot.querySelector(".bold");
51
+ expect(selected).toBeNull();
52
+
53
+ return expect(element).toBeAccessible();
54
+ });
42
55
  });
@@ -25,7 +25,6 @@ a {
25
25
 
26
26
  .title {
27
27
  color: var(--dx-g-text-heading-color);
28
- font-weight: 600;
29
28
  }
30
29
 
31
30
  .bold {
@@ -1,25 +1,60 @@
1
- import { buildSearchEngine as _buildSearchEngine } from "@coveo/headless";
1
+ import {
2
+ buildSearchEngine as _buildSearchEngine,
3
+ SearchAppState,
4
+ SearchEngineOptions
5
+ } from "@coveo/headless";
2
6
 
3
7
  export const buildSearchEngine = ({
4
8
  organizationId,
9
+ preloadedState,
5
10
  publicAccessToken,
6
- searchPipeline: pipeline,
7
- searchHub
11
+ searchHub,
12
+ searchPipeline
8
13
  }: {
9
14
  organizationId: string;
10
15
  publicAccessToken: string;
11
16
  searchPipeline: string;
12
17
  searchHub: string;
18
+ preloadedState: SearchAppState;
13
19
  }) => {
14
- const search = pipeline ? { pipeline, searchHub } : { searchHub };
15
- return _buildSearchEngine({
16
- configuration: {
17
- organizationId,
18
- accessToken: publicAccessToken,
19
- search
20
- }
21
- });
20
+ const search = searchPipeline
21
+ ? { pipeline: searchPipeline, searchHub }
22
+ : { searchHub };
23
+
24
+ const configuration = {
25
+ accessToken: publicAccessToken,
26
+ organizationId,
27
+ search
28
+ };
29
+
30
+ const engineConfiguration: SearchEngineOptions = preloadedState
31
+ ? { configuration, preloadedState }
32
+ : { configuration };
33
+
34
+ return _buildSearchEngine(engineConfiguration);
22
35
  };
23
36
 
24
37
  export const getSidebarSearchParams = () =>
25
38
  new URLSearchParams(window.location.search).get("q");
39
+
40
+ export const coveoXMLDocsConfig = {
41
+ coveoOrganizationId: "coveosalesforcetestakshatha",
42
+ coveoPublicAccessToken: "xxfeb39525-e402-4e41-a870-7132441f7875",
43
+ coveoSearchHub: "Developer_Docs_SS",
44
+ coveoAdvancedQueryConfig: JSON.stringify({
45
+ objecttype: "HTDeveloperDocumentsC",
46
+ sflanguage: "en_US",
47
+ sfrelease__c: "232.0",
48
+ sfdelivarable__c: "apexcode"
49
+ })
50
+ };
51
+
52
+ export const coveoSFDocsConfig = {
53
+ coveoOrganizationId: "coveosalesforcetestakshatha",
54
+ coveoPublicAccessToken: "xxfeb39525-e402-4e41-a870-7132441f7875",
55
+ coveoSearchHub: "Developer_MdDocs_SS",
56
+ coveoAdvancedQueryConfig: JSON.stringify({
57
+ source: "Sitemap - Developer Docs",
58
+ path_segment_3: "pardot"
59
+ })
60
+ };
@@ -0,0 +1,79 @@
1
+ import { RecentSearches, LOCAL_STORAGE_KEY, LIMIT } from "utils/recentSearches";
2
+
3
+ describe("recentSearches", () => {
4
+ beforeEach(() => {
5
+ window.localStorage.clear();
6
+ });
7
+
8
+ it("initializes correctly from local storage", () => {
9
+ const initial = ["test", "test1", "test2"];
10
+
11
+ window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(initial));
12
+ const Searches = new RecentSearches();
13
+
14
+ expect(Searches.get()).toEqual(initial);
15
+ });
16
+
17
+ it("ignores exact duplicate additions", () => {
18
+ const Searches = new RecentSearches();
19
+
20
+ const item = "test";
21
+
22
+ Searches.add(item);
23
+ Searches.add(item);
24
+
25
+ expect(Searches.get().length).toEqual(1);
26
+ });
27
+
28
+ it("ignores duplicate additions with extraneous white space", () => {
29
+ const Searches = new RecentSearches();
30
+
31
+ const item1 = "test";
32
+ const item2 = " test ";
33
+
34
+ Searches.add(item1);
35
+ Searches.add(item2);
36
+
37
+ expect(Searches.get().length).toEqual(1);
38
+ expect(Searches.get()[0]).toEqual(item1);
39
+ });
40
+
41
+ it("prioritizes the last searched item", () => {
42
+ const Searches = new RecentSearches();
43
+
44
+ const item1 = "test1";
45
+ const item2 = "test2";
46
+
47
+ Searches.add(item1);
48
+ Searches.add(item2);
49
+
50
+ expect(Searches.get().length).toEqual(2);
51
+
52
+ expect(Searches.get()[0]).toEqual(item2);
53
+ expect(Searches.get()[1]).toEqual(item1);
54
+
55
+ Searches.add(item1);
56
+
57
+ expect(Searches.get().length).toEqual(2);
58
+ expect(Searches.get()[0]).toEqual(item1);
59
+ expect(Searches.get()[1]).toEqual(item2);
60
+ });
61
+
62
+ it("will not exceed the limit", () => {
63
+ const Searches = new RecentSearches();
64
+
65
+ Array.apply(null, Array(LIMIT + 1)).forEach((_, i) => {
66
+ Searches.add(i.toString());
67
+ });
68
+
69
+ expect(Searches.get().length).toEqual(LIMIT);
70
+ });
71
+
72
+ it("doesn't add a bogus value", () => {
73
+ const Searches = new RecentSearches();
74
+
75
+ [null, "", " ", " ", 5].forEach((v) => Searches.add(v));
76
+
77
+ expect(Searches.get().length).toEqual(0);
78
+ });
79
+ });
@@ -1,6 +1,6 @@
1
- const RECENT_SEARCHES = "dx-sidebar-recent-searches";
1
+ export const LOCAL_STORAGE_KEY = "dx-sidebar-recent-searches";
2
2
 
3
- const LIMIT = 5;
3
+ export const LIMIT = 5;
4
4
 
5
5
  export class RecentSearches {
6
6
  items: string[] = [];
@@ -10,11 +10,11 @@ export class RecentSearches {
10
10
  }
11
11
 
12
12
  get() {
13
- return this.items.map((item) => ({ id: item, label: item }));
13
+ return this.items;
14
14
  }
15
15
 
16
16
  add(item: string | undefined) {
17
- if (!item) {
17
+ if (!item || typeof item !== "string") {
18
18
  return;
19
19
  }
20
20
  const normalized = item.trim();
@@ -30,7 +30,7 @@ export class RecentSearches {
30
30
  // private
31
31
  _init() {
32
32
  this.items = JSON.parse(
33
- window.localStorage.getItem(RECENT_SEARCHES) || "[]"
33
+ window.localStorage.getItem(LOCAL_STORAGE_KEY) || "[]"
34
34
  );
35
35
  }
36
36
 
@@ -50,17 +50,8 @@ export class RecentSearches {
50
50
 
51
51
  _addToStorage() {
52
52
  window.localStorage.setItem(
53
- RECENT_SEARCHES,
53
+ LOCAL_STORAGE_KEY,
54
54
  JSON.stringify(this.items)
55
55
  );
56
56
  }
57
-
58
- _isDuplicate(searchItem: string) {
59
- return (
60
- this.items.filter(
61
- (item: string) =>
62
- item.toLowerCase() === searchItem.toLowerCase()
63
- ).length > 0
64
- );
65
- }
66
57
  }