@truedat/dd 7.12.2 → 7.12.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/dd",
|
|
3
|
-
"version": "7.12.
|
|
3
|
+
"version": "7.12.4",
|
|
4
4
|
"description": "Truedat Web Data Dictionary",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@testing-library/jest-dom": "^6.6.3",
|
|
49
49
|
"@testing-library/react": "^16.3.0",
|
|
50
50
|
"@testing-library/user-event": "^14.6.1",
|
|
51
|
-
"@truedat/test": "7.12.
|
|
51
|
+
"@truedat/test": "7.12.4",
|
|
52
52
|
"identity-obj-proxy": "^3.0.0",
|
|
53
53
|
"jest": "^29.7.0",
|
|
54
54
|
"redux-saga-test-plan": "^4.0.6"
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"svg-pan-zoom": "^3.6.2",
|
|
84
84
|
"swr": "^2.3.3"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "6e0e12074f41a48b5ff7a03e43ca41b3cda59b2d"
|
|
87
87
|
}
|
|
@@ -2,23 +2,25 @@ import { useState } from "react";
|
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { Button, Checkbox, Modal, Icon } from "semantic-ui-react";
|
|
4
4
|
import { useIntl } from "react-intl";
|
|
5
|
-
import {
|
|
5
|
+
import { STRUCTURE } from "@truedat/core/routes";
|
|
6
|
+
import { useDataStructureDownload } from "../hooks/useStructures";
|
|
6
7
|
|
|
7
8
|
export const StructureNotesDownloadButton = ({ structureId }) => {
|
|
8
9
|
const { formatMessage, locale } = useIntl();
|
|
9
10
|
const [open, setOpen] = useState(false);
|
|
10
|
-
const [selectedStatuses, setSelectedStatuses] = useState(["published"]);
|
|
11
11
|
const [includeChildren, setIncludeChildren] = useState(false);
|
|
12
12
|
|
|
13
13
|
const { trigger: triggerDownload, isMutating: isDownloading } =
|
|
14
|
-
|
|
14
|
+
useDataStructureDownload();
|
|
15
15
|
|
|
16
16
|
const handleDownload = () => {
|
|
17
17
|
triggerDownload({
|
|
18
|
-
|
|
19
|
-
statuses: selectedStatuses,
|
|
18
|
+
data_structure_id: structureId,
|
|
20
19
|
include_children: includeChildren,
|
|
21
|
-
lang: locale
|
|
20
|
+
lang: locale,
|
|
21
|
+
structure_url_schema: window.location.origin + STRUCTURE,
|
|
22
|
+
download_type: "editable",
|
|
23
|
+
note_type: "published",
|
|
22
24
|
});
|
|
23
25
|
setOpen(false);
|
|
24
26
|
};
|
|
@@ -2,7 +2,12 @@ import React from "react";
|
|
|
2
2
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
3
3
|
import { IntlProvider } from "react-intl";
|
|
4
4
|
import { StructureNotesDownloadButton } from "../StructureNotesDownloadButton";
|
|
5
|
-
import
|
|
5
|
+
import { useDataStructureDownload } from "../../hooks/useStructures";
|
|
6
|
+
|
|
7
|
+
// Mock del hook
|
|
8
|
+
jest.mock("../../hooks/useStructures", () => ({
|
|
9
|
+
useDataStructureDownload: jest.fn(),
|
|
10
|
+
}));
|
|
6
11
|
|
|
7
12
|
const messages = {
|
|
8
13
|
"structure.actions.downloadNotes": "Download notes",
|
|
@@ -20,20 +25,14 @@ const renderWithIntl = (component) => {
|
|
|
20
25
|
);
|
|
21
26
|
};
|
|
22
27
|
|
|
23
|
-
// Helper function to get checkbox by label text
|
|
24
|
-
const getCheckboxByLabel = (labelText) => {
|
|
25
|
-
const label = screen.getByText(labelText);
|
|
26
|
-
const checkboxContainer = label.closest(".ui.checkbox");
|
|
27
|
-
return checkboxContainer.querySelector("input[type='checkbox']");
|
|
28
|
-
};
|
|
29
|
-
|
|
30
28
|
describe("StructureNotesDownloadButton", () => {
|
|
31
29
|
const mockTrigger = jest.fn();
|
|
32
30
|
const mockStructureId = "123";
|
|
33
31
|
|
|
34
32
|
beforeEach(() => {
|
|
35
33
|
jest.clearAllMocks();
|
|
36
|
-
|
|
34
|
+
// Mock el hook correcto
|
|
35
|
+
useDataStructureDownload.mockReturnValue({
|
|
37
36
|
trigger: mockTrigger,
|
|
38
37
|
isMutating: false,
|
|
39
38
|
});
|
|
@@ -76,8 +75,11 @@ describe("StructureNotesDownloadButton", () => {
|
|
|
76
75
|
const button = screen.getByRole("button");
|
|
77
76
|
fireEvent.click(button);
|
|
78
77
|
|
|
79
|
-
const
|
|
80
|
-
expect(
|
|
78
|
+
const includeChildrenLabel = screen.getByText("Include direct children notes");
|
|
79
|
+
expect(includeChildrenLabel).toBeInTheDocument();
|
|
80
|
+
|
|
81
|
+
const checkbox = screen.getByRole("checkbox");
|
|
82
|
+
expect(checkbox).toBeInTheDocument();
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
it("allows toggling include children checkbox", () => {
|
|
@@ -90,16 +92,15 @@ describe("StructureNotesDownloadButton", () => {
|
|
|
90
92
|
const button = screen.getByRole("button");
|
|
91
93
|
fireEvent.click(button);
|
|
92
94
|
|
|
93
|
-
const
|
|
95
|
+
const checkbox = screen.getByRole("checkbox");
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
expect(includeChildrenCheckbox).not.toBeChecked();
|
|
97
|
+
expect(checkbox).not.toBeChecked();
|
|
97
98
|
|
|
98
|
-
fireEvent.click(
|
|
99
|
-
expect(
|
|
99
|
+
fireEvent.click(checkbox);
|
|
100
|
+
expect(checkbox).toBeChecked();
|
|
100
101
|
|
|
101
|
-
fireEvent.click(
|
|
102
|
-
expect(
|
|
102
|
+
fireEvent.click(checkbox);
|
|
103
|
+
expect(checkbox).not.toBeChecked();
|
|
103
104
|
});
|
|
104
105
|
|
|
105
106
|
it("calls trigger with correct parameters when download button is clicked", async () => {
|
|
@@ -112,20 +113,21 @@ describe("StructureNotesDownloadButton", () => {
|
|
|
112
113
|
const openButton = screen.getByRole("button");
|
|
113
114
|
fireEvent.click(openButton);
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
expect(includeChildrenCheckbox).toBeChecked();
|
|
116
|
+
const checkbox = screen.getByRole("checkbox");
|
|
117
|
+
fireEvent.click(checkbox);
|
|
118
|
+
expect(checkbox).toBeChecked();
|
|
119
119
|
|
|
120
|
-
const downloadButton = screen.getByRole("button", { name:
|
|
120
|
+
const downloadButton = screen.getByRole("button", { name: /download/i });
|
|
121
121
|
fireEvent.click(downloadButton);
|
|
122
122
|
|
|
123
123
|
await waitFor(() => {
|
|
124
124
|
expect(mockTrigger).toHaveBeenCalledWith({
|
|
125
|
-
|
|
125
|
+
data_structure_id: mockStructureId,
|
|
126
126
|
include_children: true,
|
|
127
127
|
lang: "en",
|
|
128
|
-
|
|
128
|
+
structure_url_schema: expect.stringContaining("http"),
|
|
129
|
+
download_type: "editable",
|
|
130
|
+
note_type: "published"
|
|
129
131
|
});
|
|
130
132
|
});
|
|
131
133
|
});
|
|
@@ -140,19 +142,20 @@ describe("StructureNotesDownloadButton", () => {
|
|
|
140
142
|
const openButton = screen.getByRole("button");
|
|
141
143
|
fireEvent.click(openButton);
|
|
142
144
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
expect(includeChildrenCheckbox).not.toBeChecked();
|
|
145
|
+
const checkbox = screen.getByRole("checkbox");
|
|
146
|
+
expect(checkbox).not.toBeChecked();
|
|
146
147
|
|
|
147
|
-
const downloadButton = screen.getByRole("button", { name:
|
|
148
|
+
const downloadButton = screen.getByRole("button", { name: /download/i });
|
|
148
149
|
fireEvent.click(downloadButton);
|
|
149
150
|
|
|
150
151
|
await waitFor(() => {
|
|
151
152
|
expect(mockTrigger).toHaveBeenCalledWith({
|
|
152
|
-
|
|
153
|
+
data_structure_id: mockStructureId,
|
|
153
154
|
include_children: false,
|
|
154
155
|
lang: "en",
|
|
155
|
-
|
|
156
|
+
structure_url_schema: expect.stringContaining("http"),
|
|
157
|
+
download_type: "editable",
|
|
158
|
+
note_type: "published"
|
|
156
159
|
});
|
|
157
160
|
});
|
|
158
161
|
});
|
|
@@ -170,7 +173,7 @@ describe("StructureNotesDownloadButton", () => {
|
|
|
170
173
|
const modalTitle = screen.getByText("Download Structure Notes");
|
|
171
174
|
expect(modalTitle).toBeInTheDocument();
|
|
172
175
|
|
|
173
|
-
const downloadButton = screen.getByRole("button", { name:
|
|
176
|
+
const downloadButton = screen.getByRole("button", { name: /download/i });
|
|
174
177
|
fireEvent.click(downloadButton);
|
|
175
178
|
|
|
176
179
|
await waitFor(() => {
|
|
@@ -181,7 +184,7 @@ describe("StructureNotesDownloadButton", () => {
|
|
|
181
184
|
});
|
|
182
185
|
|
|
183
186
|
it("shows loading state when downloading", () => {
|
|
184
|
-
|
|
187
|
+
useDataStructureDownload.mockReturnValue({
|
|
185
188
|
trigger: mockTrigger,
|
|
186
189
|
isMutating: true,
|
|
187
190
|
});
|
|
@@ -216,4 +219,42 @@ describe("StructureNotesDownloadButton", () => {
|
|
|
216
219
|
screen.queryByText("Download Structure Notes")
|
|
217
220
|
).not.toBeInTheDocument();
|
|
218
221
|
});
|
|
222
|
+
|
|
223
|
+
it("handles window location origin correctly", async () => {
|
|
224
|
+
// Guardar y mockear window.location
|
|
225
|
+
const originalLocation = window.location;
|
|
226
|
+
Object.defineProperty(window, 'location', {
|
|
227
|
+
value: { origin: 'http://localhost' },
|
|
228
|
+
writable: true
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
renderWithIntl(
|
|
232
|
+
<StructureNotesDownloadButton
|
|
233
|
+
structureId={mockStructureId}
|
|
234
|
+
/>
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const openButton = screen.getByRole("button");
|
|
238
|
+
fireEvent.click(openButton);
|
|
239
|
+
|
|
240
|
+
const downloadButton = screen.getByRole("button", { name: /download/i });
|
|
241
|
+
fireEvent.click(downloadButton);
|
|
242
|
+
|
|
243
|
+
await waitFor(() => {
|
|
244
|
+
expect(mockTrigger).toHaveBeenCalledWith({
|
|
245
|
+
data_structure_id: mockStructureId,
|
|
246
|
+
include_children: false,
|
|
247
|
+
lang: "en",
|
|
248
|
+
structure_url_schema: "http://localhost/structures/:id",
|
|
249
|
+
download_type: "editable",
|
|
250
|
+
note_type: "published"
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Restaurar window.location
|
|
255
|
+
Object.defineProperty(window, 'location', {
|
|
256
|
+
value: originalLocation,
|
|
257
|
+
writable: true
|
|
258
|
+
});
|
|
259
|
+
});
|
|
219
260
|
});
|
|
@@ -96,16 +96,4 @@ export const useDataStructureSuggestions = () => {
|
|
|
96
96
|
return apiJsonPost(url, arg);
|
|
97
97
|
});
|
|
98
98
|
};
|
|
99
|
-
|
|
100
|
-
export const useStructureNotesDownload = () => {
|
|
101
|
-
return useSWRMutations(API_STRUCTURE_NOTES_XLSX_DOWNLOAD, (url, { arg }) => {
|
|
102
|
-
const { id, ...params } = arg;
|
|
103
|
-
const downloadUrl = url.replace(":id", id);
|
|
104
|
-
return apiJsonPost(downloadUrl, params, {
|
|
105
|
-
...JSON_OPTS,
|
|
106
|
-
responseType: "blob",
|
|
107
|
-
}).then(({ data, headers }) => {
|
|
108
|
-
saveFile({ data, headers });
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
};
|
|
99
|
+
|