@openmrs/esm-stock-management-app 1.0.1-pre.548 → 1.0.1-pre.559

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. package/dist/271.js +1 -1
  2. package/dist/281.js +1 -1
  3. package/dist/281.js.map +1 -1
  4. package/dist/319.js +1 -1
  5. package/dist/460.js +1 -1
  6. package/dist/574.js +1 -1
  7. package/dist/757.js +1 -1
  8. package/dist/788.js +1 -1
  9. package/dist/807.js +1 -1
  10. package/dist/833.js +1 -1
  11. package/dist/main.js +1 -1
  12. package/dist/main.js.map +1 -1
  13. package/dist/openmrs-esm-stock-management-app.js.buildmanifest.json +30 -30
  14. package/dist/routes.json +1 -1
  15. package/package.json +5 -5
  16. package/src/core/api/types/stockOperation/StockOperationDTO.ts +0 -1
  17. package/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx +13 -9
  18. package/src/stock-operations/add-stock-operation/add-stock-operation.utils.tsx +1 -4
  19. package/src/stock-operations/add-stock-operation/stock-operation-submission.component.tsx +17 -17
  20. package/src/stock-operations/stock-operations-dialog/stock-operations-complete-button.component.tsx +3 -2
  21. package/src/stock-operations/stock-operations-dialog/stock-operations-completed-dispatch-button.component.tsx +3 -2
  22. package/src/stock-operations/stock-operations-table.component.tsx +19 -65
  23. package/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx +4 -3
  24. package/src/stock-sources/stock-sources-delete/stock-sources-delete.test.tsx +190 -0
  25. package/translations/am.json +1 -0
  26. package/translations/ar.json +1 -0
  27. package/translations/en.json +2 -1
  28. package/translations/es.json +1 -0
  29. package/translations/fr.json +1 -0
  30. package/translations/he.json +1 -0
  31. package/translations/km.json +1 -0
  32. package/translations/zh.json +1 -0
@@ -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
+ });
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "የአክሲዮን ምንጭ በተሳካ ሁኔታ ተሰርዟል።",
281
281
  "stockUserScopeDeletedSuccessfully": "የአክሲዮን ተጠቃሚ ወሰን በተሳካ ሁኔታ ተሰርዟል።",
282
282
  "submit": "አስተዋውቅ",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "ተጠይቷል",
284
285
  "successfullysaved": "የተጠቃሚ ሚና አካባቢ በተሳካ ሁኔታ ተስተካክሏል",
285
286
  "SuccessfullyUploadedStockItem": "የአክሲዮን ንጥሎችን በተሳካ ሁኔታ ሰቅለዋል።",
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "تم حذف مصدر المخزون بنجاح",
281
281
  "stockUserScopeDeletedSuccessfully": "تم حذف نطاق مستخدم المخزون بنجاح",
282
282
  "submit": "تقديم",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "تم تقديمه",
284
285
  "successfullysaved": "تم حفظ نطاق دور المستخدم بنجاح",
285
286
  "SuccessfullyUploadedStockItem": "لقد قمت بتحميل العناصر المخزنة بنجاح",
@@ -54,7 +54,7 @@
54
54
  "code": "Code",
55
55
  "comingSoonUnderDev": "Exciting updates are on the way! In the meantime, use the link below to access Admin UI settings.",
56
56
  "commonName": "Common Name",
57
- "complete": "Complete Dispatch ",
57
+ "complete": "Complete",
58
58
  "completed": "Completed",
59
59
  "continue": "Continue",
60
60
  "created": "Created",
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "Stock Source Deleted Successfully",
281
281
  "stockUserScopeDeletedSuccessfully": "Stock User Scope Deleted Successfully",
282
282
  "submit": "Submit",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "Submitted",
284
285
  "successfullysaved": "You have successfully saved user role scope ",
285
286
  "SuccessfullyUploadedStockItem": "You have successfully uploaded stock items",
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "Fuente de stock eliminada correctamente",
281
281
  "stockUserScopeDeletedSuccessfully": "Ámbito de usuario de stock eliminado Exitosamente",
282
282
  "submit": "Enviar",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "Enviado",
284
285
  "successfullysaved": "Ha guardado con éxito el alcance del rol del usuario",
285
286
  "SuccessfullyUploadedStockItem": "Has cargado correctamente los artículos en stock",
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "Source de stock supprimée avec succès",
281
281
  "stockUserScopeDeletedSuccessfully": "Portée de l'utilisateur stock supprimée avec succès",
282
282
  "submit": "Soumettre",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "Soumis",
284
285
  "successfullysaved": "Vous avez enregistré avec succès la portée du rôle de l'utilisateur",
285
286
  "SuccessfullyUploadedStockItem": "Vous avez téléchargé avec succès les articles en stock",
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "מקור מלאי נמחק בהצלחה",
281
281
  "stockUserScopeDeletedSuccessfully": "היקף משתמש במניות נמחק בהצלחה",
282
282
  "submit": "שלח",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "נשלח",
284
285
  "successfullysaved": "שמרת בהצלחה תחום תפקיד משתמש",
285
286
  "SuccessfullyUploadedStockItem": "העלית בהצלחה פריטי מלאי",
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "ប្រភពស្តុកត្រូវបានលុបដោយជោគជ័យ",
281
281
  "stockUserScopeDeletedSuccessfully": "វិសាលភាពអ្នកប្រើប្រាស់ស្តុកត្រូវបានលុបដោយជោគជ័យ",
282
282
  "submit": "ដាក់ស្នើ",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "បានដាក់ស្នើ",
284
285
  "successfullysaved": "អ្នកបានរក្សាទុកវិសាលភាពតួនាទីអ្នកប្រើដោយជោគជ័យ",
285
286
  "SuccessfullyUploadedStockItem": "អ្នក\u200bបាន\u200bផ្ទុក\u200bឡើង\u200bធាតុ\u200bស្តុក\u200bដោយ\u200bជោគជ័យ",
@@ -280,6 +280,7 @@
280
280
  "stockSourceDeletedSuccessfully": "库存源已成功删除",
281
281
  "stockUserScopeDeletedSuccessfully": "库存用户范围已成功删除",
282
282
  "submit": "提交",
283
+ "submitForReview": "Submit For Review",
283
284
  "submitted": "已提交",
284
285
  "successfullysaved": "您已成功保存用户角色范围",
285
286
  "SuccessfullyUploadedStockItem": "您已成功上传库存商品",