@openmrs/esm-stock-management-app 3.3.2-pre.606 → 3.3.2-pre.608
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.
- package/dist/7193.js +15 -15
- package/dist/7193.js.map +1 -1
- package/dist/openmrs-esm-stock-management-app.js +2 -2
- package/dist/openmrs-esm-stock-management-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/stock-operations/stock-operation-types-selector/stock-operation-types-selector.component.tsx +41 -19
- package/src/stock-operations/stock-operation-types-selector/stock-operation-types-selector.test.tsx +119 -0
package/src/stock-operations/stock-operation-types-selector/stock-operation-types-selector.test.tsx
CHANGED
|
@@ -43,4 +43,123 @@ describe('StockOperationTypesSelector', () => {
|
|
|
43
43
|
expect(screen.getByText('Receipt')).toBeInTheDocument();
|
|
44
44
|
expect(screen.queryByText('Disposal')).not.toBeInTheDocument();
|
|
45
45
|
});
|
|
46
|
+
|
|
47
|
+
it('excludes Stock Issue when allowStockIssueWithoutRequisition is false', async () => {
|
|
48
|
+
const user = userEvent.setup();
|
|
49
|
+
mockOpenmrsFetch.mockImplementation((url: string) => {
|
|
50
|
+
if (url.includes('/stockmanagement/session')) {
|
|
51
|
+
return Promise.resolve({
|
|
52
|
+
data: {
|
|
53
|
+
privileges: [
|
|
54
|
+
{ privilege: TASK_STOCKMANAGEMENT_STOCKOPERATIONS_MUTATE, operationType: 'receipt' },
|
|
55
|
+
{ privilege: TASK_STOCKMANAGEMENT_STOCKOPERATIONS_MUTATE, operationType: 'stockissue' },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
} as FetchResponse);
|
|
59
|
+
}
|
|
60
|
+
if (url.includes('/systemsetting')) {
|
|
61
|
+
return Promise.resolve({
|
|
62
|
+
data: {
|
|
63
|
+
results: [{ property: 'stockmanagement.allowStockIssueWithoutRequisition', value: 'false' }],
|
|
64
|
+
},
|
|
65
|
+
} as FetchResponse);
|
|
66
|
+
}
|
|
67
|
+
return Promise.resolve({
|
|
68
|
+
data: {
|
|
69
|
+
results: [
|
|
70
|
+
{ operationType: 'receipt', name: 'Receipt' },
|
|
71
|
+
{ operationType: 'stockissue', name: 'Stock Issue' },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
} as FetchResponse);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
render(
|
|
78
|
+
<SWRConfig value={{ provider: () => new Map() }}>
|
|
79
|
+
<StockOperationTypesSelector />
|
|
80
|
+
</SWRConfig>,
|
|
81
|
+
);
|
|
82
|
+
await user.click(await screen.findByText(/Start New/));
|
|
83
|
+
|
|
84
|
+
expect(screen.getByText('Receipt')).toBeInTheDocument();
|
|
85
|
+
expect(screen.queryByText('Stock Issue')).not.toBeInTheDocument();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('includes Stock Issue when allowStockIssueWithoutRequisition is true', async () => {
|
|
89
|
+
const user = userEvent.setup();
|
|
90
|
+
mockOpenmrsFetch.mockImplementation((url: string) => {
|
|
91
|
+
if (url.includes('/stockmanagement/session')) {
|
|
92
|
+
return Promise.resolve({
|
|
93
|
+
data: {
|
|
94
|
+
privileges: [
|
|
95
|
+
{ privilege: TASK_STOCKMANAGEMENT_STOCKOPERATIONS_MUTATE, operationType: 'receipt' },
|
|
96
|
+
{ privilege: TASK_STOCKMANAGEMENT_STOCKOPERATIONS_MUTATE, operationType: 'stockissue' },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
} as FetchResponse);
|
|
100
|
+
}
|
|
101
|
+
if (url.includes('/systemsetting')) {
|
|
102
|
+
return Promise.resolve({
|
|
103
|
+
data: {
|
|
104
|
+
results: [{ property: 'stockmanagement.allowStockIssueWithoutRequisition', value: 'true' }],
|
|
105
|
+
},
|
|
106
|
+
} as FetchResponse);
|
|
107
|
+
}
|
|
108
|
+
return Promise.resolve({
|
|
109
|
+
data: {
|
|
110
|
+
results: [
|
|
111
|
+
{ operationType: 'receipt', name: 'Receipt' },
|
|
112
|
+
{ operationType: 'stockissue', name: 'Stock Issue' },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
} as FetchResponse);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
render(
|
|
119
|
+
<SWRConfig value={{ provider: () => new Map() }}>
|
|
120
|
+
<StockOperationTypesSelector />
|
|
121
|
+
</SWRConfig>,
|
|
122
|
+
);
|
|
123
|
+
await user.click(await screen.findByText(/Start New/));
|
|
124
|
+
|
|
125
|
+
expect(screen.getByText('Receipt')).toBeInTheDocument();
|
|
126
|
+
expect(screen.getByText('Stock Issue')).toBeInTheDocument();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('fails safe by hiding Stock Issue when the system setting request fails', async () => {
|
|
130
|
+
const user = userEvent.setup();
|
|
131
|
+
mockOpenmrsFetch.mockImplementation((url: string) => {
|
|
132
|
+
if (url.includes('/stockmanagement/session')) {
|
|
133
|
+
return Promise.resolve({
|
|
134
|
+
data: {
|
|
135
|
+
privileges: [
|
|
136
|
+
{ privilege: TASK_STOCKMANAGEMENT_STOCKOPERATIONS_MUTATE, operationType: 'receipt' },
|
|
137
|
+
{ privilege: TASK_STOCKMANAGEMENT_STOCKOPERATIONS_MUTATE, operationType: 'stockissue' },
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
} as FetchResponse);
|
|
141
|
+
}
|
|
142
|
+
if (url.includes('/systemsetting')) {
|
|
143
|
+
return Promise.reject(new Error('Forbidden'));
|
|
144
|
+
}
|
|
145
|
+
return Promise.resolve({
|
|
146
|
+
data: {
|
|
147
|
+
results: [
|
|
148
|
+
{ operationType: 'receipt', name: 'Receipt' },
|
|
149
|
+
{ operationType: 'stockissue', name: 'Stock Issue' },
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
} as FetchResponse);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
render(
|
|
156
|
+
<SWRConfig value={{ provider: () => new Map() }}>
|
|
157
|
+
<StockOperationTypesSelector />
|
|
158
|
+
</SWRConfig>,
|
|
159
|
+
);
|
|
160
|
+
await user.click(await screen.findByText(/Start New/));
|
|
161
|
+
|
|
162
|
+
expect(screen.getByText('Receipt')).toBeInTheDocument();
|
|
163
|
+
expect(screen.queryByText('Stock Issue')).not.toBeInTheDocument();
|
|
164
|
+
});
|
|
46
165
|
});
|