@openmrs/esm-stock-management-app 1.0.1-pre.683 → 1.0.1-pre.686
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/973.js +1 -1
- package/dist/973.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 +1 -1
- package/src/stock-operations/batch-no-selector/batch-no-selector.component.tsx +7 -5
- package/src/stock-operations/batch-no-selector/batch-no-selector.test.tsx +96 -5
@@ -134,10 +134,10 @@
|
|
134
134
|
"initial": true,
|
135
135
|
"entry": true,
|
136
136
|
"recorded": false,
|
137
|
-
"size":
|
137
|
+
"size": 5407793,
|
138
138
|
"sizes": {
|
139
139
|
"consume-shared": 252,
|
140
|
-
"javascript":
|
140
|
+
"javascript": 5385844,
|
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": "
|
157
|
+
"hash": "b6ba4ea06ac17137",
|
158
158
|
"childrenByOrder": {}
|
159
159
|
},
|
160
160
|
{
|
@@ -607,9 +607,9 @@
|
|
607
607
|
"initial": false,
|
608
608
|
"entry": false,
|
609
609
|
"recorded": false,
|
610
|
-
"size":
|
610
|
+
"size": 1748921,
|
611
611
|
"sizes": {
|
612
|
-
"javascript":
|
612
|
+
"javascript": 1748711,
|
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": "
|
626
|
+
"hash": "f060b14379d6e58f",
|
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.
|
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.686"}
|
package/package.json
CHANGED
@@ -65,7 +65,7 @@ const BatchNoSelector = <T,>(props: BatchNoSelectorProps<T>) => {
|
|
65
65
|
}
|
66
66
|
}, [isLoading, stockItemBatchNos, props.selectedItem, filteredBatches]);
|
67
67
|
|
68
|
-
if (isLoading) return <InlineLoading status="active" />;
|
68
|
+
if (isLoading) return <InlineLoading status="active" data-testid="loading" />;
|
69
69
|
|
70
70
|
return (
|
71
71
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
@@ -88,9 +88,7 @@ const BatchNoSelector = <T,>(props: BatchNoSelectorProps<T>) => {
|
|
88
88
|
onChange(data.selectedItem?.uuid);
|
89
89
|
}}
|
90
90
|
initialSelectedItem={initialSelectedItem}
|
91
|
-
itemToString={(s: StockBatchDTO) =>
|
92
|
-
s?.batchNo ? `${s?.batchNo} | Qty: ${s?.quantity ?? "Unknown"}` : ""
|
93
|
-
}
|
91
|
+
itemToString={(s: StockBatchDTO) => (s?.batchNo ? `${s?.batchNo} | Qty: ${s?.quantity ?? 'Unknown'}` : '')}
|
94
92
|
placeholder={props.placeholder}
|
95
93
|
invalid={props.invalid}
|
96
94
|
invalidText={props.invalidText}
|
@@ -99,7 +97,11 @@ const BatchNoSelector = <T,>(props: BatchNoSelectorProps<T>) => {
|
|
99
97
|
)}
|
100
98
|
/>
|
101
99
|
{isLoading && <InlineLoading status="active" />}
|
102
|
-
{validationMessage &&
|
100
|
+
{validationMessage && (
|
101
|
+
<div data-testid="validation-message" style={{ color: 'red', marginTop: '8px' }}>
|
102
|
+
{t(validationMessage)}
|
103
|
+
</div>
|
104
|
+
)}
|
103
105
|
</div>
|
104
106
|
);
|
105
107
|
};
|
@@ -1,10 +1,101 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
|
3
|
-
import {
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import { useForm, FormProvider } from 'react-hook-form';
|
4
|
+
import { useStockItemBatchNos } from './batch-no-selector.resource';
|
5
|
+
import { useStockItemBatchInformationHook } from '../../stock-items/add-stock-item/batch-information/batch-information.resource';
|
4
6
|
import BatchNoSelector from './batch-no-selector.component';
|
7
|
+
import { StockBatchDTO } from '../../core/api/types/stockItem/StockBatchDTO';
|
8
|
+
import userEvent from '@testing-library/user-event';
|
9
|
+
import { waitFor } from '@testing-library/react';
|
10
|
+
|
11
|
+
// Mock hooks
|
12
|
+
jest.mock('./batch-no-selector.resource');
|
13
|
+
jest.mock('../../stock-items/add-stock-item/batch-information/batch-information.resource');
|
14
|
+
jest.mock('react-i18next', () => ({
|
15
|
+
useTranslation: () => ({ t: (key: string) => key }),
|
16
|
+
}));
|
17
|
+
|
18
|
+
const mockUseStockItemBatchNos = useStockItemBatchNos as jest.Mock;
|
19
|
+
const mockUseStockItemBatchInformationHook = useStockItemBatchInformationHook as jest.Mock;
|
20
|
+
|
21
|
+
describe('BatchNoSelector Component', () => {
|
22
|
+
const stockItemUuid = 'test-uuid';
|
23
|
+
const batchUuid = 'batch-uuid';
|
24
|
+
const mockStockItemBatchNos: StockBatchDTO[] = [
|
25
|
+
{ uuid: '1', batchNo: 'batch1', quantity: '10', expiration: new Date(), stockItemUuid: '', voided: false },
|
26
|
+
{ uuid: '2', batchNo: 'batch2', quantity: '20', expiration: new Date(), stockItemUuid: '', voided: false },
|
27
|
+
];
|
28
|
+
const mockBatchInformation = [
|
29
|
+
{ batchNumber: 'batch1', quantity: '10' },
|
30
|
+
{ batchNumber: 'batch2', quantity: '20' },
|
31
|
+
];
|
32
|
+
|
33
|
+
beforeEach(() => {
|
34
|
+
mockUseStockItemBatchNos.mockReturnValue({
|
35
|
+
isLoading: false,
|
36
|
+
stockItemBatchNos: mockStockItemBatchNos,
|
37
|
+
});
|
38
|
+
mockUseStockItemBatchInformationHook.mockReturnValue({
|
39
|
+
items: mockBatchInformation,
|
40
|
+
setStockItemUuid: jest.fn(),
|
41
|
+
});
|
42
|
+
});
|
43
|
+
|
44
|
+
const renderComponent = () => {
|
45
|
+
const Wrapper = () => {
|
46
|
+
const methods = useForm();
|
47
|
+
return (
|
48
|
+
<FormProvider {...methods}>
|
49
|
+
<BatchNoSelector
|
50
|
+
stockItemUuid={stockItemUuid}
|
51
|
+
batchUuid={batchUuid}
|
52
|
+
controllerName="batchNo"
|
53
|
+
name="batchNo"
|
54
|
+
control={methods.control}
|
55
|
+
/>
|
56
|
+
</FormProvider>
|
57
|
+
);
|
58
|
+
};
|
59
|
+
render(<Wrapper />);
|
60
|
+
};
|
61
|
+
|
62
|
+
test('should render without crashing', () => {
|
63
|
+
renderComponent();
|
64
|
+
expect(screen.getByRole('combobox')).toBeInTheDocument();
|
65
|
+
});
|
66
|
+
|
67
|
+
test('should display loading state when isLoading is true', () => {
|
68
|
+
mockUseStockItemBatchNos.mockReturnValueOnce({
|
69
|
+
isLoading: true,
|
70
|
+
stockItemBatchNos: [],
|
71
|
+
});
|
72
|
+
renderComponent();
|
73
|
+
expect(screen.getByTestId('loading')).toBeInTheDocument();
|
74
|
+
});
|
75
|
+
|
76
|
+
test('should call onBatchNoChanged when a batch is selected', async () => {
|
77
|
+
const onBatchNoChanged = jest.fn();
|
78
|
+
const Wrapper = () => {
|
79
|
+
const methods = useForm();
|
80
|
+
return (
|
81
|
+
<FormProvider {...methods}>
|
82
|
+
<BatchNoSelector
|
83
|
+
stockItemUuid={stockItemUuid}
|
84
|
+
batchUuid={batchUuid}
|
85
|
+
controllerName="batchNo"
|
86
|
+
name="batchNo"
|
87
|
+
control={methods.control}
|
88
|
+
onBatchNoChanged={onBatchNoChanged}
|
89
|
+
/>
|
90
|
+
</FormProvider>
|
91
|
+
);
|
92
|
+
};
|
93
|
+
render(<Wrapper />);
|
94
|
+
|
95
|
+
const combobox = screen.getByRole('combobox');
|
96
|
+
await userEvent.click(combobox);
|
97
|
+
await userEvent.click(screen.getByText((content) => content.includes('batch1')));
|
5
98
|
|
6
|
-
|
7
|
-
it(`renders without dying`, () => {
|
8
|
-
// render(<BatchNoSelector />);
|
99
|
+
expect(onBatchNoChanged).toHaveBeenCalledWith(mockStockItemBatchNos[0]);
|
9
100
|
});
|
10
101
|
});
|