@openmrs/esm-stock-management-app 1.0.1-pre.702 → 1.0.1-pre.710

Sign up to get free protection for your applications and to get access to all the features.
@@ -134,10 +134,10 @@
134
134
  "initial": true,
135
135
  "entry": true,
136
136
  "recorded": false,
137
- "size": 5408566,
137
+ "size": 5409050,
138
138
  "sizes": {
139
139
  "consume-shared": 252,
140
- "javascript": 5386617,
140
+ "javascript": 5387101,
141
141
  "share-init": 252,
142
142
  "runtime": 21445
143
143
  },
@@ -154,7 +154,7 @@
154
154
  "auxiliaryFiles": [
155
155
  "main.js.map"
156
156
  ],
157
- "hash": "bde00c76e90fc524",
157
+ "hash": "549717c7f94ac2f7",
158
158
  "childrenByOrder": {}
159
159
  },
160
160
  {
@@ -372,9 +372,9 @@
372
372
  "initial": false,
373
373
  "entry": false,
374
374
  "recorded": false,
375
- "size": 9348,
375
+ "size": 9345,
376
376
  "sizes": {
377
- "javascript": 9348
377
+ "javascript": 9345
378
378
  },
379
379
  "names": [],
380
380
  "idHints": [],
@@ -388,7 +388,7 @@
388
388
  "auxiliaryFiles": [
389
389
  "627.js.map"
390
390
  ],
391
- "hash": "e44bfcef4206b456",
391
+ "hash": "0b31b4561c627de5",
392
392
  "childrenByOrder": {}
393
393
  },
394
394
  {
@@ -607,9 +607,9 @@
607
607
  "initial": false,
608
608
  "entry": false,
609
609
  "recorded": false,
610
- "size": 1749694,
610
+ "size": 1750178,
611
611
  "sizes": {
612
- "javascript": 1749484,
612
+ "javascript": 1749968,
613
613
  "consume-shared": 210
614
614
  },
615
615
  "names": [],
@@ -623,7 +623,7 @@
623
623
  "auxiliaryFiles": [
624
624
  "973.js.map"
625
625
  ],
626
- "hash": "4e40bb4e6400af3e",
626
+ "hash": "3c6bcfc1834a0d12",
627
627
  "childrenByOrder": {}
628
628
  }
629
629
  ]
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-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"modals":[{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsModal"},{"name":"stock-operation-dialog","component":"stockOperationModal"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.702"}
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-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"modals":[{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsModal"},{"name":"stock-operation-dialog","component":"stockOperationModal"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.710"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-stock-management-app",
3
- "version": "1.0.1-pre.702",
3
+ "version": "1.0.1-pre.710",
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",
@@ -64,7 +64,7 @@ const ImportDialogPopup: React.FC<ImportDialogPopupProps> = ({ closeModal }) =>
64
64
  labelDescription="Only .csv files at 2mb or less"
65
65
  filenameStatus="edit"
66
66
  labelTitle=""
67
- size="small"
67
+ size="sm"
68
68
  onChange={onFileChanged}
69
69
  />
70
70
  </ModalBody>
@@ -0,0 +1,105 @@
1
+ import React from 'react';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import ImportDialogPopup from './stock-items-bulk-import.component';
5
+ import { showSnackbar } from '@openmrs/esm-framework';
6
+ import { UploadStockItems } from './stock-items-bulk-import.resource';
7
+
8
+ jest.mock('@openmrs/esm-framework', () => ({
9
+ showSnackbar: jest.fn(),
10
+ }));
11
+
12
+ jest.mock('./stock-items-bulk-import.resource', () => ({
13
+ UploadStockItems: jest.fn(),
14
+ }));
15
+
16
+ describe('ImportDialogPopup', () => {
17
+ const mockCloseModal = jest.fn();
18
+
19
+ beforeEach(() => {
20
+ jest.clearAllMocks();
21
+ });
22
+
23
+ it('renders with initial state and UI elements', () => {
24
+ render(<ImportDialogPopup closeModal={mockCloseModal} />);
25
+
26
+ expect(screen.getByText('Import Stock Items')).toBeInTheDocument();
27
+ expect(screen.getByRole('button', { name: 'Select file' })).toBeInTheDocument();
28
+ expect(screen.getByText('Only .csv files at 2mb or less')).toBeInTheDocument();
29
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
30
+ expect(screen.getByRole('button', { name: 'Upload StockItems' })).toBeInTheDocument();
31
+ });
32
+
33
+ it('allows only CSV files', async () => {
34
+ render(<ImportDialogPopup closeModal={mockCloseModal} />);
35
+
36
+ const fileInput = screen.getByLabelText('Select file') as HTMLInputElement;
37
+ expect(fileInput.accept).toBe('.csv');
38
+ });
39
+
40
+ it('closes modal when cancel button is clicked', async () => {
41
+ render(<ImportDialogPopup closeModal={mockCloseModal} />);
42
+
43
+ const cancelButton = screen.getByRole('button', { name: 'Cancel' });
44
+ await userEvent.click(cancelButton);
45
+
46
+ expect(mockCloseModal).toHaveBeenCalledTimes(1);
47
+ });
48
+
49
+ it('does nothing when upload is clicked without a file', async () => {
50
+ render(<ImportDialogPopup closeModal={mockCloseModal} />);
51
+
52
+ const uploadButton = screen.getByRole('button', { name: 'Upload StockItems' });
53
+ await userEvent.click(uploadButton);
54
+
55
+ expect(UploadStockItems).not.toHaveBeenCalled();
56
+ expect(showSnackbar).not.toHaveBeenCalled();
57
+ expect(mockCloseModal).not.toHaveBeenCalled();
58
+ });
59
+
60
+ it('uploads file successfully and shows success snackbar', async () => {
61
+ (UploadStockItems as jest.Mock).mockResolvedValue({});
62
+ render(<ImportDialogPopup closeModal={mockCloseModal} />);
63
+
64
+ const validFile = new File(['test content'], 'valid.csv', { type: 'text/csv' });
65
+ const fileInput = screen.getByLabelText('Select file') as HTMLInputElement;
66
+ await userEvent.upload(fileInput, validFile);
67
+
68
+ const uploadButton = screen.getByRole('button', { name: 'Upload StockItems' });
69
+ await userEvent.click(uploadButton);
70
+
71
+ await waitFor(() => expect(UploadStockItems).toHaveBeenCalled());
72
+ await waitFor(() =>
73
+ expect(showSnackbar).toHaveBeenCalledWith(
74
+ expect.objectContaining({
75
+ kind: 'success',
76
+ title: 'Uploaded Order',
77
+ }),
78
+ ),
79
+ );
80
+ await waitFor(() => expect(mockCloseModal).toHaveBeenCalledTimes(1));
81
+ });
82
+
83
+ it('shows error snackbar on upload failure', async () => {
84
+ (UploadStockItems as jest.Mock).mockRejectedValue(new Error('Upload failed'));
85
+ render(<ImportDialogPopup closeModal={mockCloseModal} />);
86
+
87
+ const validFile = new File(['test content'], 'valid.csv', { type: 'text/csv' });
88
+ const fileInput = screen.getByLabelText('Select file') as HTMLInputElement;
89
+ await userEvent.upload(fileInput, validFile);
90
+
91
+ const uploadButton = screen.getByRole('button', { name: 'Upload StockItems' });
92
+ await userEvent.click(uploadButton);
93
+
94
+ await waitFor(() => expect(UploadStockItems).toHaveBeenCalled());
95
+ await waitFor(() =>
96
+ expect(showSnackbar).toHaveBeenCalledWith(
97
+ expect.objectContaining({
98
+ kind: 'error',
99
+ title: 'An error occurred uploading stock items',
100
+ }),
101
+ ),
102
+ );
103
+ await waitFor(() => expect(mockCloseModal).not.toHaveBeenCalled());
104
+ });
105
+ });
@@ -37,5 +37,18 @@ export function useValidationSchema(operationType?: string) {
37
37
  stockItems: z.array(customSchema),
38
38
  });
39
39
  }
40
+ if (operationType === 'adjustment') {
41
+ const customSchema = stockItemTableSchema.extend({
42
+ quantity: z.coerce
43
+ .number()
44
+ .refine((value) => value !== 0, {
45
+ message: 'Quantity cannot be zero.',
46
+ })
47
+ .or(z.literal(0, { invalid_type_error: 'Invalid quantity format' })),
48
+ });
49
+ return z.object({
50
+ stockItems: z.array(customSchema),
51
+ });
52
+ }
40
53
  return stockOperationItemsSchema;
41
54
  }