@openmrs/esm-stock-management-app 1.0.1-pre.548 → 1.0.1-pre.554
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/281.js +1 -1
- package/dist/281.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-stock-management-app.js.buildmanifest.json +6 -6
- package/dist/routes.json +1 -1
- package/package.json +5 -5
- package/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx +4 -3
- package/src/stock-sources/stock-sources-delete/stock-sources-delete.test.tsx +190 -0
@@ -85,10 +85,10 @@
|
|
85
85
|
"initial": true,
|
86
86
|
"entry": true,
|
87
87
|
"recorded": false,
|
88
|
-
"size":
|
88
|
+
"size": 5449043,
|
89
89
|
"sizes": {
|
90
90
|
"consume-shared": 252,
|
91
|
-
"javascript":
|
91
|
+
"javascript": 5427093,
|
92
92
|
"share-init": 252,
|
93
93
|
"runtime": 21446
|
94
94
|
},
|
@@ -105,7 +105,7 @@
|
|
105
105
|
"auxiliaryFiles": [
|
106
106
|
"main.js.map"
|
107
107
|
],
|
108
|
-
"hash": "
|
108
|
+
"hash": "5c66dbf37bc59c64",
|
109
109
|
"childrenByOrder": {}
|
110
110
|
},
|
111
111
|
{
|
@@ -135,9 +135,9 @@
|
|
135
135
|
"initial": false,
|
136
136
|
"entry": false,
|
137
137
|
"recorded": false,
|
138
|
-
"size":
|
138
|
+
"size": 1780616,
|
139
139
|
"sizes": {
|
140
|
-
"javascript":
|
140
|
+
"javascript": 1780406,
|
141
141
|
"consume-shared": 210
|
142
142
|
},
|
143
143
|
"names": [],
|
@@ -151,7 +151,7 @@
|
|
151
151
|
"auxiliaryFiles": [
|
152
152
|
"281.js.map"
|
153
153
|
],
|
154
|
-
"hash": "
|
154
|
+
"hash": "25cca919bb307ac6",
|
155
155
|
"childrenByOrder": {}
|
156
156
|
},
|
157
157
|
{
|
package/dist/routes.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"extensions":[{"name":"stock-nav-menu","slot":"stock-sidebar-slot","component":"stockNavMenu","online":true,"offline":true},{"name":"overview-db-link","slot":"stock-page-dashboard-slot","component":"stockOverviewLink","meta":{"name":"overview","slot":"overview-dashboard-slot","title":"overview"},"order":0,"online":true,"offline":true},{"name":"stock-overview-db","slot":"overview-dashboard-slot","component":"stockOverview"},{"name":"operations-db-link","slot":"stock-page-dashboard-slot","component":"stockOperationsLink","meta":{"name":"operations","slot":"operations-dashboard-slot","title":"operations"},"order":2,"online":true,"offline":true},{"name":"stock-operations-db","slot":"operations-dashboard-slot","component":"stockOperations"},{"name":"items-db-link","slot":"stock-page-dashboard-slot","component":"stockItemsLink","meta":{"name":"items","slot":"items-dashboard-slot","title":"items"},"order":1,"online":true,"offline":true},{"name":"stock-items-db","slot":"items-dashboard-slot","component":"stockItems"},{"name":"user-scopes-db-link","slot":"stock-page-dashboard-slot","component":"stockUserScopesLink","meta":{"name":"user-scopes","slot":"user-scopes-dashboard-slot","title":"user-scopes"},"order":3,"online":true,"offline":true},{"name":"stock-user-scopes-db","slot":"user-scopes-dashboard-slot","component":"stockUserScopes"},{"name":"sources-db-link","slot":"stock-page-dashboard-slot","component":"stockSourcesLink","meta":{"name":"sources","slot":"sources-dashboard-slot","title":"Sources"},"order":2,"online":true,"offline":true},{"name":"stock-sources-db","slot":"sources-dashboard-slot","component":"stockSources"},{"name":"locations-db-link","slot":"stock-page-dashboard-slot","component":"stockLocationsLink","meta":{"name":"locations","slot":"locations-dashboard-slot","title":"Locations"},"order":4,"online":true,"offline":true},{"name":"stock-locations-db","slot":"locations-dashboard-slot","component":"stockLocations"},{"name":"reports-db-link","slot":"stock-page-dashboard-slot","component":"stockReportsLink","meta":{"name":"reports","slot":"reports-dashboard-slot","title":"Reports"},"order":5,"online":true,"offline":true},{"name":"stock-reports-db","slot":"reports-dashboard-slot","component":"stockReports"},{"name":"settings-db-link","slot":"stock-page-dashboard-slot","component":"stockSettingsLink","meta":{"name":"settings","slot":"settings-dashboard-slot","title":"Settings"},"order":6,"online":true,"offline":true},{"name":"stock-settings-db","slot":"settings-dashboard-slot","component":"stockSettings"},{"name":"stock-management-admin-card-link","slot":"system-admin-page-card-link-slot","component":"stockManagementAdminCardLink"},{"name":"stock-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.
|
1
|
+
{"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"extensions":[{"name":"stock-nav-menu","slot":"stock-sidebar-slot","component":"stockNavMenu","online":true,"offline":true},{"name":"overview-db-link","slot":"stock-page-dashboard-slot","component":"stockOverviewLink","meta":{"name":"overview","slot":"overview-dashboard-slot","title":"overview"},"order":0,"online":true,"offline":true},{"name":"stock-overview-db","slot":"overview-dashboard-slot","component":"stockOverview"},{"name":"operations-db-link","slot":"stock-page-dashboard-slot","component":"stockOperationsLink","meta":{"name":"operations","slot":"operations-dashboard-slot","title":"operations"},"order":2,"online":true,"offline":true},{"name":"stock-operations-db","slot":"operations-dashboard-slot","component":"stockOperations"},{"name":"items-db-link","slot":"stock-page-dashboard-slot","component":"stockItemsLink","meta":{"name":"items","slot":"items-dashboard-slot","title":"items"},"order":1,"online":true,"offline":true},{"name":"stock-items-db","slot":"items-dashboard-slot","component":"stockItems"},{"name":"user-scopes-db-link","slot":"stock-page-dashboard-slot","component":"stockUserScopesLink","meta":{"name":"user-scopes","slot":"user-scopes-dashboard-slot","title":"user-scopes"},"order":3,"online":true,"offline":true},{"name":"stock-user-scopes-db","slot":"user-scopes-dashboard-slot","component":"stockUserScopes"},{"name":"sources-db-link","slot":"stock-page-dashboard-slot","component":"stockSourcesLink","meta":{"name":"sources","slot":"sources-dashboard-slot","title":"Sources"},"order":2,"online":true,"offline":true},{"name":"stock-sources-db","slot":"sources-dashboard-slot","component":"stockSources"},{"name":"locations-db-link","slot":"stock-page-dashboard-slot","component":"stockLocationsLink","meta":{"name":"locations","slot":"locations-dashboard-slot","title":"Locations"},"order":4,"online":true,"offline":true},{"name":"stock-locations-db","slot":"locations-dashboard-slot","component":"stockLocations"},{"name":"reports-db-link","slot":"stock-page-dashboard-slot","component":"stockReportsLink","meta":{"name":"reports","slot":"reports-dashboard-slot","title":"Reports"},"order":5,"online":true,"offline":true},{"name":"stock-reports-db","slot":"reports-dashboard-slot","component":"stockReports"},{"name":"settings-db-link","slot":"stock-page-dashboard-slot","component":"stockSettingsLink","meta":{"name":"settings","slot":"settings-dashboard-slot","title":"Settings"},"order":6,"online":true,"offline":true},{"name":"stock-settings-db","slot":"settings-dashboard-slot","component":"stockSettings"},{"name":"stock-management-admin-card-link","slot":"system-admin-page-card-link-slot","component":"stockManagementAdminCardLink"},{"name":"stock-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.554"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@openmrs/esm-stock-management-app",
|
3
|
-
"version": "1.0.1-pre.
|
3
|
+
"version": "1.0.1-pre.554",
|
4
4
|
"license": "MPL-2.0",
|
5
5
|
"description": "Stock management microfrontend for OpenMRS 3.x",
|
6
6
|
"browser": "dist/openmrs-esm-stock-management-app.js",
|
@@ -69,14 +69,14 @@
|
|
69
69
|
"@swc/cli": "^0.1.62",
|
70
70
|
"@swc/core": "^1.3.68",
|
71
71
|
"@swc/jest": "^0.2.26",
|
72
|
-
"@testing-library/dom": "^
|
72
|
+
"@testing-library/dom": "^10.4.0",
|
73
73
|
"@testing-library/jest-dom": "^5.16.5",
|
74
|
-
"@testing-library/react": "^
|
74
|
+
"@testing-library/react": "^16.0.0",
|
75
75
|
"@testing-library/user-event": "^14.4.3",
|
76
76
|
"@types/file-saver": "^2.0.5",
|
77
77
|
"@types/jest": "^28.1.8",
|
78
|
-
"@types/react": "^18.
|
79
|
-
"@types/react-dom": "^18.
|
78
|
+
"@types/react": "^18.3.3",
|
79
|
+
"@types/react-dom": "^18.3.0",
|
80
80
|
"@types/react-router": "^5.1.20",
|
81
81
|
"@types/react-router-dom": "^5.3.3",
|
82
82
|
"@types/webpack-env": "^1.18.1",
|
@@ -61,9 +61,10 @@ const StockSourcesDeleteActionMenu: React.FC<
|
|
61
61
|
kind="ghost"
|
62
62
|
size="md"
|
63
63
|
onClick={handleDeleteStockSource}
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
aria-label={t("deleteSource", "Delete Source")}
|
65
|
+
>
|
66
|
+
<TrashCan size={16} />
|
67
|
+
</Button>
|
67
68
|
);
|
68
69
|
|
69
70
|
return deletingSource ? <InlineLoading /> : deleteButton;
|
@@ -0,0 +1,190 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { render, fireEvent, waitFor, screen } from "@testing-library/react";
|
3
|
+
import "@testing-library/jest-dom/extend-expect";
|
4
|
+
import { showModal, showSnackbar } from "@openmrs/esm-framework";
|
5
|
+
import { deleteStockSource } from "../stock-sources.resource";
|
6
|
+
import StockSourcesDeleteActionMenu from "./stock-sources-delete.component";
|
7
|
+
import DeleteConfirmation from "../../stock-user-role-scopes/delete-stock-user-scope-modal.component";
|
8
|
+
import { handleMutate } from "../../utils";
|
9
|
+
|
10
|
+
jest.mock("react-i18next", () => ({
|
11
|
+
useTranslation: () => ({
|
12
|
+
t: (key) => key,
|
13
|
+
}),
|
14
|
+
}));
|
15
|
+
|
16
|
+
jest.mock("@openmrs/esm-framework", () => ({
|
17
|
+
showModal: jest.fn(),
|
18
|
+
showSnackbar: jest.fn(),
|
19
|
+
restBaseUrl: "http://localhost:8080",
|
20
|
+
}));
|
21
|
+
|
22
|
+
jest.mock("../stock-sources.resource", () => ({
|
23
|
+
deleteStockSource: jest.fn(),
|
24
|
+
}));
|
25
|
+
|
26
|
+
jest.mock("../../utils", () => ({
|
27
|
+
handleMutate: jest.fn(),
|
28
|
+
}));
|
29
|
+
|
30
|
+
describe("StockSourcesDeleteActionMenu", () => {
|
31
|
+
const uuid = "1234-5678";
|
32
|
+
const uuids: string[] = ["1234-5678"];
|
33
|
+
|
34
|
+
beforeEach(() => {
|
35
|
+
jest.clearAllMocks();
|
36
|
+
});
|
37
|
+
|
38
|
+
it("renders the delete button correctly", () => {
|
39
|
+
const { getByRole } = render(<StockSourcesDeleteActionMenu uuid={uuid} />);
|
40
|
+
const button = getByRole("button", { name: "deleteSource" });
|
41
|
+
expect(button).toBeInTheDocument();
|
42
|
+
});
|
43
|
+
|
44
|
+
it("opens the delete modal when the delete button is clicked", () => {
|
45
|
+
const { getByRole } = render(<StockSourcesDeleteActionMenu uuid={uuid} />);
|
46
|
+
const button = getByRole("button", { name: "deleteSource" });
|
47
|
+
fireEvent.click(button);
|
48
|
+
expect(showModal).toHaveBeenCalledWith("delete-stock-modal", expect.objectContaining({
|
49
|
+
close: expect.any(Function),
|
50
|
+
uuid: uuid,
|
51
|
+
onConfirmation: expect.any(Function),
|
52
|
+
}));
|
53
|
+
});
|
54
|
+
|
55
|
+
it('calls onConfirmation when delete is clicked', () => {
|
56
|
+
const mockOnConfirmation = jest.fn();
|
57
|
+
const mockClose = jest.fn();
|
58
|
+
|
59
|
+
render(
|
60
|
+
<DeleteConfirmation
|
61
|
+
close={mockClose}
|
62
|
+
onConfirmation={mockOnConfirmation}
|
63
|
+
/>
|
64
|
+
);
|
65
|
+
|
66
|
+
expect(screen.getByText(/deleteStockUserScope/i)).toBeInTheDocument();
|
67
|
+
|
68
|
+
const deleteButton = screen.getByRole('button', { name: /delete/i });
|
69
|
+
fireEvent.click(deleteButton);
|
70
|
+
|
71
|
+
expect(mockOnConfirmation).toHaveBeenCalledTimes(1);
|
72
|
+
expect(mockClose).not.toHaveBeenCalled();
|
73
|
+
});
|
74
|
+
|
75
|
+
it("calls deleteStockSource with the correct UUID on confirmation", async () => {
|
76
|
+
const mockOnConfirmation = jest.fn();
|
77
|
+
const mockClose = jest.fn();
|
78
|
+
|
79
|
+
render(
|
80
|
+
<DeleteConfirmation
|
81
|
+
close={mockClose}
|
82
|
+
onConfirmation={() => {
|
83
|
+
mockOnConfirmation();
|
84
|
+
deleteStockSource([uuid]);
|
85
|
+
}}
|
86
|
+
/>
|
87
|
+
);
|
88
|
+
|
89
|
+
const deleteButton = screen.getByRole('button', { name: /delete/i });
|
90
|
+
fireEvent.click(deleteButton);
|
91
|
+
|
92
|
+
expect(mockOnConfirmation).toHaveBeenCalledTimes(1);
|
93
|
+
expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
|
94
|
+
});
|
95
|
+
|
96
|
+
it("calls handleMutate with the correct URL on successful deletion", async () => {
|
97
|
+
(deleteStockSource as jest.Mock).mockResolvedValueOnce({});
|
98
|
+
|
99
|
+
const mockOnConfirmation = jest.fn();
|
100
|
+
const mockClose = jest.fn();
|
101
|
+
|
102
|
+
render(
|
103
|
+
<DeleteConfirmation
|
104
|
+
close={mockClose}
|
105
|
+
onConfirmation={async () => {
|
106
|
+
await deleteStockSource([uuid]);
|
107
|
+
handleMutate("/openmrs/ws/rest/v1/stocksource");
|
108
|
+
}}
|
109
|
+
/>
|
110
|
+
);
|
111
|
+
|
112
|
+
const deleteButton = screen.getByRole('button', { name: /delete/i });
|
113
|
+
fireEvent.click(deleteButton);
|
114
|
+
|
115
|
+
await waitFor(() => {
|
116
|
+
expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
|
117
|
+
expect(handleMutate).toHaveBeenCalledWith("/openmrs/ws/rest/v1/stocksource");
|
118
|
+
});
|
119
|
+
});
|
120
|
+
|
121
|
+
it("calls showSnackbar with the correct parameters on deletion error", async () => {
|
122
|
+
(deleteStockSource as jest.Mock).mockRejectedValueOnce(new Error("Deletion failed"));
|
123
|
+
|
124
|
+
const mockOnConfirmation = jest.fn();
|
125
|
+
const mockClose = jest.fn();
|
126
|
+
|
127
|
+
render(
|
128
|
+
<DeleteConfirmation
|
129
|
+
close={mockClose}
|
130
|
+
onConfirmation={async () => {
|
131
|
+
try {
|
132
|
+
await deleteStockSource([uuid]);
|
133
|
+
} catch (error) {
|
134
|
+
showSnackbar({
|
135
|
+
title: "stockSourceDeleteError",
|
136
|
+
kind: "error",
|
137
|
+
});
|
138
|
+
}
|
139
|
+
}}
|
140
|
+
/>
|
141
|
+
);
|
142
|
+
|
143
|
+
const deleteButton = screen.getByRole('button', { name: /delete/i });
|
144
|
+
fireEvent.click(deleteButton);
|
145
|
+
|
146
|
+
await waitFor(() => {
|
147
|
+
expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
|
148
|
+
expect(showSnackbar).toHaveBeenCalledWith({
|
149
|
+
title: "stockSourceDeleteError",
|
150
|
+
kind: "error",
|
151
|
+
});
|
152
|
+
});
|
153
|
+
});
|
154
|
+
|
155
|
+
it("handles the error state correctly when the delete action fails", async () => {
|
156
|
+
(deleteStockSource as jest.Mock).mockRejectedValueOnce(new Error("Deletion failed"));
|
157
|
+
|
158
|
+
const mockOnConfirmation = jest.fn();
|
159
|
+
const mockClose = jest.fn();
|
160
|
+
|
161
|
+
render(
|
162
|
+
<DeleteConfirmation
|
163
|
+
close={mockClose}
|
164
|
+
onConfirmation={async () => {
|
165
|
+
try {
|
166
|
+
await deleteStockSource([uuid]);
|
167
|
+
} catch (error) {
|
168
|
+
showSnackbar({
|
169
|
+
title: "stockSourceDeleteError",
|
170
|
+
kind: "error",
|
171
|
+
});
|
172
|
+
}
|
173
|
+
}}
|
174
|
+
/>
|
175
|
+
);
|
176
|
+
|
177
|
+
const deleteButton = screen.getByRole("button", { name: /delete/i });
|
178
|
+
fireEvent.click(deleteButton);
|
179
|
+
|
180
|
+
await waitFor(() => {
|
181
|
+
expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
|
182
|
+
|
183
|
+
expect(showSnackbar).toHaveBeenCalledWith({
|
184
|
+
title: "stockSourceDeleteError",
|
185
|
+
kind: "error",
|
186
|
+
});
|
187
|
+
expect(deleteButton).toBeInTheDocument();
|
188
|
+
});
|
189
|
+
});
|
190
|
+
});
|