@truedat/dq 7.14.1 → 7.14.3

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": "@truedat/dq",
3
- "version": "7.14.1",
3
+ "version": "7.14.3",
4
4
  "description": "Truedat Web Data Quality Module",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -53,7 +53,7 @@
53
53
  "@testing-library/jest-dom": "^6.6.3",
54
54
  "@testing-library/react": "^16.3.0",
55
55
  "@testing-library/user-event": "^14.6.1",
56
- "@truedat/test": "7.14.1",
56
+ "@truedat/test": "7.14.3",
57
57
  "identity-obj-proxy": "^3.0.0",
58
58
  "jest": "^29.7.0",
59
59
  "redux-saga-test-plan": "^4.0.6"
@@ -86,5 +86,5 @@
86
86
  "semantic-ui-react": "^3.0.0-beta.2",
87
87
  "swr": "^2.3.3"
88
88
  },
89
- "gitHead": "afc55f553bb99ed37bfcc85fc83ba815d48b4769"
89
+ "gitHead": "f8b2f517aa25cf1eab47a89b17e0b08dfe6c8a26"
90
90
  }
@@ -16,7 +16,18 @@ export const ImplementationStructuresNew = ({
16
16
  creatingImplementationStructure,
17
17
  implementation,
18
18
  createImplementationStructure,
19
+ canCreateLink,
19
20
  }) => {
21
+ if (!canCreateLink) {
22
+ window.location.replace(
23
+ linkTo.IMPLEMENTATION_STRUCTURES({
24
+ id: implementation.rule_id,
25
+ implementation_id: implementation.id,
26
+ })
27
+ );
28
+ return null;
29
+ }
30
+
20
31
  const { formatMessage } = useIntl();
21
32
  const [selectedTarget, setSelectedTarget] = useState(null);
22
33
  const [type, setType] = useState("dataset");
@@ -80,12 +91,14 @@ export const ImplementationStructuresNew = ({
80
91
  key="datasetSelector"
81
92
  onSelect={handleTargetSelected}
82
93
  defaultFilters={{ "class.raw": ["table"] }}
94
+ withLinkStructures={true}
83
95
  />
84
96
  ) : (
85
97
  <StructureSelector
86
98
  key="nonDatasetSelector"
87
99
  onSelect={handleTargetSelected}
88
100
  defaultFilters={{ "class.raw": ["field"] }}
101
+ withLinkStructures={true}
89
102
  />
90
103
  )
91
104
  }
@@ -112,11 +125,13 @@ ImplementationStructuresNew.propTypes = {
112
125
  implementation: PropTypes.object,
113
126
  creatingImplementationStructure: PropTypes.bool,
114
127
  createImplementationStructure: PropTypes.func,
128
+ canCreateLink: PropTypes.bool,
115
129
  };
116
130
 
117
131
  const mapStateToProps = (state) => ({
118
132
  creatingImplementationStructure: state.creatingImplementationStructure,
119
133
  implementation: state.ruleImplementation,
134
+ canCreateLink: _.propOr(false, "link_structure")(state.implementationActions),
120
135
  });
121
136
 
122
137
  export default connect(mapStateToProps, { createImplementationStructure })(
@@ -0,0 +1,34 @@
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import { ImplementationStructureLinksActions } from "../ImplementationStructureLinksActions";
3
+
4
+ describe("<ImplementationStructureLinksActions />", () => {
5
+ it("renders button when implementation_id is present and canCreateLink is true", async () => {
6
+ const props = {
7
+ implementation_id: 1,
8
+ canCreateLink: true,
9
+ };
10
+ const rendered = render(<ImplementationStructureLinksActions {...props} />);
11
+ await waitForLoad(rendered);
12
+ expect(rendered.getByText("links.actions.create")).toBeInTheDocument();
13
+ });
14
+
15
+ it("does not render button when canCreateLink is false", async () => {
16
+ const props = {
17
+ implementation_id: 1,
18
+ canCreateLink: false,
19
+ };
20
+ const rendered = render(<ImplementationStructureLinksActions {...props} />);
21
+ await waitForLoad(rendered);
22
+ expect(rendered.queryByText("links.actions.create")).not.toBeInTheDocument();
23
+ });
24
+
25
+ it("does not render button when implementation_id is missing", async () => {
26
+ const props = {
27
+ implementation_id: null,
28
+ canCreateLink: true,
29
+ };
30
+ const rendered = render(<ImplementationStructureLinksActions {...props} />);
31
+ await waitForLoad(rendered);
32
+ expect(rendered.queryByText("links.actions.create")).not.toBeInTheDocument();
33
+ });
34
+ });
@@ -1,6 +1,15 @@
1
1
  import { render, waitForLoad } from "@truedat/test/render";
2
2
  import { ImplementationStructuresNew } from "../ImplementationStructuresNew";
3
3
 
4
+ jest.mock("@truedat/core/routes", () => ({
5
+ linkTo: {
6
+ IMPLEMENTATION_STRUCTURES: jest.fn(
7
+ ({ id, implementation_id }) =>
8
+ `/implementations/${id}/structures/${implementation_id}`
9
+ ),
10
+ },
11
+ }));
12
+
4
13
  jest.mock("@truedat/dd/hooks/useStructures", () => {
5
14
  const originalModule = jest.requireActual("@truedat/dd/hooks/useStructures");
6
15
  const structures = [1, 2, 3].map((id) => ({
@@ -41,14 +50,46 @@ jest.mock("@truedat/dd/hooks/useStructures", () => {
41
50
  });
42
51
 
43
52
  describe("<ImplementationStructuresNew />", () => {
53
+ const originalLocation = window.location;
54
+
55
+ beforeAll(() => {
56
+ delete window.location;
57
+ window.location = { replace: jest.fn() };
58
+ });
59
+
60
+ afterAll(() => {
61
+ window.location = originalLocation;
62
+ });
63
+
64
+ afterEach(() => {
65
+ jest.clearAllMocks();
66
+ });
67
+
44
68
  it("matches the latest snapshot", async () => {
45
69
  const props = {
46
70
  implementation: {},
47
71
  creatingImplementationStructure: false,
48
72
  createImplementationStructure: jest.fn(),
73
+ canCreateLink: true,
49
74
  };
50
75
  const rendered = render(<ImplementationStructuresNew {...props} />);
51
76
  await waitForLoad(rendered);
52
77
  expect(rendered.container).toMatchSnapshot();
53
78
  });
79
+
80
+ it("redirects when canCreateLink is false", () => {
81
+ const props = {
82
+ implementation: { id: 100, rule_id: 200 },
83
+ creatingImplementationStructure: false,
84
+ createImplementationStructure: jest.fn(),
85
+ canCreateLink: false,
86
+ };
87
+
88
+ const rendered = render(<ImplementationStructuresNew {...props} />);
89
+
90
+ expect(window.location.replace).toHaveBeenCalledWith(
91
+ "/implementations/200/structures/100"
92
+ );
93
+ expect(rendered.container).toBeEmptyDOMElement();
94
+ });
54
95
  });