@truedat/se 7.5.9 → 7.5.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.
Files changed (37) hide show
  1. package/package.json +43 -64
  2. package/src/components/CardResult.js +3 -4
  3. package/src/components/DeleteIndexButton.js +0 -1
  4. package/src/components/ElasticIndexes.js +5 -4
  5. package/src/components/Search.js +0 -1
  6. package/src/components/SearchHome.js +4 -4
  7. package/src/components/SearchInput.js +0 -1
  8. package/src/components/SearchLoader.js +17 -37
  9. package/src/components/SearchPagination.js +0 -1
  10. package/src/components/SearchResults.js +4 -5
  11. package/src/components/SearchRoutes.js +21 -67
  12. package/src/components/SearchTabs.js +7 -8
  13. package/src/components/__tests__/CardResult.spec.js +7 -7
  14. package/src/components/__tests__/DeleteIndexButton.spec.js +22 -37
  15. package/src/components/__tests__/ElasticIndexes.spec.js +5 -26
  16. package/src/components/__tests__/Search.spec.js +0 -1
  17. package/src/components/__tests__/SearchInput.spec.js +7 -12
  18. package/src/components/__tests__/SearchLoader.spec.js +64 -72
  19. package/src/components/__tests__/SearchPagination.spec.js +0 -1
  20. package/src/components/__tests__/SearchResults.spec.js +0 -1
  21. package/src/components/__tests__/SearchRoutes.spec.js +107 -7
  22. package/src/components/__tests__/SearchTabs.spec.js +6 -5
  23. package/src/components/__tests__/SearchTabsHide.spec.js +9 -25
  24. package/src/components/__tests__/__snapshots__/CardResult.spec.js.snap +29 -22
  25. package/src/components/__tests__/__snapshots__/ElasticIndexes.spec.js.snap +1 -12
  26. package/src/components/__tests__/__snapshots__/Search.spec.js.snap +6 -5
  27. package/src/components/__tests__/__snapshots__/SearchInput.spec.js.snap +15 -14
  28. package/src/components/__tests__/__snapshots__/SearchLoader.spec.js.snap +7 -1
  29. package/src/components/__tests__/__snapshots__/SearchResults.spec.js.snap +3 -2
  30. package/src/components/__tests__/__snapshots__/SearchRoutes.spec.js.snap +94 -5
  31. package/src/components/__tests__/__snapshots__/SearchTabs.spec.js.snap +4 -0
  32. package/src/hooks/__tests__/{useElasticIndexes.spec.js → useElasticIndexes.spec.js.disabled} +1 -1
  33. package/src/selectors/__tests__/getSearchQuery.spec.js +7 -7
  34. package/src/selectors/__tests__/searchIndicesSelector.spec.js +2 -2
  35. package/src/selectors/__tests__/searchResultsSelector.spec.js +13 -10
  36. package/src/selectors/defaultIndices.js +2 -2
  37. package/src/selectors/searchResultsSelector.js +4 -4
@@ -1,25 +1,20 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { intl } from "@truedat/test/intl-stub";
1
+ import { render, waitForLoad } from "@truedat/test/render";
4
2
  import { SearchInput } from "../SearchInput";
5
3
 
6
- // workaround for enzyme issue with React.useContext
7
- // see https://github.com/airbnb/enzyme/issues/2176#issuecomment-532361526
8
- jest.spyOn(React, "useContext").mockImplementation(() => intl);
9
-
10
4
  describe("<SearchInput />", () => {
11
5
  const query = "My Q";
12
6
  const fetchSearch = jest.fn();
13
7
  const loading = false;
14
8
 
15
- it("it matches the last snapshot", () => {
9
+ it("it matches the last snapshot", async () => {
16
10
  const props = {
17
11
  query,
18
12
  fetchSearch,
19
- loading
13
+ loading,
20
14
  };
21
- const wrapper = shallow(<SearchInput {...props} />);
22
- expect(wrapper).toMatchSnapshot();
23
- expect(wrapper.find("Input").length).toBe(1);
15
+ const rendered = render(<SearchInput {...props} />);
16
+ await waitForLoad(rendered);
17
+ expect(rendered.container).toMatchSnapshot();
18
+ expect(rendered.container.querySelector("input")).toBeInTheDocument();
24
19
  });
25
20
  });
@@ -1,86 +1,78 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { SearchLoader } from "../SearchLoader";
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import SearchLoader from "../SearchLoader";
3
+ import { clearSearch, fetchSearch, updateSearchPath } from "../../routines";
4
4
 
5
5
  describe("<SearchLoader />", () => {
6
- const searchLoading = false;
7
- const fetchSearch = jest.fn();
8
- const clearSearch = jest.fn();
9
- const updateSearchPath = jest.fn();
10
- const match = { path: "my_path" };
6
+ beforeEach(() => {
7
+ jest.clearAllMocks();
8
+ });
9
+
10
+ it("it matches the last snapshot", async () => {
11
+ const mockDispatch = jest.fn();
12
+ const rendered = render(<SearchLoader />, {
13
+ state: { searchLoading: true },
14
+ dispatch: mockDispatch,
15
+ });
11
16
 
12
- it("it matches the last snapshot", () => {
13
- const searchLoading = true;
14
- const props = {
15
- clearSearch,
16
- fetchSearch,
17
- updateSearchPath,
18
- match,
19
- searchLoading
20
- };
21
- const wrapper = shallow(<SearchLoader {...props} />);
22
- expect(wrapper).toMatchSnapshot();
17
+ expect(rendered.container).toMatchSnapshot();
23
18
  });
24
19
 
25
- it("renders a loader if searchLoading is true", () => {
26
- const searchLoading = true;
27
- const props = {
28
- clearSearch,
29
- fetchSearch,
30
- updateSearchPath,
31
- match,
32
- searchLoading
33
- };
34
- const wrapper = shallow(<SearchLoader {...props} />);
35
- expect(wrapper.find("Loading").length).toBe(1);
20
+ it("renders a loader if searchLoading is true", async () => {
21
+ const mockDispatch = jest.fn();
22
+ const rendered = render(<SearchLoader />, {
23
+ state: { searchLoading: true },
24
+ dispatch: mockDispatch,
25
+ });
26
+ expect(rendered.container.querySelector(".loader")).toBeInTheDocument();
36
27
  });
37
28
 
38
- it("renders null if searchLoading is false", () => {
39
- const props = {
40
- clearSearch,
41
- fetchSearch,
42
- updateSearchPath,
43
- match,
44
- searchLoading
45
- };
46
- const wrapper = shallow(<SearchLoader {...props} />);
47
- expect(wrapper.getElement()).toBeNull();
29
+ it("renders null if searchLoading is false", async () => {
30
+ const mockDispatch = jest.fn();
31
+ const rendered = render(<SearchLoader />, {
32
+ state: { searchLoading: false },
33
+ dispatch: mockDispatch,
34
+ });
35
+
36
+ await waitForLoad(rendered);
37
+ expect(rendered.container.firstChild).toBeNull();
48
38
  });
49
39
 
50
- it("calls fetchSearch when component mounts but not when it unmounts", () => {
51
- const fetchSearch = jest.fn();
52
- const updateSearchPath = jest.fn();
40
+ it("calls fetchSearch when component mounts but not when it unmounts", async () => {
41
+ const mockDispatch = jest.fn();
42
+ const rendered = render(<SearchLoader />, {
43
+ state: { searchLoading: false },
44
+ dispatch: mockDispatch,
45
+ });
46
+
47
+ await waitForLoad(rendered);
48
+
49
+ // Verify updateSearchPath and fetchSearch were called on mount
50
+ expect(mockDispatch).toHaveBeenCalledWith(
51
+ updateSearchPath(expect.objectContaining({ path: expect.any(String) }))
52
+ );
53
+ expect(mockDispatch).toHaveBeenCalledWith(fetchSearch({}));
53
54
 
54
- const props = {
55
- clearSearch,
56
- fetchSearch,
57
- updateSearchPath,
58
- match,
59
- searchLoading
60
- };
61
- jest.spyOn(SearchLoader.prototype, "componentDidMount");
62
- const wrapper = shallow(<SearchLoader {...props} />);
63
- expect(SearchLoader.prototype.componentDidMount.mock.calls.length).toBe(1);
64
- expect(fetchSearch.mock.calls.length).toBe(1);
65
- expect(updateSearchPath.mock.calls.length).toBe(1);
66
- wrapper.unmount();
67
- expect(fetchSearch.mock.calls.length).toBe(1);
68
- expect(updateSearchPath.mock.calls.length).toBe(1);
55
+ const dispatchCallCount = mockDispatch.mock.calls.length;
56
+ rendered.unmount();
57
+
58
+ // Verify no additional calls to fetchSearch or updateSearchPath
59
+ expect(mockDispatch.mock.calls.length).toBe(dispatchCallCount + 1); // +1 for clearSearch
69
60
  });
70
61
 
71
- it("calls clearSearch when component mounts but not when it unmounts", () => {
72
- const clearSearch = jest.fn();
73
- const props = {
74
- clearSearch,
75
- fetchSearch,
76
- updateSearchPath,
77
- match,
78
- searchLoading
79
- };
80
- jest.spyOn(SearchLoader.prototype, "componentWillUnmount");
81
- const wrapper = shallow(<SearchLoader {...props} />);
82
- expect(clearSearch.mock.calls.length).toBe(0);
83
- wrapper.unmount();
84
- expect(clearSearch.mock.calls.length).toBe(1);
62
+ it("calls clearSearch when component unmounts", async () => {
63
+ const mockDispatch = jest.fn();
64
+ const rendered = render(<SearchLoader />, {
65
+ state: { searchLoading: false },
66
+ dispatch: mockDispatch,
67
+ });
68
+
69
+ await waitForLoad(rendered);
70
+
71
+ mockDispatch.mockClear(); // Clear previous calls
72
+ rendered.unmount();
73
+
74
+ // Verify clearSearch was called on unmount
75
+ expect(mockDispatch).toHaveBeenCalledTimes(1);
76
+ expect(mockDispatch).toHaveBeenCalledWith(clearSearch());
85
77
  });
86
78
  });
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import SearchPagination from "../SearchPagination";
4
3
 
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import { SearchResults } from "../SearchResults";
4
3
 
@@ -1,14 +1,114 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import { useAuthorized } from "@truedat/core/hooks/useAuthorized";
3
+ import {
4
+ SEARCH,
5
+ SEARCH_CONCEPTS,
6
+ SEARCH_INGESTS,
7
+ SEARCH_RESULTS,
8
+ SEARCH_STRUCTURES,
9
+ ELASTICINDEXES,
10
+ } from "@truedat/core/routes";
3
11
  import { SearchRoutes } from "../SearchRoutes";
4
12
 
5
- jest.mock("@truedat/core/hooks", () => ({
6
- useAuthorized: jest.fn(() => true),
13
+ // Mock the hooks module
14
+ jest.mock("@truedat/core/hooks/useAuthorized");
15
+
16
+ // Mock child components
17
+ jest.mock(
18
+ "../SearchLoader",
19
+ () =>
20
+ function SearchLoader() {
21
+ return <div>SearchLoader</div>;
22
+ }
23
+ );
24
+ jest.mock(
25
+ "../SearchHome",
26
+ () =>
27
+ function SearchHome() {
28
+ return <div>SearchHome</div>;
29
+ }
30
+ );
31
+ jest.mock(
32
+ "../Search",
33
+ () =>
34
+ function Search() {
35
+ return <div>Search</div>;
36
+ }
37
+ );
38
+ jest.mock(
39
+ "../ElasticIndexes",
40
+ () =>
41
+ function ElasticIndexes() {
42
+ return <div>ElasticIndexes</div>;
43
+ }
44
+ );
45
+ jest.mock("@truedat/core/components", () => ({
46
+ Unauthorized: () => <div>Unauthorized</div>,
47
+ ...jest.requireActual("@truedat/core/components"),
7
48
  }));
8
49
 
9
50
  describe("<SearchRoutes />", () => {
10
- it("matches the latest snapshot", () => {
11
- const wrapper = shallow(<SearchRoutes />);
12
- expect(wrapper).toMatchSnapshot();
51
+ it("renders correctly with default route", async () => {
52
+ const rendered = render(<SearchRoutes />);
53
+ await waitForLoad(rendered);
54
+ expect(rendered.container).toMatchSnapshot();
55
+ });
56
+
57
+ it("renders correctly with SEARCH route", async () => {
58
+ const rendered = render(<SearchRoutes />, {
59
+ routes: [SEARCH],
60
+ });
61
+ await waitForLoad(rendered);
62
+ expect(rendered.container).toMatchSnapshot();
63
+ });
64
+
65
+ it("renders correctly with SEARCH_RESULTS route", async () => {
66
+ const rendered = render(<SearchRoutes />, {
67
+ routes: [SEARCH_RESULTS],
68
+ });
69
+ await waitForLoad(rendered);
70
+ expect(rendered.container).toMatchSnapshot();
71
+ });
72
+
73
+ it("renders correctly with SEARCH_CONCEPTS route", async () => {
74
+ const rendered = render(<SearchRoutes />, {
75
+ routes: [SEARCH_CONCEPTS],
76
+ });
77
+ await waitForLoad(rendered);
78
+ expect(rendered.container).toMatchSnapshot();
79
+ });
80
+
81
+ it("renders correctly with SEARCH_INGESTS route", async () => {
82
+ const rendered = render(<SearchRoutes />, {
83
+ routes: [SEARCH_INGESTS],
84
+ });
85
+ await waitForLoad(rendered);
86
+ expect(rendered.container).toMatchSnapshot();
87
+ });
88
+
89
+ it("renders correctly with SEARCH_STRUCTURES route", async () => {
90
+ const rendered = render(<SearchRoutes />, {
91
+ routes: [SEARCH_STRUCTURES],
92
+ });
93
+ await waitForLoad(rendered);
94
+ expect(rendered.container).toMatchSnapshot();
95
+ });
96
+
97
+ it("renders correctly with ELASTICINDEXES route", async () => {
98
+ const rendered = render(<SearchRoutes />, {
99
+ routes: [ELASTICINDEXES],
100
+ });
101
+ await waitForLoad(rendered);
102
+ expect(rendered.container).toMatchSnapshot();
103
+ });
104
+
105
+ it("renders unauthorized component when not authorized", async () => {
106
+ useAuthorized.mockReturnValueOnce(false);
107
+
108
+ const rendered = render(<SearchRoutes />, {
109
+ routes: [ELASTICINDEXES],
110
+ });
111
+ await waitForLoad(rendered);
112
+ expect(rendered.container).toMatchSnapshot();
13
113
  });
14
114
  });
@@ -1,11 +1,12 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import { waitFor } from "@testing-library/react";
4
3
  import { SearchTabs } from "../SearchTabs";
5
4
 
6
5
  jest.mock("@truedat/core/hooks", () => ({
7
6
  useAuthorized: jest.fn(() => true),
8
- useActiveRoute: jest.fn(param => (param === "/search/results" ? true : false))
7
+ useActiveRoute: jest.fn((param) =>
8
+ param === "/search/results" ? true : false
9
+ ),
9
10
  }));
10
11
 
11
12
  describe("<SearchTabs />", () => {
@@ -16,9 +17,9 @@ describe("<SearchTabs />", () => {
16
17
  "tabs.se.all": "All",
17
18
  "tabs.se.concepts": "Concepts",
18
19
  "tabs.se.structures": "Structures",
19
- "tabs.se.ingests": "Ingests"
20
- }
21
- }
20
+ "tabs.se.ingests": "Ingests",
21
+ },
22
+ },
22
23
  };
23
24
 
24
25
  it("matches the latest snapshot", async () => {
@@ -1,40 +1,24 @@
1
- import React from "react";
2
- import { render } from "@truedat/test/render";
3
- import { waitFor } from "@testing-library/react";
1
+ import { render, waitForLoad } from "@truedat/test/render";
4
2
  import { SearchTabs } from "../SearchTabs";
5
3
 
6
4
  jest.mock("@truedat/core/hooks", () => ({
7
5
  useAuthorized: jest.fn(
8
- params =>
6
+ (params) =>
9
7
  params.includes("all") || params.includes("business_glossary_view")
10
8
  ),
11
- useActiveRoute: jest.fn(params => params === "/search/results")
9
+ useActiveRoute: jest.fn((params) => params === "/search/results"),
12
10
  }));
13
11
 
14
12
  describe("<SearchTabs />", () => {
15
13
  const props = { indices: ["concepts", "ingests", "structures"] };
16
- const renderOpts = {
17
- messages: {
18
- en: {
19
- "tabs.se.all": "All",
20
- "tabs.se.concepts": "Concepts",
21
- "tabs.se.structures": "Structures",
22
- "tabs.se.ingests": "Ingests"
23
- }
24
- }
25
- };
26
14
 
27
15
  it("show all and Concepts tabs, structures and Ingest tabs are removed", async () => {
28
- const { getByText, findAllByText } = render(
29
- <SearchTabs {...props} />,
30
- renderOpts
31
- );
16
+ const rendered = render(<SearchTabs {...props} />);
17
+ await waitForLoad(rendered);
32
18
 
33
- await waitFor(
34
- () => expect(getByText(/All/)).not.toBeNull(),
35
- expect(getByText(/Concepts/)).not.toBeNull(),
36
- expect(findAllByText(/Structures/)).toMatchObject({}),
37
- expect(findAllByText(/Ingests/)).toMatchObject({})
38
- );
19
+ expect(rendered.getByText(/all/i)).toBeInTheDocument();
20
+ expect(rendered.getByText(/concepts/i)).toBeInTheDocument();
21
+ expect(rendered.queryByText(/structures/i)).not.toBeInTheDocument();
22
+ expect(rendered.queryByText(/ingests/i)).not.toBeInTheDocument();
39
23
  });
40
24
  });
@@ -1,28 +1,35 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`<CardResult /> it matches the last snapshot 1`] = `
4
- <Card
5
- className="search result"
6
- description="My description"
7
- header={
8
- <div>
9
- <Link
10
- to="/foo"
4
+ <div>
5
+ <div
6
+ class="ui card search result"
7
+ >
8
+ <div
9
+ class="content"
10
+ >
11
+ <div>
12
+ <a
13
+ data-discover="true"
14
+ href="/foo"
15
+ >
16
+ My header
17
+ </a>
18
+ <p>
19
+ business_concept.search.description
20
+ </p>
21
+ </div>
22
+ <div
23
+ class="meta"
11
24
  >
12
- My header
13
- </Link>
14
- <p>
15
- <Memo(MemoizedFormattedMessage)
16
- id="business_concept.search.description"
17
- values={
18
- {
19
- "header": "My header",
20
- }
21
- }
22
- />
23
- </p>
25
+ levelOne &gt; levelTwo &gt; levelThree
26
+ </div>
27
+ <div
28
+ class="description"
29
+ >
30
+ My description
31
+ </div>
24
32
  </div>
25
- }
26
- meta="levelOne > levelTwo > levelThree"
27
- />
33
+ </div>
34
+ </div>
28
35
  `;
@@ -1,6 +1,6 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`<ElasticIndexes /> matches the last snapshot 1`] = `
3
+ exports[`<ElasticIndexes /> matches the latest snapshot 1`] = `
4
4
  <div>
5
5
  <div
6
6
  class="ui segment"
@@ -26,17 +26,6 @@ exports[`<ElasticIndexes /> matches the last snapshot 1`] = `
26
26
  <div
27
27
  class="dimmable"
28
28
  >
29
- <div
30
- class="ui inverted dimmer"
31
- >
32
- <div
33
- class="content"
34
- >
35
- <div
36
- class="ui loader"
37
- />
38
- </div>
39
- </div>
40
29
  <table
41
30
  class="ui table"
42
31
  >
@@ -9,9 +9,8 @@ exports[`<Search /> it matches the last snapshot 1`] = `
9
9
  class="ui icon input custom"
10
10
  >
11
11
  <input
12
- placeholder="Search"
12
+ placeholder="search.input.placeholder"
13
13
  type="text"
14
- value=""
15
14
  />
16
15
  <i
17
16
  aria-hidden="true"
@@ -23,9 +22,10 @@ exports[`<Search /> it matches the last snapshot 1`] = `
23
22
  >
24
23
  <a
25
24
  class="item"
25
+ data-discover="true"
26
26
  href="/search/results"
27
27
  >
28
- All
28
+ tabs.se.all
29
29
  </a>
30
30
  </div>
31
31
  <div
@@ -41,13 +41,14 @@ exports[`<Search /> it matches the last snapshot 1`] = `
41
41
  <div
42
42
  class="header"
43
43
  >
44
- No results found
44
+ search.not_found.header
45
45
  </div>
46
46
  <a
47
47
  class="link pointer"
48
+ data-discover="true"
48
49
  href="/search"
49
50
  >
50
- Try another search
51
+ search.not_found.body
51
52
  </a>
52
53
  </div>
53
54
  </div>
@@ -1,18 +1,19 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`<SearchInput /> it matches the last snapshot 1`] = `
4
- <Input
5
- className="custom"
6
- icon={
7
- {
8
- "link": true,
9
- "name": "search",
10
- }
11
- }
12
- loading={false}
13
- onChange={[Function]}
14
- placeholder="search.input.placeholder"
15
- type="text"
16
- value="My Q"
17
- />
4
+ <div>
5
+ <div
6
+ class="ui icon input custom"
7
+ >
8
+ <input
9
+ placeholder="search.input.placeholder"
10
+ type="text"
11
+ value="My Q"
12
+ />
13
+ <i
14
+ aria-hidden="true"
15
+ class="search link icon"
16
+ />
17
+ </div>
18
+ </div>
18
19
  `;
@@ -1,3 +1,9 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`<SearchLoader /> it matches the last snapshot 1`] = `<Loading />`;
3
+ exports[`<SearchLoader /> it matches the last snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="ui active loader"
7
+ />
8
+ </div>
9
+ `;
@@ -15,13 +15,14 @@ exports[`<SearchResults /> it matches the last snapshot 1`] = `
15
15
  <div
16
16
  class="header"
17
17
  >
18
- No results found
18
+ search.not_found.header
19
19
  </div>
20
20
  <a
21
21
  class="link pointer"
22
+ data-discover="true"
22
23
  href="/search"
23
24
  >
24
- Try another search
25
+ search.not_found.body
25
26
  </a>
26
27
  </div>
27
28
  </div>