@truedat/bg 6.3.2 → 6.3.4

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 (113) hide show
  1. package/package.json +6 -6
  2. package/src/concepts/api.js +3 -7
  3. package/src/concepts/components/ConceptActions.js +1 -0
  4. package/src/concepts/components/ConceptCreate.js +6 -4
  5. package/src/concepts/components/ConceptRoutes.js +10 -33
  6. package/src/concepts/components/Concepts.js +25 -16
  7. package/src/concepts/components/ConceptsActions.js +8 -14
  8. package/src/concepts/components/ConceptsBulkUpdate.js +25 -64
  9. package/src/concepts/components/ConceptsLabelResults.js +13 -26
  10. package/src/concepts/components/ConceptsLinksManagement.js +6 -92
  11. package/src/concepts/components/ConceptsPagination.js +13 -11
  12. package/src/concepts/components/ConceptsPanel.js +51 -22
  13. package/src/concepts/components/ConceptsTable.js +77 -106
  14. package/src/concepts/components/ConceptsUpdateButton.js +49 -37
  15. package/src/concepts/components/DomainConcepts.js +2 -11
  16. package/src/concepts/components/LinkedMessage.js +81 -0
  17. package/src/concepts/components/__tests__/ConceptLinksManagement.spec.js +60 -12
  18. package/src/concepts/components/__tests__/Concepts.spec.js +66 -11
  19. package/src/concepts/components/__tests__/ConceptsActions.spec.js +47 -3
  20. package/src/concepts/components/__tests__/ConceptsBulkUpdate.spec.js +7 -3
  21. package/src/concepts/components/__tests__/ConceptsLabelResults.spec.js +34 -4
  22. package/src/concepts/components/__tests__/ConceptsPanel.spec.js +59 -13
  23. package/src/concepts/components/__tests__/ConceptsTable.spec.js +53 -6
  24. package/src/concepts/components/__tests__/ConceptsUpdateButton.spec.js +26 -13
  25. package/src/concepts/components/__tests__/__snapshots__/ConceptLinksManagement.spec.js.snap +164 -8
  26. package/src/concepts/components/__tests__/__snapshots__/Concepts.spec.js.snap +284 -34
  27. package/src/concepts/components/__tests__/__snapshots__/ConceptsActions.spec.js.snap +1 -1
  28. package/src/concepts/components/__tests__/__snapshots__/ConceptsPanel.spec.js.snap +125 -2
  29. package/src/concepts/components/__tests__/__snapshots__/ConceptsTable.spec.js.snap +28 -44
  30. package/src/concepts/components/__tests__/__snapshots__/ConceptsUpdateButton.spec.js.snap +10 -47
  31. package/src/concepts/hooks/useConcepts.js +34 -0
  32. package/src/concepts/reducers/bulkUpdateQueryInfo.js +12 -0
  33. package/src/concepts/reducers/index.js +2 -26
  34. package/src/concepts/relations/components/ConceptRelationsRoutes.js +39 -35
  35. package/src/concepts/relations/components/ConceptSelector.js +37 -31
  36. package/src/concepts/relations/components/__tests__/ConceptRelationForm.spec.js +63 -23
  37. package/src/concepts/relations/components/__tests__/ConceptSelector.spec.js +74 -41
  38. package/src/concepts/relations/components/__tests__/ConceptSelector2.spec.js +72 -0
  39. package/src/concepts/relations/components/__tests__/__snapshots__/ConceptRelationForm.spec.js.snap +44 -8
  40. package/src/concepts/relations/components/__tests__/__snapshots__/ConceptSelector.spec.js.snap +44 -27
  41. package/src/concepts/routines.js +2 -29
  42. package/src/concepts/sagas/__tests__/bulkUpdate.spec.js +6 -10
  43. package/src/concepts/sagas/__tests__/downloadConcepts.spec.js +4 -8
  44. package/src/concepts/sagas/bulkUpdate.js +6 -5
  45. package/src/concepts/sagas/downloadConcepts.js +3 -4
  46. package/src/concepts/sagas/index.js +2 -17
  47. package/src/concepts/selectors/getConceptColumns.js +12 -21
  48. package/src/concepts/selectors/index.js +1 -7
  49. package/src/concepts/utils/filterOptions.js +6 -5
  50. package/src/concepts/components/ConceptFilters.js +0 -20
  51. package/src/concepts/components/ConceptFiltersLoader.js +0 -27
  52. package/src/concepts/components/ConceptSelectedFilters.js +0 -29
  53. package/src/concepts/components/ConceptSelectedFiltersDefault.js +0 -42
  54. package/src/concepts/components/ConceptSelectedFiltersPending.js +0 -41
  55. package/src/concepts/components/ConceptSelectedFiltersPublished.js +0 -73
  56. package/src/concepts/components/ConceptUserFiltersLoader.js +0 -27
  57. package/src/concepts/components/ConceptsLoader.js +0 -38
  58. package/src/concepts/components/ConceptsSearch.js +0 -32
  59. package/src/concepts/components/__tests__/ConceptFilters.spec.js +0 -19
  60. package/src/concepts/components/__tests__/ConceptSelectedFilters.spec.js +0 -10
  61. package/src/concepts/components/__tests__/ConceptUserFiltersLoader.spec.js +0 -27
  62. package/src/concepts/components/__tests__/ConceptsLoader.spec.js +0 -34
  63. package/src/concepts/components/__tests__/__snapshots__/ConceptFilters.spec.js.snap +0 -47
  64. package/src/concepts/components/__tests__/__snapshots__/ConceptSelectedFilters.spec.js.snap +0 -9
  65. package/src/concepts/components/__tests__/__snapshots__/ConceptUserFiltersLoader.spec.js.snap +0 -3
  66. package/src/concepts/reducers/__tests__/conceptActiveFilters.spec.js +0 -83
  67. package/src/concepts/reducers/__tests__/conceptCount.spec.js +0 -33
  68. package/src/concepts/reducers/__tests__/conceptFilters.spec.js +0 -49
  69. package/src/concepts/reducers/__tests__/conceptFiltersLoading.spec.js +0 -28
  70. package/src/concepts/reducers/__tests__/conceptQuery.spec.js +0 -75
  71. package/src/concepts/reducers/__tests__/conceptSelectedFilter.spec.js +0 -66
  72. package/src/concepts/reducers/__tests__/conceptSelectedUserFilter.spec.js +0 -53
  73. package/src/concepts/reducers/__tests__/conceptUserFilters.spec.js +0 -76
  74. package/src/concepts/reducers/__tests__/concepts.spec.js +0 -40
  75. package/src/concepts/reducers/__tests__/conceptsActions.spec.js +0 -38
  76. package/src/concepts/reducers/__tests__/conceptsLoading.spec.js +0 -32
  77. package/src/concepts/reducers/__tests__/conceptsPageSize.spec.js +0 -33
  78. package/src/concepts/reducers/__tests__/previousConceptQuery.spec.js +0 -23
  79. package/src/concepts/reducers/conceptActiveFilters.js +0 -58
  80. package/src/concepts/reducers/conceptCount.js +0 -20
  81. package/src/concepts/reducers/conceptFilters.js +0 -21
  82. package/src/concepts/reducers/conceptFiltersLoading.js +0 -14
  83. package/src/concepts/reducers/conceptQuery.js +0 -60
  84. package/src/concepts/reducers/conceptSelectedFilter.js +0 -34
  85. package/src/concepts/reducers/conceptSelectedUserFilter.js +0 -31
  86. package/src/concepts/reducers/conceptUserFilters.js +0 -36
  87. package/src/concepts/reducers/concepts.js +0 -21
  88. package/src/concepts/reducers/conceptsActions.js +0 -24
  89. package/src/concepts/reducers/conceptsLoading.js +0 -16
  90. package/src/concepts/reducers/conceptsPageSize.js +0 -16
  91. package/src/concepts/reducers/previousConceptQuery.js +0 -15
  92. package/src/concepts/sagas/__tests__/deleteConceptUserFilter.spec.js +0 -75
  93. package/src/concepts/sagas/__tests__/fetchConceptUserFilters.spec.js +0 -70
  94. package/src/concepts/sagas/__tests__/fetchConcepts.spec.js +0 -87
  95. package/src/concepts/sagas/__tests__/saveConceptFilters.spec.js +0 -78
  96. package/src/concepts/sagas/deleteConceptUserFilter.js +0 -34
  97. package/src/concepts/sagas/fecthConceptUserFilters.js +0 -30
  98. package/src/concepts/sagas/fetchConceptFilters.js +0 -29
  99. package/src/concepts/sagas/fetchConcepts.js +0 -27
  100. package/src/concepts/sagas/saveConceptFilters.js +0 -30
  101. package/src/concepts/selectors/__tests__/getConceptAvailableFilters.spec.js +0 -16
  102. package/src/concepts/selectors/__tests__/getConceptFilterTypes.spec.js +0 -19
  103. package/src/concepts/selectors/__tests__/getConceptSelectedFilterActiveValues.spec.js +0 -16
  104. package/src/concepts/selectors/__tests__/getConceptSelectedFilterValues.spec.js +0 -15
  105. package/src/concepts/selectors/__tests__/getConceptSelectedFilters.spec.js +0 -15
  106. package/src/concepts/selectors/__tests__/mapSelectedFilterStateToPropsByStatus.spec.js +0 -37
  107. package/src/concepts/selectors/getConceptAvailableFilters.js +0 -15
  108. package/src/concepts/selectors/getConceptFilterTypes.js +0 -7
  109. package/src/concepts/selectors/getConceptSelectedFilterActiveValues.js +0 -9
  110. package/src/concepts/selectors/getConceptSelectedFilterValues.js +0 -12
  111. package/src/concepts/selectors/getConceptSelectedFilters.js +0 -7
  112. package/src/concepts/selectors/getPreviousConceptQuery.js +0 -1
  113. package/src/concepts/selectors/mapSelectedFilterStateToPropsByStatus.js +0 -47
@@ -0,0 +1,81 @@
1
+ import React from "react";
2
+ import PropTypes from "prop-types";
3
+ import { useIntl } from "react-intl";
4
+ import { Message } from "semantic-ui-react";
5
+
6
+ const STATUS_PENDING = "pending";
7
+ const STATUS_CREATED = "created";
8
+ const STATUS_DELETED = "deleted";
9
+
10
+ const LinkedMessage = ({
11
+ selectedSourceConcept,
12
+ selectedTargetConcept,
13
+ selectedLinkType,
14
+ selectedStructure,
15
+ selectedTag,
16
+ status,
17
+ }) => {
18
+ const { formatMessage } = useIntl();
19
+
20
+ const messagesMap = {
21
+ [STATUS_PENDING]: formatMessage({ id: "concept.events.relation_creating" }),
22
+ [STATUS_DELETED]: formatMessage({ id: "concept.events.relation_deleted" }),
23
+ [STATUS_CREATED]: formatMessage({ id: "concept.events.relation_created" }),
24
+ };
25
+
26
+ return (
27
+ <Message success={status !== STATUS_PENDING} floating>
28
+ <Message.Header>{messagesMap[status]}</Message.Header>
29
+ <Message.List>
30
+ {selectedSourceConcept ? (
31
+ <Message.Item>
32
+ {formatMessage({ id: "conceptRelations.from" })}
33
+ {": "} {selectedSourceConcept.name}
34
+ </Message.Item>
35
+ ) : null}
36
+ {selectedStructure ? (
37
+ <Message.Item>
38
+ {formatMessage({ id: "conceptRelations.to" })}
39
+ {": "}
40
+ {selectedStructure.name}
41
+ </Message.Item>
42
+ ) : selectedTargetConcept ? (
43
+ <Message.Item>
44
+ {formatMessage({ id: "conceptRelations.to" })}
45
+ {": "}
46
+ {selectedTargetConcept.name}
47
+ </Message.Item>
48
+ ) : null}
49
+ {selectedTag ? (
50
+ <Message.Item>
51
+ {formatMessage({ id: "conceptRelations.tag" })}
52
+ {": "}
53
+ {selectedLinkType === "structures"
54
+ ? formatMessage({
55
+ id: selectedTag.text,
56
+ defaultMessage: selectedTag.text,
57
+ })
58
+ : formatMessage({
59
+ id: `source.${selectedTag.text}`,
60
+ defaultMessage: formatMessage({
61
+ id: selectedTag.text,
62
+ defaultMessage: selectedTag.text,
63
+ }),
64
+ })}
65
+ </Message.Item>
66
+ ) : null}
67
+ </Message.List>
68
+ </Message>
69
+ );
70
+ };
71
+
72
+ LinkedMessage.propTypes = {
73
+ selectedSourceConcept: PropTypes.object,
74
+ selectedStructure: PropTypes.object,
75
+ selectedTargetConcept: PropTypes.object,
76
+ selectedLinkType: PropTypes.string,
77
+ selectedTag: PropTypes.object,
78
+ status: PropTypes.string,
79
+ };
80
+
81
+ export default LinkedMessage;
@@ -4,6 +4,62 @@ import userEvent from "@testing-library/user-event";
4
4
  import ConceptsLinksManagement from "../ConceptsLinksManagement";
5
5
  import en from "../../../messages/en";
6
6
 
7
+ const data = {
8
+ data: [
9
+ {
10
+ _actions: { can_create_structure_link: true },
11
+ id: 1,
12
+ business_concept_id: 1111,
13
+ name: "foo",
14
+ domain: { id: 1, name: "bar" },
15
+ status: "draft",
16
+ links: [
17
+ {
18
+ id: 745,
19
+ resource_id: 4569480,
20
+ resource_type: "data_structure",
21
+ },
22
+ ],
23
+ },
24
+ ],
25
+ };
26
+
27
+ const filterData = {
28
+ data: {
29
+ some: {
30
+ values: ["some_xxx", "some_yyy", "some_xwy"],
31
+ },
32
+ },
33
+ };
34
+
35
+ jest.mock("@truedat/bg/concepts/hooks/useConcepts", () => {
36
+ const originalModule = jest.requireActual(
37
+ "@truedat/bg/concepts/hooks/useConcepts"
38
+ );
39
+
40
+ return {
41
+ __esModule: true,
42
+ ...originalModule,
43
+ useConceptFilters: () => ({
44
+ trigger: () => ({
45
+ then: (callback) =>
46
+ callback({
47
+ data: filterData,
48
+ }),
49
+ }),
50
+ }),
51
+ useConceptVersionsSearch: () => ({
52
+ trigger: () => ({
53
+ then: (callback) =>
54
+ callback({
55
+ data,
56
+ headers: { "x-total-count": 123 },
57
+ }),
58
+ }),
59
+ }),
60
+ };
61
+ });
62
+
7
63
  const messages = {
8
64
  en: {
9
65
  ...en,
@@ -12,6 +68,7 @@ const messages = {
12
68
  "search.clear_filters": "clear filters",
13
69
  "search.applied_filters": "apply filters",
14
70
  "structures.not_found.body": "",
71
+ "search.placeholder": "Search concepts...",
15
72
  },
16
73
  };
17
74
 
@@ -21,15 +78,6 @@ const link = {
21
78
  resource_type: "data_structure",
22
79
  };
23
80
 
24
- const concept = {
25
- _actions: { can_create_structure_link: true },
26
- id: 1,
27
- business_concept_id: 1111,
28
- name: "foo",
29
- domain: { id: 1, name: "bar" },
30
- status: "draft",
31
- links: [link],
32
- };
33
81
  const structure = {
34
82
  id: 4569480,
35
83
  name: "Contrato",
@@ -53,18 +101,18 @@ describe("<ConceptsLinksManagement />", () => {
53
101
  state: {
54
102
  loading: false,
55
103
  links: [link],
56
- concepts: [concept],
57
104
  structures: [structure],
58
105
  structuresRows: [structure],
59
106
  conceptActiveFilters: { filter: "some" },
60
107
  },
61
108
  };
62
109
 
63
- it("matches the latest snapshot", () => {
64
- const { container } = render(
110
+ it("matches the latest snapshot", async () => {
111
+ const { container, queryByText } = render(
65
112
  <ConceptsLinksManagement {...props} />,
66
113
  renderOpts
67
114
  );
115
+ userEvent.click(await queryByText(/some/));
68
116
  expect(container).toMatchSnapshot();
69
117
  });
70
118
 
@@ -1,28 +1,83 @@
1
1
  import React from "react";
2
- import { shallow } from "enzyme";
2
+ import { render } from "@truedat/test/render";
3
3
  import { Concepts } from "../Concepts";
4
4
 
5
+ const data = {
6
+ data: [
7
+ {
8
+ id: 1,
9
+ name: "s1",
10
+ description: "dd",
11
+ version: "vs",
12
+ status: "st",
13
+ last_change_at: "2020-01-01T00:00:00.000Z",
14
+ },
15
+ ],
16
+ };
17
+
18
+ jest.mock("@truedat/bg/concepts/hooks/useConcepts", () => {
19
+ const originalModule = jest.requireActual(
20
+ "@truedat/bg/concepts/hooks/useConcepts"
21
+ );
22
+
23
+ return {
24
+ __esModule: true,
25
+ ...originalModule,
26
+ useConceptFilters: () => ({
27
+ trigger: () => ({
28
+ then: (callback) =>
29
+ callback({
30
+ data: [],
31
+ }),
32
+ }),
33
+ }),
34
+ useConceptVersionsSearch: () => ({
35
+ trigger: () => ({
36
+ then: (callback) =>
37
+ callback({
38
+ data,
39
+ headers: { "x-total-count": 123 },
40
+ }),
41
+ }),
42
+ }),
43
+ };
44
+ });
45
+
46
+ const messages = {
47
+ en: {
48
+ "search.placeholder": "Search concepts...",
49
+ "concepts.searching": "Searching...",
50
+ "concepts.search.results.empty": "No concepts found",
51
+ "concepts.retrieved.results": "{count} concepts found",
52
+ "concepts.props.last_change_at": "Last modification date",
53
+ "concepts.props.link_count": "Link to field",
54
+ "concepts.props.rule_count": "Quality rules",
55
+ "concepts.props.domain": "Domain",
56
+ "concepts.props.name": "Term",
57
+ },
58
+ };
59
+
5
60
  describe("<Concepts />", () => {
6
61
  it("matches the latest snapshot", () => {
7
- const concepts = [
8
- { id: 1, name: "s1", description: "dd", version: "vs", status: "st" }
9
- ];
10
- const loading = false;
62
+ const renderOpts = {
63
+ messages,
64
+ };
65
+
11
66
  const header = "concepts.header.manage";
12
67
  const subheader = "concepts.subheader.manage";
13
68
  const icon = "edit";
14
69
  const create = true;
15
70
  const update = true;
71
+ const defaultFilters = {};
16
72
  const props = {
17
- concepts,
18
- create,
19
- loading,
20
73
  header,
21
74
  subheader,
22
75
  icon,
23
- update
76
+ defaultFilters,
77
+ update,
78
+ create,
24
79
  };
25
- const wrapper = shallow(<Concepts {...props} />);
26
- expect(wrapper).toMatchSnapshot();
80
+ const { container } = render(<Concepts {...props} />, renderOpts);
81
+ expect(container).toMatchSnapshot();
27
82
  });
28
83
  });
@@ -1,11 +1,49 @@
1
1
  import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
3
4
  import { ConceptsActions } from "../ConceptsActions";
4
5
 
6
+ const data = {
7
+ _actions: {
8
+ create: { method: "POST" },
9
+ upload: { method: "POST" },
10
+ },
11
+ data: [],
12
+ };
13
+
14
+ const useFilters = () => ({
15
+ trigger: () => ({
16
+ then: (callback) =>
17
+ callback({
18
+ data: [],
19
+ }),
20
+ }),
21
+ });
22
+
23
+ const useSearch = () => ({
24
+ trigger: () => ({
25
+ then: (callback) =>
26
+ callback({
27
+ data,
28
+ headers: {},
29
+ }),
30
+ }),
31
+ });
32
+
33
+ const defaultFilters = {};
34
+
35
+ const searchProps = {
36
+ initialSortColumn: "name.raw",
37
+ initialSortDirection: "ascending",
38
+ useSearch: useSearch,
39
+ useFilters: useFilters,
40
+ userFiltersType: "business_concept_user_filters",
41
+ omitFilters: [],
42
+ translations: jest.fn(),
43
+ };
44
+
5
45
  describe("<ConceptsActions />", () => {
6
46
  const props = {
7
- createUrl: "/url/to/create/concept",
8
- conceptActionsLoaded: true,
9
47
  conceptsDownloading: true,
10
48
  create: true,
11
49
  upload: true,
@@ -17,6 +55,7 @@ describe("<ConceptsActions />", () => {
17
55
  "concepts.actions.create": "Create",
18
56
  "concepts.actions.download.tooltip": "Download",
19
57
  "concepts.actions.upload.tooltip": "concepts.actions.upload.tooltip",
58
+ "uploadModal.accept.publish": "Upload and publish",
20
59
  },
21
60
  },
22
61
  state: {
@@ -27,7 +66,12 @@ describe("<ConceptsActions />", () => {
27
66
  };
28
67
 
29
68
  it("matches the latest snapshot", () => {
30
- const { container } = render(<ConceptsActions {...props} />, renderOpts);
69
+ const { container } = render(
70
+ <SearchContextProvider {...searchProps} defaultFilters={defaultFilters}>
71
+ <ConceptsActions {...props} />
72
+ </SearchContextProvider>,
73
+ renderOpts
74
+ );
31
75
  expect(container).toMatchSnapshot();
32
76
  });
33
77
  });
@@ -20,8 +20,11 @@ const content = [
20
20
  const template = { name: "template1", id: 1, content: content };
21
21
 
22
22
  const state = {
23
- conceptCount: 1,
24
- concepts: [{ type: "template1" }],
23
+ bulkUpdateQueryInfo: {
24
+ conceptCount: 1,
25
+ concepts: [{ type: "template1" }],
26
+ searchParams: {},
27
+ },
25
28
  templates: [template],
26
29
  loading: false,
27
30
  templateLoading: false,
@@ -83,7 +86,8 @@ describe("<ConceptsBulkUpdate />", () => {
83
86
  await waitFor(() => {
84
87
  expect(dispatch).toHaveBeenLastCalledWith(
85
88
  bulkUpdate({
86
- update_attributes: { content: { field1: "abc123456" }, domain_id: 1 },
89
+ updateAttributes: { content: { field1: "abc123456" }, domain_id: 1 },
90
+ searchParams: {},
87
91
  })
88
92
  );
89
93
  });
@@ -1,12 +1,42 @@
1
1
  import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
- import { ConceptsLabelResults } from "../ConceptsLabelResults";
3
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
4
+ import ConceptsLabelResults from "../ConceptsLabelResults";
4
5
 
5
- describe("<ConceptsLabelResults />", () => {
6
- const props = { conceptCount: 22 };
6
+ const useFilters = jest.fn(() => ({
7
+ trigger: jest.fn(() => new Promise(() => {})),
8
+ isMutating: false,
9
+ }));
10
+
11
+ const useSearch = () => ({
12
+ trigger: () => ({
13
+ then: (callback) =>
14
+ callback({
15
+ data: [],
16
+ headers: { "x-total-count": 22 },
17
+ }),
18
+ }),
19
+ });
7
20
 
21
+ const defaultFilters = {};
22
+
23
+ const searchProps = {
24
+ initialSortColumn: "name.raw",
25
+ initialSortDirection: "ascending",
26
+ useSearch: useSearch,
27
+ useFilters: useFilters,
28
+ userFiltersType: "business_concept_user_filters",
29
+ omitFilters: [],
30
+ translations: jest.fn(),
31
+ };
32
+
33
+ describe("<ConceptsLabelResults />", () => {
8
34
  it("matches the latest snapshot", () => {
9
- const { container } = render(<ConceptsLabelResults {...props} />);
35
+ const { container } = render(
36
+ <SearchContextProvider {...searchProps} defaultFilters={defaultFilters}>
37
+ <ConceptsLabelResults />
38
+ </SearchContextProvider>
39
+ );
10
40
  expect(container).toMatchSnapshot();
11
41
  });
12
42
  });
@@ -2,24 +2,70 @@ import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
3
  import ConceptsPanel from "../ConceptsPanel";
4
4
 
5
- const renderOpts = {
6
- state: {
7
- conceptCount: 123,
8
- concepts: [
9
- {
10
- id: 1,
11
- name: "concept",
12
- domain: { name: "domain" },
13
- status: "published",
14
- last_change_at: "2020-01-01T00:00:00.000Z",
15
- },
16
- ],
5
+ const data = {
6
+ data: [
7
+ {
8
+ id: 1,
9
+ name: "concept",
10
+ domain: { name: "domain" },
11
+ status: "published",
12
+ last_change_at: "2020-01-01T00:00:00.000Z",
13
+ },
14
+ ],
15
+ };
16
+
17
+ jest.mock("@truedat/bg/concepts/hooks/useConcepts", () => {
18
+ const originalModule = jest.requireActual(
19
+ "@truedat/bg/concepts/hooks/useConcepts"
20
+ );
21
+
22
+ return {
23
+ __esModule: true,
24
+ ...originalModule,
25
+ useConceptFilters: () => ({
26
+ trigger: () => ({
27
+ then: (callback) =>
28
+ callback({
29
+ data: [],
30
+ }),
31
+ }),
32
+ }),
33
+ useConceptVersionsSearch: () => ({
34
+ trigger: () => ({
35
+ then: (callback) =>
36
+ callback({
37
+ data,
38
+ headers: { "x-total-count": 123 },
39
+ }),
40
+ }),
41
+ }),
42
+ };
43
+ });
44
+
45
+ const messages = {
46
+ en: {
47
+ "search.placeholder": "Search concepts...",
48
+ "concepts.searching": "Searching...",
49
+ "concepts.search.results.empty": "No concepts found",
50
+ "concepts.retrieved.results": "{count} concepts found",
51
+ "concepts.props.last_change_at": "Last modification date",
52
+ "concepts.props.link_count": "Link to field",
53
+ "concepts.props.rule_count": "Quality rules",
54
+ "concepts.props.domain": "Domain",
55
+ "concepts.props.name": "Term",
17
56
  },
18
57
  };
19
58
 
59
+ const renderOpts = {
60
+ messages,
61
+ };
62
+
20
63
  describe("<ConceptsPanel />", () => {
64
+ const props = {
65
+ defaultFilters: {},
66
+ };
21
67
  it("matches latest snapshot", () => {
22
- const { container } = render(<ConceptsPanel />, renderOpts);
68
+ const { container } = render(<ConceptsPanel {...props} />, renderOpts);
23
69
  expect(container).toMatchSnapshot();
24
70
  });
25
71
  });
@@ -1,13 +1,60 @@
1
1
  import React from "react";
2
- import { shallow } from "enzyme";
2
+ import { render } from "@truedat/test/render";
3
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
3
4
  import { ConceptsTable } from "../ConceptsTable";
4
5
 
6
+ const data = {
7
+ data: [
8
+ {
9
+ id: 1,
10
+ name: "concept",
11
+ status: "draft",
12
+ last_change_at: "2020-01-01T00:00:00.000Z",
13
+ },
14
+ ],
15
+ };
16
+
17
+ const useFilters = () => ({
18
+ trigger: () => ({
19
+ then: (callback) =>
20
+ callback({
21
+ data: [],
22
+ }),
23
+ }),
24
+ });
25
+
26
+ const useSearch = () => ({
27
+ trigger: () => ({
28
+ then: (callback) =>
29
+ callback({
30
+ data,
31
+ headers: {},
32
+ }),
33
+ }),
34
+ });
35
+
36
+ const defaultFilters = {};
37
+
38
+ const searchProps = {
39
+ initialSortColumn: "name.raw",
40
+ initialSortDirection: "ascending",
41
+ useSearch: useSearch,
42
+ useFilters: useFilters,
43
+ userFiltersType: "business_concept_user_filters",
44
+ omitFilters: [],
45
+ translations: jest.fn(),
46
+ };
47
+
5
48
  describe("<ConceptsTable />", () => {
6
49
  it("matches the latest snapshot", () => {
7
- const columns = ["name", "status"].map(name => ({ name }));
8
- const concepts = [{ id: 1 }];
9
- const props = { columns, concepts };
10
- const wrapper = shallow(<ConceptsTable {...props} />);
11
- expect(wrapper).toMatchSnapshot();
50
+ const columns = ["name", "status"].map((name) => ({ name }));
51
+
52
+ const props = { columns };
53
+ const { container } = render(
54
+ <SearchContextProvider {...searchProps} defaultFilters={defaultFilters}>
55
+ <ConceptsTable {...props} />
56
+ </SearchContextProvider>
57
+ );
58
+ expect(container).toMatchSnapshot();
12
59
  });
13
60
  });
@@ -1,6 +1,6 @@
1
- // only admin user
2
1
  import React from "react";
3
- import { shallow } from "enzyme";
2
+ import { render } from "@truedat/test/render";
3
+ import SearchContext from "@truedat/core/search/SearchContext";
4
4
  import { ConceptsUpdateButton } from "../ConceptsUpdateButton";
5
5
 
6
6
  jest.mock("@truedat/core/hooks", () => ({
@@ -12,21 +12,34 @@ jest.mock("react-router-dom", () => ({
12
12
  useLocation: () => ({ pathname: "/concept" }),
13
13
  }));
14
14
 
15
+ const searchProps = {
16
+ allActiveFilters: {
17
+ template: ["Basic"],
18
+ },
19
+ count: 2,
20
+ filters: {},
21
+ loading: false,
22
+ filterParams: {},
23
+ searchData: [],
24
+ };
25
+
15
26
  describe("<ConceptsUpdateButton />", () => {
16
27
  it("button will appear disabled if template is empty", () => {
17
- const props = {
18
- updateUrl: "",
19
- };
20
- const wrapper = shallow(<ConceptsUpdateButton {...props} />);
21
- wrapper.find("Popup").props().content;
22
- expect(wrapper.find({ disabled: false }).length).toBe(1);
28
+ const { getByRole, debug } = render(
29
+ <SearchContext.Provider value={searchProps}>
30
+ <ConceptsUpdateButton />
31
+ </SearchContext.Provider>
32
+ );
33
+ debug();
34
+ expect(getByRole("button", { name: /Update/i })).toBeEnabled();
23
35
  });
24
36
 
25
37
  it("matches the latest snapshot", () => {
26
- const props = {
27
- updateUrl: "url",
28
- };
29
- const wrapper = shallow(<ConceptsUpdateButton {...props} />);
30
- expect(wrapper).toMatchSnapshot();
38
+ const { container } = render(
39
+ <SearchContext.Provider value={searchProps}>
40
+ <ConceptsUpdateButton />
41
+ </SearchContext.Provider>
42
+ );
43
+ expect(container).toMatchSnapshot();
31
44
  });
32
45
  });