@openmrs/esm-stock-management-app 3.3.2-pre.21 → 3.3.2-pre.231

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 (240) hide show
  1. package/README.md +20 -0
  2. package/dist/1164.js +1 -1
  3. package/dist/1164.js.map +1 -1
  4. package/dist/1207.js +1 -0
  5. package/dist/1207.js.map +1 -0
  6. package/dist/1209.js +1 -0
  7. package/dist/1209.js.map +1 -0
  8. package/dist/1480.js +1 -1
  9. package/dist/1480.js.map +1 -1
  10. package/dist/1600.js +1 -1
  11. package/dist/1600.js.map +1 -1
  12. package/dist/1646.js +1 -1
  13. package/dist/1646.js.map +1 -1
  14. package/dist/1869.js +1 -1
  15. package/dist/1869.js.map +1 -1
  16. package/dist/1877.js +1 -1
  17. package/dist/1877.js.map +1 -1
  18. package/dist/1878.js +1 -1
  19. package/dist/1878.js.map +1 -1
  20. package/dist/2317.js +1 -1
  21. package/dist/2317.js.map +1 -1
  22. package/dist/2392.js +11 -11
  23. package/dist/2392.js.map +1 -1
  24. package/dist/2416.js +1 -1
  25. package/dist/2416.js.map +1 -1
  26. package/dist/2713.js +1 -1
  27. package/dist/2713.js.map +1 -1
  28. package/dist/282.js +1 -1
  29. package/dist/282.js.map +1 -1
  30. package/dist/2881.js +1 -1
  31. package/dist/2881.js.map +1 -1
  32. package/dist/3378.js +1 -1
  33. package/dist/3378.js.map +1 -1
  34. package/dist/3576.js +2 -2
  35. package/dist/3576.js.map +1 -1
  36. package/dist/3588.js +1 -0
  37. package/dist/3588.js.map +1 -0
  38. package/dist/3963.js +1 -1
  39. package/dist/3963.js.map +1 -1
  40. package/dist/4106.js +1 -1
  41. package/dist/4106.js.map +1 -1
  42. package/dist/4111.js +1 -1
  43. package/dist/4111.js.map +1 -1
  44. package/dist/4214.js +1 -1
  45. package/dist/4214.js.map +1 -1
  46. package/dist/434.js +1 -1
  47. package/dist/434.js.map +1 -1
  48. package/dist/4348.js +1 -1
  49. package/dist/4348.js.map +1 -1
  50. package/dist/4383.js +1 -1
  51. package/dist/4383.js.map +1 -1
  52. package/dist/4658.js +1 -1
  53. package/dist/4658.js.map +1 -1
  54. package/dist/4869.css +1 -0
  55. package/dist/4869.css.map +1 -0
  56. package/dist/4869.js +1048 -0
  57. package/dist/4869.js.map +1 -0
  58. package/dist/4928.js +1 -1
  59. package/dist/4928.js.map +1 -1
  60. package/dist/5117.js +1 -1
  61. package/dist/5117.js.map +1 -1
  62. package/dist/5132.js +1 -1
  63. package/dist/5132.js.map +1 -1
  64. package/dist/5145.js +1 -1
  65. package/dist/5145.js.map +1 -1
  66. package/dist/5503.js +1 -1
  67. package/dist/5503.js.map +1 -1
  68. package/dist/556.js +1 -1
  69. package/dist/556.js.map +1 -1
  70. package/dist/5644.js +1 -1
  71. package/dist/5644.js.map +1 -1
  72. package/dist/5838.js +1 -1
  73. package/dist/5838.js.map +1 -1
  74. package/dist/5940.js +1 -1
  75. package/dist/5940.js.map +1 -1
  76. package/dist/5996.js +1 -1
  77. package/dist/5996.js.map +1 -1
  78. package/dist/6047.js +1 -1
  79. package/dist/6047.js.map +1 -1
  80. package/dist/6105.js +1 -1
  81. package/dist/6105.js.map +1 -1
  82. package/dist/6371.js +1 -1
  83. package/dist/6371.js.map +1 -1
  84. package/dist/6377.js +1 -1
  85. package/dist/6377.js.map +1 -1
  86. package/dist/6444.js +1 -1
  87. package/dist/6444.js.map +1 -1
  88. package/dist/6508.js +1 -1
  89. package/dist/6508.js.map +1 -1
  90. package/dist/6724.js +1 -1
  91. package/dist/6724.js.map +1 -1
  92. package/dist/6904.js +1 -1
  93. package/dist/6904.js.map +1 -1
  94. package/dist/6981.js +1 -1
  95. package/dist/6981.js.map +1 -1
  96. package/dist/7037.js +1 -1
  97. package/dist/7045.js +1 -1
  98. package/dist/7045.js.map +1 -1
  99. package/dist/7175.js +1 -1
  100. package/dist/7175.js.map +1 -1
  101. package/dist/7182.js +1 -1
  102. package/dist/7182.js.map +1 -1
  103. package/dist/7742.js +1 -1
  104. package/dist/7742.js.map +1 -1
  105. package/dist/7912.js +1 -1
  106. package/dist/7912.js.map +1 -1
  107. package/dist/8156.js +1 -1
  108. package/dist/8156.js.map +1 -1
  109. package/dist/822.js +1 -1
  110. package/dist/822.js.map +1 -1
  111. package/dist/8358.js +1 -1
  112. package/dist/8358.js.map +1 -1
  113. package/dist/8359.js +1 -1
  114. package/dist/8359.js.map +1 -1
  115. package/dist/8473.js +1 -0
  116. package/dist/8473.js.map +1 -0
  117. package/dist/854.js +1 -0
  118. package/dist/854.js.map +1 -0
  119. package/dist/8661.js +1 -1
  120. package/dist/8661.js.map +1 -1
  121. package/dist/8695.js +1 -1
  122. package/dist/8695.js.map +1 -1
  123. package/dist/8990.js +1 -1
  124. package/dist/8990.js.map +1 -1
  125. package/dist/903.js +1 -1
  126. package/dist/903.js.map +1 -1
  127. package/dist/9072.js +1 -1
  128. package/dist/9072.js.map +1 -1
  129. package/dist/9154.js +1 -1
  130. package/dist/9154.js.map +1 -1
  131. package/dist/9191.js +1 -1
  132. package/dist/9191.js.map +1 -1
  133. package/dist/9806.js +1 -1
  134. package/dist/9806.js.map +1 -1
  135. package/dist/openmrs-esm-stock-management-app.js +2 -2
  136. package/dist/openmrs-esm-stock-management-app.js.map +1 -1
  137. package/dist/routes.json +1 -1
  138. package/package.json +1 -1
  139. package/src/config-schema.ts +38 -0
  140. package/src/constants.ts +0 -56
  141. package/src/routes.json +6 -2
  142. package/src/stock-app-menu-item/item.component.tsx +9 -11
  143. package/src/stock-app-menu-item/item.test.tsx +18 -0
  144. package/src/stock-home/expired-stock.modal.tsx +2 -6
  145. package/src/stock-home/expired-stock.test.tsx +23 -0
  146. package/src/stock-home/issuing-stock.modal.tsx +18 -16
  147. package/src/stock-home/issuing-stock.test.tsx +41 -0
  148. package/src/stock-items/add-stock-item/add-stock-item.component.tsx +10 -1
  149. package/src/stock-items/add-stock-item/add-stock-item.integration.test.tsx +45 -1
  150. package/src/stock-items/add-stock-item/add-stock-item.test.tsx +20 -1
  151. package/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx +13 -4
  152. package/src/stock-items/add-stock-item/stock-item-units-edit/stock-item-units-edit.component.test.tsx +69 -0
  153. package/src/stock-items/add-stock-item/stock-item-units-edit/stock-item-units-edit.component.tsx +1 -1
  154. package/src/stock-items/stock-items.resource.test.ts +79 -0
  155. package/src/stock-items/stock-items.resource.ts +25 -3
  156. package/src/stock-items/validationSchema.test.ts +51 -0
  157. package/src/stock-items/validationSchema.ts +10 -1
  158. package/src/stock-locations/stock-locations-table.resource.test.ts +24 -2
  159. package/src/stock-lookups/stock-lookups.resource.ts +12 -22
  160. package/src/stock-operations/stock-operation-types-selector/stock-operation-types-selector.component.tsx +4 -1
  161. package/src/stock-operations/stock-operation-types-selector/stock-operation-types-selector.test.tsx +46 -0
  162. package/src/stock-operations/stock-operations-forms/hooks/useFilteredOperationTypesByRoles.test.tsx +77 -0
  163. package/src/stock-operations/stock-operations-forms/hooks/useFilteredOperationTypesByRoles.ts +20 -9
  164. package/src/stock-operations/stock-operations-forms/steps/base-operation-details-form-step.test.tsx +64 -0
  165. package/src/stock-operations/stock-operations-forms/steps/base-operation-details-form-step.tsx +16 -5
  166. package/src/stock-operations/stock-operations-forms/steps/stock-operation-item-cell.component.tsx +2 -7
  167. package/src/stock-operations/stock-operations-forms/steps/stock-operation-submission-form-step.component.tsx +11 -3
  168. package/src/stock-operations/stock-operations-forms/steps/stock-operation-submission-form-step.test.tsx +146 -0
  169. package/src/stock-operations/stock-operations-forms/stock-operation-form.component.tsx +4 -2
  170. package/src/stock-operations/stock-operations-forms/stock-operation-form.test.tsx +135 -0
  171. package/src/stock-operations/stock-operations-modal/stock-operations.modal.test.tsx +69 -0
  172. package/src/stock-operations/stock-operations-modal/stock-operations.modal.tsx +12 -2
  173. package/src/stock-operations/stock-operations-table.component.tsx +8 -2
  174. package/src/stock-operations/stock-operations-table.test.tsx +48 -0
  175. package/src/stock-operations/stock-print-reports/StockOperationReport.test.ts +15 -0
  176. package/src/stock-operations/stock-print-reports/StockOperationReport.tsx +5 -2
  177. package/src/stock-reports/ReportType.ts +0 -14
  178. package/src/stock-reports/generate-report/create-stock-report.test.tsx +191 -0
  179. package/src/stock-reports/generate-report/create-stock-report.workspace.tsx +63 -37
  180. package/src/stock-reports/report-list/stock-reports.component.tsx +3 -4
  181. package/src/stock-reports/report-validation-schema.ts +13 -2
  182. package/src/stock-reports/stock-reports.resource.test.ts +50 -0
  183. package/src/stock-reports/stock-reports.resource.ts +23 -13
  184. package/src/stock-sources/add-stock-sources/add-stock-sources.test.tsx +30 -0
  185. package/src/stock-sources/add-stock-sources/add-stock-sources.workspace.tsx +2 -8
  186. package/src/stock-sources/stock-sources-items-table.resource.test.ts +40 -0
  187. package/src/stock-sources/stock-sources-items-table.resource.ts +2 -1
  188. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.test.tsx +49 -0
  189. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.workspace.tsx +6 -21
  190. package/src/stock-user-role-scopes/stock-user-role-scopes-items-table.component.tsx +1 -10
  191. package/src/stock-user-role-scopes/stock-user-role-scopes-items-table.test.tsx +65 -0
  192. package/translations/am.json +6 -1
  193. package/translations/ar.json +6 -1
  194. package/translations/ar_SY.json +6 -1
  195. package/translations/bn.json +6 -1
  196. package/translations/cs.json +6 -1
  197. package/translations/de.json +6 -1
  198. package/translations/en.json +6 -1
  199. package/translations/en_US.json +6 -1
  200. package/translations/es.json +6 -1
  201. package/translations/es_MX.json +6 -1
  202. package/translations/fr.json +6 -1
  203. package/translations/he.json +6 -1
  204. package/translations/hi.json +6 -1
  205. package/translations/hi_IN.json +6 -1
  206. package/translations/id.json +6 -1
  207. package/translations/it.json +6 -1
  208. package/translations/ka.json +6 -1
  209. package/translations/km.json +6 -1
  210. package/translations/ku.json +6 -1
  211. package/translations/ky.json +6 -1
  212. package/translations/lg.json +6 -1
  213. package/translations/ne.json +6 -1
  214. package/translations/pl.json +6 -1
  215. package/translations/pt.json +6 -1
  216. package/translations/pt_BR.json +6 -1
  217. package/translations/qu.json +6 -1
  218. package/translations/ro_RO.json +6 -1
  219. package/translations/ru_RU.json +6 -1
  220. package/translations/si.json +6 -1
  221. package/translations/sq.json +6 -1
  222. package/translations/sw.json +6 -1
  223. package/translations/sw_KE.json +6 -1
  224. package/translations/tr.json +6 -1
  225. package/translations/tr_TR.json +6 -1
  226. package/translations/uk.json +6 -1
  227. package/translations/uz.json +6 -1
  228. package/translations/uz@Latn.json +6 -1
  229. package/translations/uz_UZ.json +6 -1
  230. package/translations/vi.json +6 -1
  231. package/translations/zh.json +6 -1
  232. package/translations/zh_CN.json +6 -1
  233. package/translations/zh_TW.json +6 -1
  234. package/dist/138.js +0 -1
  235. package/dist/138.js.map +0 -1
  236. package/dist/3936.css +0 -1
  237. package/dist/3936.css.map +0 -1
  238. package/dist/3936.js +0 -1048
  239. package/dist/3936.js.map +0 -1
  240. package/src/stock-app-menu-item/item.scss +0 -14
@@ -0,0 +1,135 @@
1
+ import React from 'react';
2
+ import { vi, describe, it, expect, beforeEach } from 'vitest';
3
+ import { render, screen } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { useConfig, useSession } from '@openmrs/esm-framework';
6
+ import { mockWorkspace2Props, stockIssueOperationtypeMock } from '@mocks';
7
+ import { type Party } from '../../core/api/types/Party';
8
+ import { type StockOperationDTO } from '../../core/api/types/stockOperation/StockOperationDTO';
9
+ import { type StockOperationType } from '../../core/api/types/stockOperation/StockOperationType';
10
+ import { useStockOperationAndItems } from '../stock-operations.resource';
11
+ import useParties from './hooks/useParties';
12
+ import StockOperationForm from './stock-operation-form.component';
13
+
14
+ const mockUseStockOperationAndItems = vi.mocked(useStockOperationAndItems);
15
+ const mockUseParties = vi.mocked(useParties);
16
+ const mockUseConfig = vi.mocked(useConfig);
17
+ const mockUseSession = vi.mocked(useSession);
18
+
19
+ vi.mock('../../stock-lookups/stock-lookups.resource', () => ({
20
+ useStockOperationTypes: vi.fn().mockReturnValue({ types: { results: [] }, isLoading: false, error: null }),
21
+ useUsers: vi.fn().mockReturnValue({ items: { results: [] }, isLoading: false }),
22
+ useUser: vi.fn().mockReturnValue({ data: { display: 'Test User' }, isLoading: false, error: null }),
23
+ useConcept: vi.fn().mockReturnValue({ items: { answers: [] }, isLoading: false, error: null }),
24
+ }));
25
+
26
+ vi.mock('../stock-operations.resource', () => ({
27
+ getStockOperationLinks: vi.fn(),
28
+ operationStatusColor: vi.fn(() => 'some-color'),
29
+ useStockOperations: vi.fn().mockReturnValue({ items: { results: [] }, isLoading: false, error: null }),
30
+ useStockOperation: vi.fn().mockReturnValue({ items: undefined, isLoading: false, error: null }),
31
+ useStockOperationAndItems: vi.fn(),
32
+ }));
33
+
34
+ vi.mock('./hooks/useParties', () => ({
35
+ default: vi.fn(),
36
+ useParties: vi.fn(),
37
+ }));
38
+
39
+ const requisitionUuid = 'requisition-uuid';
40
+ const stockIssueType = stockIssueOperationtypeMock as unknown as StockOperationType;
41
+
42
+ const parties = [
43
+ { uuid: 'issue-source-uuid', name: 'Issue Source Store' },
44
+ { uuid: 'issue-destination-uuid', name: 'Issue Destination Ward' },
45
+ { uuid: 'requisition-source-uuid', name: 'Requisition Pharmacy' },
46
+ { uuid: 'requisition-destination-uuid', name: 'Requisition Store' },
47
+ ] as Party[];
48
+
49
+ const requisition = {
50
+ uuid: requisitionUuid,
51
+ sourceUuid: 'requisition-source-uuid',
52
+ destinationUuid: 'requisition-destination-uuid',
53
+ responsiblePersonUuid: 'requisition-person-uuid',
54
+ stockOperationItems: [{ uuid: 'requisition-line', stockItemUuid: 'item-uuid', quantity: 30 }],
55
+ } as StockOperationDTO;
56
+
57
+ const savedIssue = {
58
+ uuid: 'issue-uuid',
59
+ operationTypeUuid: stockIssueOperationtypeMock.uuid,
60
+ operationType: 'stockissue',
61
+ status: 'NEW',
62
+ sourceUuid: 'issue-source-uuid',
63
+ destinationUuid: 'issue-destination-uuid',
64
+ responsiblePersonUuid: 'issuer-person-uuid',
65
+ remarks: 'Issue remarks',
66
+ requisitionStockOperationUuid: requisitionUuid,
67
+ stockOperationItems: [
68
+ { uuid: 'issue-line-1', stockItemUuid: 'item-uuid', stockBatchUuid: 'batch-b2', quantity: 12 },
69
+ { uuid: 'issue-line-2', stockItemUuid: 'item-uuid', stockBatchUuid: 'batch-bulk', quantity: 4 },
70
+ ],
71
+ } as StockOperationDTO;
72
+
73
+ describe('StockOperationForm with a linked requisition', () => {
74
+ beforeEach(() => {
75
+ mockUseStockOperationAndItems.mockImplementation((uuid) => ({
76
+ items: uuid === requisitionUuid ? requisition : undefined,
77
+ isLoading: false,
78
+ error: null,
79
+ }));
80
+ mockUseParties.mockReturnValue({
81
+ destinationParties: parties,
82
+ destinationPartiesFilter: () => true,
83
+ destinationTags: [],
84
+ error: undefined,
85
+ isLoading: false,
86
+ mutate: vi.fn(),
87
+ parties,
88
+ sourceParties: parties,
89
+ sourcePartiesFilter: () => true,
90
+ sourceTags: [],
91
+ });
92
+ mockUseConfig.mockReturnValue({ autoPopulateResponsiblePerson: false });
93
+ mockUseSession.mockReturnValue({
94
+ authenticated: true,
95
+ sessionId: 'test-session-id',
96
+ user: { uuid: 'test-user-uuid' },
97
+ } as ReturnType<typeof useSession>);
98
+ });
99
+
100
+ it("shows a saved issue's own details and lines instead of the requisition's", async () => {
101
+ const user = userEvent.setup();
102
+ render(
103
+ <StockOperationForm
104
+ {...mockWorkspace2Props({
105
+ stockOperationType: stockIssueType,
106
+ stockOperation: savedIssue,
107
+ stockRequisitionUuid: requisitionUuid,
108
+ })}
109
+ />,
110
+ );
111
+
112
+ expect(screen.getByRole('combobox', { name: /source/i })).toHaveValue('Issue Source Store');
113
+ expect(screen.getByRole('combobox', { name: /destination/i })).toHaveValue('Issue Destination Ward');
114
+ expect(mockUseStockOperationAndItems).not.toHaveBeenCalledWith(requisitionUuid);
115
+
116
+ await user.click(screen.getByText(/stock items/i));
117
+
118
+ const lines = screen.getAllByRole('row').slice(1);
119
+ expect(lines).toHaveLength(2);
120
+ });
121
+
122
+ it('prefills a new issue from the requisition', () => {
123
+ render(
124
+ <StockOperationForm
125
+ {...mockWorkspace2Props({
126
+ stockOperationType: stockIssueType,
127
+ stockRequisitionUuid: requisitionUuid,
128
+ })}
129
+ />,
130
+ );
131
+
132
+ expect(screen.getByRole('combobox', { name: /source/i })).toHaveValue('Requisition Store');
133
+ expect(screen.getByRole('combobox', { name: /destination/i })).toHaveValue('Requisition Pharmacy');
134
+ });
135
+ });
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { describe, expect, it, vi } from 'vitest';
5
+ import StockOperationsModal from './stock-operations.modal';
6
+ import { executeStockOperationAction } from '../stock-operations.resource';
7
+ import { type StockOperationDTO } from '../../core/api/types/stockOperation/StockOperationDTO';
8
+
9
+ vi.mock('../stock-operations.resource', () => ({
10
+ executeStockOperationAction: vi.fn().mockResolvedValue({}),
11
+ }));
12
+
13
+ vi.mock('../../utils', () => ({
14
+ useHandleMutate: () => vi.fn(),
15
+ }));
16
+
17
+ describe('StockOperationsModal', () => {
18
+ it('does not submit Cancel without a non-whitespace reason', async () => {
19
+ const user = userEvent.setup();
20
+ render(
21
+ <StockOperationsModal
22
+ title="Cancel"
23
+ requireReason
24
+ operation={{ uuid: 'operation-uuid' } as StockOperationDTO}
25
+ closeModal={vi.fn()}
26
+ />,
27
+ );
28
+
29
+ await user.type(screen.getByRole('textbox'), ' ');
30
+ await user.click(screen.getByRole('button', { name: 'Submit' }));
31
+
32
+ expect(screen.getByText('Required')).toBeInTheDocument();
33
+ expect(executeStockOperationAction).not.toHaveBeenCalled();
34
+
35
+ await user.clear(screen.getByRole('textbox'));
36
+ await user.type(screen.getByRole('textbox'), 'Duplicate request');
37
+ await user.click(screen.getByRole('button', { name: 'Submit' }));
38
+
39
+ await waitFor(() =>
40
+ expect(executeStockOperationAction).toHaveBeenCalledWith({
41
+ name: 'CANCEL',
42
+ uuid: 'operation-uuid',
43
+ reason: 'Duplicate request',
44
+ }),
45
+ );
46
+ });
47
+
48
+ it('submits without a reason when none is required', async () => {
49
+ const user = userEvent.setup();
50
+ render(
51
+ <StockOperationsModal
52
+ title="Approve"
53
+ requireReason={false}
54
+ operation={{ uuid: 'operation-uuid' } as StockOperationDTO}
55
+ closeModal={vi.fn()}
56
+ />,
57
+ );
58
+
59
+ await user.click(screen.getByRole('button', { name: 'Submit' }));
60
+
61
+ await waitFor(() =>
62
+ expect(executeStockOperationAction).toHaveBeenCalledWith({
63
+ name: 'APPROVE',
64
+ uuid: 'operation-uuid',
65
+ reason: '',
66
+ }),
67
+ );
68
+ });
69
+ });
@@ -24,11 +24,17 @@ const StockOperationsModal: React.FC<StockOperationsModalProps> = ({ title, requ
24
24
  const { t } = useTranslation();
25
25
  const handleMutate = useHandleMutate();
26
26
  const [notes, setNotes] = useState('');
27
+ const [reasonIsInvalid, setReasonIsInvalid] = useState(false);
27
28
  const [isApproving, setIsApproving] = useState(false);
28
29
 
29
30
  const handleClick = async (event) => {
30
31
  event.preventDefault();
31
32
 
33
+ if (requireReason && !notes.trim()) {
34
+ setReasonIsInvalid(true);
35
+ return;
36
+ }
37
+
32
38
  setIsApproving(true);
33
39
 
34
40
  let actionName: StopOperationActionType | null = null;
@@ -70,7 +76,7 @@ const StockOperationsModal: React.FC<StockOperationsModalProps> = ({ title, requ
70
76
  const payload: StopOperationAction = {
71
77
  name: actionName,
72
78
  uuid: operation?.uuid,
73
- reason: notes,
79
+ reason: notes.trim(),
74
80
  };
75
81
 
76
82
  // submit action
@@ -121,10 +127,14 @@ const StockOperationsModal: React.FC<StockOperationsModalProps> = ({ title, requ
121
127
  labelText={t('notes', 'Please explain the reason:')}
122
128
  id="nextNotes"
123
129
  name="nextNotes"
130
+ invalid={reasonIsInvalid}
124
131
  invalidText={t('required', 'Required')}
125
132
  maxCount={500}
126
133
  enableCounter
127
- onChange={(e) => setNotes(e.target.value)}
134
+ onChange={(e) => {
135
+ setNotes(e.target.value);
136
+ setReasonIsInvalid(!e.target.value.trim());
137
+ }}
128
138
  />
129
139
  </section>
130
140
  )}
@@ -26,7 +26,8 @@ import {
26
26
  } from '@carbon/react';
27
27
  import { ArrowRight } from '@carbon/react/icons';
28
28
  import { useTranslation } from 'react-i18next';
29
- import { isDesktop, restBaseUrl } from '@openmrs/esm-framework';
29
+ import { isDesktop, restBaseUrl, useConfig } from '@openmrs/esm-framework';
30
+ import { type ConfigObject } from '../config-schema';
30
31
  import { DATE_PICKER_CONTROL_FORMAT, DATE_PICKER_FORMAT, StockFilters } from '../constants';
31
32
  import { formatDisplayDate } from '../core/utils/datetimeUtils';
32
33
  import { useHandleMutate } from '../utils';
@@ -45,6 +46,7 @@ interface StockOperationsTableProps {
45
46
  const StockOperations: React.FC<StockOperationsTableProps> = () => {
46
47
  const { t } = useTranslation();
47
48
  const handleMutate = useHandleMutate();
49
+ const { stockSourceTypeUUID } = useConfig<ConfigObject>();
48
50
 
49
51
  const handleRefresh = () => {
50
52
  handleMutate(`${restBaseUrl}/stockmanagement/stockoperation`);
@@ -198,7 +200,11 @@ const StockOperations: React.FC<StockOperationsTableProps> = () => {
198
200
  placeholder={DATE_PICKER_FORMAT}
199
201
  />
200
202
  </DatePicker>
201
- <StockOperationsFilters filterName={StockFilters.SOURCES} onFilterChange={handleOnFilterChange} />
203
+ <StockOperationsFilters
204
+ conceptUuid={stockSourceTypeUUID}
205
+ filterName={StockFilters.SOURCES}
206
+ onFilterChange={handleOnFilterChange}
207
+ />
202
208
  <StockOperationsFilters filterName={StockFilters.STATUS} onFilterChange={handleOnFilterChange} />
203
209
  <StockOperationsFilters filterName={StockFilters.OPERATION} onFilterChange={handleOnFilterChange} />
204
210
  </div>
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { vi, describe, it, expect, beforeEach } from 'vitest';
3
+ import { render } from '@testing-library/react';
4
+ import { useConfig } from '@openmrs/esm-framework';
5
+ import { StockFilters } from '../constants';
6
+ import StockOperationsFilters from './stock-operations-filters.component';
7
+ import StockOperations from './stock-operations-table.component';
8
+
9
+ const mockUseConfig = vi.mocked(useConfig);
10
+ const mockStockOperationsFilters = vi.mocked(StockOperationsFilters);
11
+
12
+ vi.mock('./stock-operations-filters.component', () => ({
13
+ default: vi.fn(() => null),
14
+ }));
15
+
16
+ vi.mock('./stock-operation-types-selector/stock-operation-types-selector.component', () => ({
17
+ default: () => null,
18
+ }));
19
+
20
+ vi.mock('./stock-operations-table.resource', () => ({
21
+ useStockOperationPages: vi.fn(() => ({
22
+ items: [],
23
+ tableHeaders: [],
24
+ currentPage: 1,
25
+ pageSizes: [10],
26
+ totalItems: 0,
27
+ goTo: vi.fn(),
28
+ currentPageSize: 10,
29
+ setPageSize: vi.fn(),
30
+ isLoading: false,
31
+ })),
32
+ }));
33
+
34
+ describe('StockOperations', () => {
35
+ beforeEach(() => {
36
+ mockUseConfig.mockReturnValue({ stockSourceTypeUUID: 'stock-source-type-uuid' });
37
+ });
38
+
39
+ it('passes the stock source type concept to the Sources filter', () => {
40
+ render(<StockOperations />);
41
+
42
+ const sourcesFilterProps = mockStockOperationsFilters.mock.calls
43
+ .map(([props]) => props)
44
+ .find((props) => props.filterName === StockFilters.SOURCES);
45
+
46
+ expect(sourcesFilterProps?.conceptUuid).toBe('stock-source-type-uuid');
47
+ });
48
+ });
@@ -0,0 +1,15 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { getConfig } from '@openmrs/esm-framework';
3
+ import { type StockOperationDTO } from '../../core/api/types/stockOperation/StockOperationDTO';
4
+ import { BuildStockOperationData } from './StockOperationReport';
5
+
6
+ describe('BuildStockOperationData', () => {
7
+ it('uses the configured facility name as the organization name', async () => {
8
+ vi.mocked(getConfig).mockResolvedValue({ facilityName: 'Mosoriot Sub-County Hospital' });
9
+
10
+ const data = await BuildStockOperationData({ operationTypeName: 'Requisition' } as StockOperationDTO, []);
11
+
12
+ expect(getConfig).toHaveBeenCalledWith('@openmrs/esm-stock-management-app');
13
+ expect(data?.organizationName).toBe('Mosoriot Sub-County Hospital');
14
+ });
15
+ });
@@ -1,8 +1,10 @@
1
+ import { getConfig } from '@openmrs/esm-framework';
2
+ import { type ConfigObject } from '../../config-schema';
1
3
  import { type StockItemInventory } from '../../core/api/types/stockItem/StockItemInventory';
2
4
  import { type StockOperationDTO } from '../../core/api/types/stockOperation/StockOperationDTO';
3
5
  import { type StockOperationItemCost } from '../../core/api/types/stockOperation/StockOperationItemCost';
4
6
  import { type StockOperationItemDTO } from '../../core/api/types/stockOperation/StockOperationItemDTO';
5
- import { HEALTH_CENTER_NAME } from '../../constants';
7
+ import { moduleName } from '../../constants';
6
8
  import { OperationType } from '../../core/api/types/stockOperation/StockOperationType';
7
9
 
8
10
  export interface StockOperationPrintData {
@@ -65,7 +67,8 @@ export const BuildStockOperationData = async (
65
67
  data.responsiblePerson = data.orderedBy = parentOperation?.responsiblePersonFamilyName
66
68
  ? `${parentOperation.responsiblePersonFamilyName ?? ''} ${parentOperation?.responsiblePersonGivenName ?? ''}`
67
69
  : `${currentOperation.responsiblePersonFamilyName ?? ''} ${currentOperation.responsiblePersonGivenName ?? ''}`;
68
- data.organizationName = HEALTH_CENTER_NAME;
70
+ const { facilityName } = await getConfig<ConfigObject>(moduleName);
71
+ data.organizationName = facilityName;
69
72
  data.documentTitle = `${currentOperation.operationTypeName} ${currentOperation?.operationNumber}${
70
73
  parentOperation ? ` of ${parentOperation.operationTypeName} ${parentOperation?.operationNumber}` : ''
71
74
  }`;
@@ -24,20 +24,6 @@ export const isForecastReport = (reportSystemName: string | undefined | null) =>
24
24
  return reportSystemName === 'STOCK_FORECAST_REPORT' || reportSystemName === 'STOCK_EXPIRY_FORECAST_REPORT';
25
25
  };
26
26
 
27
- export const getReportLimitLabel = (reportSystemName: string | undefined | null) => {
28
- return isForecastReport(reportSystemName)
29
- ? 'stockmanagement.report.edit.months'
30
- : 'stockmanagement.report.edit.limit';
31
- };
32
-
33
- export const getReportStartDateLabel = (reportSystemName: string | undefined | null) => {
34
- return isForecastReport(reportSystemName) ? 'stockmanagement.report.edit.historicalstartdate' : 'Start Date';
35
- };
36
-
37
- export const getReportEndDateLabel = (reportSystemName: string | undefined | null) => {
38
- return isForecastReport(reportSystemName) ? 'stockmanagement.report.edit.historicalenddate' : 'End Date';
39
- };
40
-
41
27
  export interface ReportType {
42
28
  order: number;
43
29
  name: string;
@@ -0,0 +1,191 @@
1
+ import React from 'react';
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { showSnackbar, useConfig } from '@openmrs/esm-framework';
6
+ import { mockWorkspace2Props } from '@mocks';
7
+ import { createBatchJob } from '../../stock-batch/stock-batch.resource';
8
+ import { useConcept, useStockTagLocations } from '../../stock-lookups/stock-lookups.resource';
9
+ import { useReportTypes } from '../stock-reports.resource';
10
+ import CreateReport from './create-stock-report.workspace';
11
+
12
+ vi.mock('../../stock-batch/stock-batch.resource', () => ({ createBatchJob: vi.fn() }));
13
+ vi.mock('../../stock-lookups/stock-lookups.resource', () => ({
14
+ useConcept: vi.fn(),
15
+ useStockTagLocations: vi.fn(),
16
+ }));
17
+ vi.mock('../stock-reports.resource', () => ({ useReportTypes: vi.fn() }));
18
+ vi.mock('../../utils', () => ({ useHandleMutate: vi.fn(() => vi.fn()) }));
19
+
20
+ const reportTypes = [
21
+ {
22
+ name: 'Stock Expiry Report',
23
+ systemName: 'STOCK_EXPIRY_REPORT',
24
+ parameters: ['StartDate', 'EndDate', 'Location'],
25
+ },
26
+ {
27
+ name: 'Stock Forecast Report',
28
+ systemName: 'STOCK_FORECAST_REPORT',
29
+ parameters: ['StartDate', 'EndDate', 'Location', 'Limit'],
30
+ },
31
+ {
32
+ name: 'Most Moving Items/Least Moving Items',
33
+ systemName: 'MOST_LEAST_MOVING_STOCK_REPORT',
34
+ parameters: ['StartDate', 'EndDate', 'Location', 'Limit'],
35
+ },
36
+ ];
37
+
38
+ const renderForm = () => {
39
+ const props = mockWorkspace2Props({});
40
+ render(<CreateReport {...props} />);
41
+ return props;
42
+ };
43
+
44
+ const selectReport = async (user: ReturnType<typeof userEvent.setup>, name: string) => {
45
+ await user.click(screen.getByRole('combobox', { name: 'Report name' }));
46
+ await user.click(screen.getByRole('option', { name }));
47
+ // The report's fields appear once the form has processed the selection
48
+ await screen.findByRole('combobox', { name: 'Location' });
49
+ };
50
+
51
+ const typeDate = (label: string, value: string) => {
52
+ const input = screen.getByRole('textbox', { name: label });
53
+ fireEvent.change(input, { target: { value } });
54
+ // flatpickr commits a typed date on Enter
55
+ fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', keyCode: 13 });
56
+ return input;
57
+ };
58
+
59
+ const save = (user: ReturnType<typeof userEvent.setup>) => user.click(screen.getByRole('button', { name: /save/i }));
60
+
61
+ const getParameters = () => vi.mocked(createBatchJob).mock.calls[0][0].parameters as string;
62
+
63
+ describe('CreateReport', () => {
64
+ beforeEach(() => {
65
+ vi.mocked(useConfig).mockReturnValue({ stockItemCategoryUUID: 'category-uuid' });
66
+ vi.mocked(useReportTypes).mockReturnValue({ reportTypes, isLoading: false } as never);
67
+ vi.mocked(useConcept).mockReturnValue({ items: { answers: [] } } as never);
68
+ vi.mocked(useStockTagLocations).mockReturnValue({
69
+ stockLocations: [{ id: 'location-uuid', name: 'Main Store' }],
70
+ } as never);
71
+ vi.mocked(createBatchJob).mockResolvedValue({ status: 201 } as never);
72
+ });
73
+
74
+ describe('saving an incomplete form', () => {
75
+ it('marks the missing fields and says what is missing', async () => {
76
+ const user = userEvent.setup();
77
+ renderForm();
78
+ await selectReport(user, 'Stock Expiry Report');
79
+
80
+ await save(user);
81
+
82
+ expect(await screen.findByText(/Start Date is required/)).toBeInTheDocument();
83
+ expect(screen.getByText(/End Date is required/)).toBeInTheDocument();
84
+ expect(screen.getByText('Location is required')).toBeInTheDocument();
85
+ expect(screen.getByRole('textbox', { name: 'Start date' })).toHaveAttribute('data-invalid', 'true');
86
+ expect(showSnackbar).toHaveBeenCalledWith(
87
+ expect.objectContaining({
88
+ kind: 'error',
89
+ subtitle: 'Complete the required fields: Start date, End date, Location',
90
+ }),
91
+ );
92
+ expect(createBatchJob).not.toHaveBeenCalled();
93
+ });
94
+
95
+ it('marks the report name when no report is chosen', async () => {
96
+ const user = userEvent.setup();
97
+ renderForm();
98
+
99
+ await save(user);
100
+
101
+ expect(await screen.findByText('Report Name Required')).toBeInTheDocument();
102
+ expect(createBatchJob).not.toHaveBeenCalled();
103
+ });
104
+
105
+ it('clears the location error once a location is chosen', async () => {
106
+ const user = userEvent.setup();
107
+ renderForm();
108
+ await selectReport(user, 'Stock Expiry Report');
109
+ await save(user);
110
+ expect(await screen.findByText('Location is required')).toBeInTheDocument();
111
+
112
+ await user.selectOptions(screen.getByRole('combobox', { name: 'Location' }), 'Main Store');
113
+
114
+ await waitFor(() => expect(screen.queryByText('Location is required')).not.toBeInTheDocument());
115
+ });
116
+ });
117
+
118
+ describe('Enter in a date field', () => {
119
+ it('commits the date without submitting a form that is otherwise complete', async () => {
120
+ const user = userEvent.setup();
121
+ const { closeWorkspace } = renderForm();
122
+ await selectReport(user, 'Stock Expiry Report');
123
+ await user.selectOptions(screen.getByRole('combobox', { name: 'Location' }), 'Main Store');
124
+ typeDate('Start date', '01/01/2026');
125
+
126
+ const endDate = screen.getByRole('textbox', { name: 'End date' });
127
+ await user.clear(endDate);
128
+ await user.type(endDate, '31/01/2026{Enter}');
129
+
130
+ await waitFor(() => expect(endDate).toHaveValue('31/01/2026'));
131
+ expect(createBatchJob).not.toHaveBeenCalled();
132
+ expect(closeWorkspace).not.toHaveBeenCalled();
133
+
134
+ await save(user);
135
+
136
+ await waitFor(() => expect(createBatchJob).toHaveBeenCalledTimes(1));
137
+ expect(getParameters()).toContain('param.EndDate.value.desc=31-Jan-2026');
138
+ });
139
+ });
140
+
141
+ describe('Limit', () => {
142
+ const fillRequiredFields = async (user: ReturnType<typeof userEvent.setup>, reportName: string) => {
143
+ await selectReport(user, reportName);
144
+ await user.selectOptions(screen.getByRole('combobox', { name: 'Location' }), 'Main Store');
145
+ typeDate('Start date', '01/01/2026');
146
+ typeDate('End date', '31/01/2026');
147
+ };
148
+
149
+ it('starts empty and sends what is typed as a number', async () => {
150
+ const user = userEvent.setup();
151
+ renderForm();
152
+ await fillRequiredFields(user, 'Most Moving Items/Least Moving Items');
153
+
154
+ const limit = screen.getByRole('spinbutton', { name: 'Limit' });
155
+ expect(limit).toHaveValue(null);
156
+
157
+ await user.type(limit, '5');
158
+ expect(limit).toHaveValue(5);
159
+
160
+ await save(user);
161
+
162
+ await waitFor(() => expect(createBatchJob).toHaveBeenCalledTimes(1));
163
+ expect(getParameters()).toContain('param.Limit.value=5\r\n');
164
+ });
165
+
166
+ it('uses the real default when a typed limit is cleared', async () => {
167
+ const user = userEvent.setup();
168
+ renderForm();
169
+ await fillRequiredFields(user, 'Stock Forecast Report');
170
+
171
+ const limit = screen.getByRole('spinbutton', { name: 'Limit' });
172
+ await user.type(limit, '5');
173
+ await user.clear(limit);
174
+ await save(user);
175
+
176
+ await waitFor(() => expect(createBatchJob).toHaveBeenCalledTimes(1));
177
+ expect(getParameters()).toContain('param.Limit.value=4\r\n');
178
+ });
179
+
180
+ it('uses the real default when left empty', async () => {
181
+ const user = userEvent.setup();
182
+ renderForm();
183
+ await fillRequiredFields(user, 'Stock Forecast Report');
184
+
185
+ await save(user);
186
+
187
+ await waitFor(() => expect(createBatchJob).toHaveBeenCalledTimes(1));
188
+ expect(getParameters()).toContain('param.Limit.value=4\r\n');
189
+ });
190
+ });
191
+ });