@openmrs/esm-stock-management-app 3.0.1-pre.853 → 3.0.1-pre.855

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 (108) hide show
  1. package/.husky/pre-commit +1 -4
  2. package/__mocks__/react-i18next.js +9 -8
  3. package/dist/10.js +1 -1
  4. package/dist/10.js.map +1 -1
  5. package/dist/119.js +1 -1
  6. package/dist/119.js.map +1 -1
  7. package/dist/14.js +1 -1
  8. package/dist/14.js.map +1 -1
  9. package/dist/172.js +1 -1
  10. package/dist/172.js.map +1 -1
  11. package/dist/20.js +1 -1
  12. package/dist/20.js.map +1 -1
  13. package/dist/290.js +1 -1
  14. package/dist/290.js.map +1 -1
  15. package/dist/467.js +1 -1
  16. package/dist/467.js.map +1 -1
  17. package/dist/574.js +1 -1
  18. package/dist/606.js +1 -1
  19. package/dist/606.js.map +1 -1
  20. package/dist/627.js +1 -0
  21. package/dist/627.js.map +1 -0
  22. package/dist/642.js +1 -1
  23. package/dist/642.js.map +1 -1
  24. package/dist/675.js +1 -1
  25. package/dist/675.js.map +1 -1
  26. package/dist/727.js +1 -1
  27. package/dist/727.js.map +1 -1
  28. package/dist/842.js +1 -1
  29. package/dist/842.js.map +1 -1
  30. package/dist/93.js +1 -1
  31. package/dist/93.js.map +1 -1
  32. package/dist/main.js +1 -1
  33. package/dist/main.js.map +1 -1
  34. package/dist/openmrs-esm-stock-management-app.js.buildmanifest.json +70 -70
  35. package/dist/routes.json +1 -1
  36. package/jest.config.js +3 -6
  37. package/package.json +1 -1
  38. package/src/core/components/table/table.component.tsx +2 -2
  39. package/src/index.ts +5 -5
  40. package/src/stock-items/add-bulk-stock-item/add-stock-items-bulk-import-action-button.component.tsx +3 -3
  41. package/src/stock-items/add-bulk-stock-item/{stock-items-bulk-import.modal.tsx → stock-items-bulk-import.component.tsx} +19 -20
  42. package/src/stock-items/add-bulk-stock-item/stock-items-bulk-import.resource.ts +1 -1
  43. package/src/stock-items/add-bulk-stock-item/stock-items-bulk-import.test.tsx +59 -59
  44. package/src/stock-items/add-stock-item/add-stock-action-button.component.tsx +6 -6
  45. package/src/stock-items/add-stock-item/add-stock-item.component.tsx +4 -6
  46. package/src/stock-items/add-stock-item/add-stock-item.scss +0 -5
  47. package/src/stock-items/add-stock-item/add-stock-item.test.tsx +43 -28
  48. package/src/stock-items/add-stock-item/packaging-units/packaging-units-delete-modal.component.tsx +4 -3
  49. package/src/stock-items/add-stock-item/packaging-units/packaging-units.component.tsx +10 -9
  50. package/src/stock-items/add-stock-item/packaging-units/packaging-units.scss +4 -4
  51. package/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx +19 -27
  52. package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.scss +4 -4
  53. package/src/stock-items/add-stock-item/stock-item-rules/add-stock-rules.component.tsx +9 -15
  54. package/src/stock-items/add-stock-item/stock-item-rules/add-stock-rules.scss +0 -1
  55. package/src/stock-items/add-stock-item/stock-item-rules/delete-stock-rule-modal.component.tsx +1 -2
  56. package/src/stock-items/add-stock-item/stock-item-rules/stock-item-rules.component.tsx +16 -14
  57. package/src/stock-items/add-stock-item/stock-item-rules/stock-item-rules.scss +3 -7
  58. package/src/stock-items/add-stock-item/transactions/printout/transactions-print-bincard-preview.modal.tsx +6 -14
  59. package/src/stock-items/add-stock-item/transactions/printout/transactions-print-stockcard-preview.modal.tsx +8 -14
  60. package/src/stock-items/edit-stock-item/edit-stock-item-action-menu.component.tsx +2 -2
  61. package/src/stock-items/stock-item.utils.tsx +5 -3
  62. package/src/stock-items/stock-items-table.component.tsx +45 -47
  63. package/src/stock-items/stock-items-table.resource.ts +2 -2
  64. package/src/stock-items/stock-items-table.scss +1 -5
  65. package/src/stock-items/stock-items-table.test.tsx +65 -106
  66. package/src/stock-locations/location-admin-form.component.tsx +4 -5
  67. package/src/stock-locations/stock-locations-table.component.tsx +8 -10
  68. package/src/stock-lookups/stock-lookups.resource.ts +2 -3
  69. package/src/stock-operations/stock-operations-dialog/stock-operations-dialog.component.tsx +2 -2
  70. package/src/stock-operations/stock-operations-forms/input-components/batch-no-selector.component.tsx +11 -11
  71. package/src/stock-operations/stock-operations-forms/input-components/batch-no-selector.test.tsx +25 -115
  72. package/src/stock-operations/stock-operations-forms/input-components/qty-uim-selector.test.tsx +65 -107
  73. package/src/stock-operations/stock-operations-forms/input-components/quantity-uom-selector.component.tsx +9 -9
  74. package/src/stock-operations/stock-operations-forms/input-components/stock-operation-reason-selector.test.tsx +153 -35
  75. package/src/stock-operations/stock-operations-forms/input-components/user-selector.test.tsx +29 -82
  76. package/src/stock-operations/stock-operations-forms/step1.test.tsx +69 -204
  77. package/src/stock-operations/stock-operations-forms/step2.test.tsx +63 -140
  78. package/src/stock-operations/stock-operations-forms/step3.test.tsx +60 -79
  79. package/src/stock-operations/stock-operations-forms/steps/stock-operation-items-form-step.component.tsx +5 -6
  80. package/src/stock-operations/stock-operations-forms/steps/stock-operation-submission-form-step.component.tsx +11 -12
  81. package/src/stock-operations/stock-operations-forms/stock-item-form/stock-item-form.scss +0 -1
  82. package/src/stock-operations/stock-operations-forms/stock-item-form/stock-item-form.workspace.tsx +12 -20
  83. package/src/stock-operations/stock-operations-forms/stock-operation-form.scss +0 -1
  84. package/src/stock-operations/stock-operations-forms/stock-operation-stepper/stepper.scss +3 -1
  85. package/src/stock-operations/stock-operations-forms/stock-operation-stepper/stock-operation-stepper.component.tsx +1 -2
  86. package/src/stock-reports/generate-report/create-stock-report.scss +2 -3
  87. package/src/stock-reports/generate-report/create-stock-report.workspace.tsx +25 -32
  88. package/src/stock-reports/report-list/stock-report-parameters.component.tsx +1 -1
  89. package/src/stock-reports/report-list/stock-report-status.component.tsx +1 -1
  90. package/src/stock-reports/report-list/stock-reports.component.tsx +25 -24
  91. package/src/stock-reports/report-list/stock-reports.scss +2 -10
  92. package/src/stock-sources/add-stock-sources/add-stock-sources.scss +4 -11
  93. package/src/stock-sources/add-stock-sources/add-stock-sources.test.tsx +36 -38
  94. package/src/stock-sources/add-stock-sources/add-stock-sources.workspace.tsx +30 -35
  95. package/src/stock-sources/delete-stock-modal.component.tsx +1 -2
  96. package/src/stock-sources/stock-sources-delete/stock-sources-delete.test.tsx +36 -27
  97. package/src/stock-sources/stock-sources-filter/stock-sources-filter.component.tsx +21 -33
  98. package/src/stock-sources/stock-sources-items-table.component.tsx +17 -16
  99. package/src/stock-sources/stock-sources-items-table.resource.ts +6 -8
  100. package/src/stock-sources/stock-sources-items-table.test.tsx +37 -60
  101. package/src/stock-sources/stock-sources.scss +2 -6
  102. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.scss +13 -5
  103. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.workspace.tsx +2 -2
  104. package/src/stock-user-role-scopes/delete-stock-user-scope-modal.component.tsx +1 -2
  105. package/translations/en.json +6 -5
  106. package/tsconfig.json +0 -4
  107. package/dist/33.js +0 -1
  108. package/dist/33.js.map +0 -1
@@ -1,66 +1,64 @@
1
- import React from 'react';
2
- import userEvent from '@testing-library/user-event';
3
1
  import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import React from 'react';
4
4
  import { useStockItem } from '../../../stock-items/stock-items.resource';
5
5
  import QtyUomSelector from './quantity-uom-selector.component';
6
6
 
7
- jest.mock('../../../stock-items/stock-items.resource', () => ({
8
- useStockItem: jest.fn().mockReturnValue({
9
- isLoading: false,
10
- item: {},
11
- error: null,
12
- }),
13
- useStockItems: jest.fn().mockReturnValue({
14
- isLoading: false,
15
- error: null,
16
- items: {},
17
- }),
18
- useStockBatches: jest.fn().mockReturnValue({
19
- isLoading: false,
20
- error: null,
21
- items: {},
22
- }),
7
+ jest.mock('../../../stock-items/stock-items.resource');
8
+ jest.mock('react-i18next', () => ({
9
+ useTranslation: () => ({ t: (key: string) => key }),
23
10
  }));
24
11
 
25
- const mockUseStockItem = jest.mocked(useStockItem);
12
+ const mockUseStockItem = useStockItem as jest.Mock;
26
13
 
27
14
  describe('QtyUOMSelector', () => {
28
15
  const mockOnValueChange = jest.fn();
29
16
  const mockStockItemUuid = 'test-uuid';
30
-
31
- const mockStockItem = {
32
- acronym: null,
33
- categoryName: 'Other Lymph Node Comments',
34
- categoryUuid: '183f9497-b72e-4ebe-ae17-5dcf110ff3b6',
35
- commonName: 'Ibuprofen 5 MG/ML Injectable Solution',
36
- conceptName: 'IBUPROFEN',
17
+ const mockitem = {
18
+ uuid: '33225466-93c8-4720-b110-4f445f3764c6',
19
+ drugUuid: '1776AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
20
+ drugName: 'Ibuprofen Injection solution 5mg/mL ',
37
21
  conceptUuid: '77897AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
38
- creatorFamilyName: 'Miller',
39
- creatorGivenName: 'Mark',
40
- dateCreated: new Date('2024-09-03T09:46:47.000+0300'),
41
- defaultStockOperationsUoMFactor: null,
42
- defaultStockOperationsUoMName: null,
43
- defaultStockOperationsUoMUuid: null,
22
+ conceptName: 'IBUPROFEN',
23
+ hasExpiration: true,
24
+ preferredVendorUuid: 'b7e481ef-06e7-46ba-8a7c-ab077aa3355f',
25
+ preferredVendorName: 'Kenya Medical Supplies Authority',
26
+ purchasePrice: 100.0,
27
+ purchasePriceUoMUuid: '65dc9ec7-0663-4cf0-a35c-6a2d2cf99eee',
28
+ purchasePriceUoMName: 'Box',
29
+ purchasePriceUoMFactor: 10.0,
44
30
  dispensingUnitName: 'Tablet',
45
- dispensingUnitPackagingUoMFactor: 10.0,
46
- dispensingUnitPackagingUoMName: 'Box',
47
- dispensingUnitPackagingUoMUuid: '65dc9ec7-0663-4cf0-a35c-6a2d2cf99eee',
48
31
  dispensingUnitUuid: '1513AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
49
- drugName: 'Ibuprofen Injection solution 5mg/mL ',
50
- drugUuid: '1776AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
32
+ dispensingUnitPackagingUoMUuid: '65dc9ec7-0663-4cf0-a35c-6a2d2cf99eee',
33
+ dispensingUnitPackagingUoMName: 'Box',
34
+ dispensingUnitPackagingUoMFactor: 10.0,
35
+ defaultStockOperationsUoMUuid: null,
36
+ defaultStockOperationsUoMName: null,
37
+ defaultStockOperationsUoMFactor: null,
38
+ categoryUuid: '183f9497-b72e-4ebe-ae17-5dcf110ff3b6',
39
+ categoryName: 'Other Lymph Node Comments',
40
+ commonName: 'Ibuprofen 5 MG/ML Injectable Solution',
41
+ acronym: null,
42
+ reorderLevel: null,
43
+ reorderLevelUoMUuid: null,
44
+ reorderLevelUoMName: null,
45
+ reorderLevelUoMFactor: null,
46
+ dateCreated: '2024-09-03T09:46:47.000+0300',
47
+ creatorGivenName: 'Mark',
48
+ creatorFamilyName: 'Miller',
49
+ voided: false,
51
50
  expiryNotice: 180,
52
- hasExpiration: true,
53
- isDrug: true,
54
- links: [
55
- {
56
- rel: 'self',
57
- uri: 'http://hie.kenyahmis.org/openmrs/ws/rest/v1/stockmanagement/stockitem/33225466-93c8-4720-b110-4f445f3764c6',
58
- resourceAlias: 'stockitem',
59
- },
60
- ],
51
+ permission: {
52
+ canView: true,
53
+ canEdit: true,
54
+ },
61
55
  packagingUnits: [
62
56
  {
57
+ uuid: '8023ef7d-56da-442f-bc74-319f000840b4',
63
58
  factor: 1.0,
59
+ packagingUomUuid: '162382AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
60
+ packagingUomName: 'Vial',
61
+ stockItemUuid: '33225466-93c8-4720-b110-4f445f3764c6',
64
62
  isDefaultStockOperationsUoM: false,
65
63
  isDispensingUnit: false,
66
64
  links: [
@@ -70,14 +68,14 @@ describe('QtyUOMSelector', () => {
70
68
  resourceAlias: 'stockitempackaginguom',
71
69
  },
72
70
  ],
73
- packagingUomName: 'Vial',
74
- packagingUomUuid: '162382AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
75
71
  resourceVersion: '1.8',
76
- stockItemUuid: '33225466-93c8-4720-b110-4f445f3764c6',
77
- uuid: '8023ef7d-56da-442f-bc74-319f000840b4',
78
72
  },
79
73
  {
74
+ uuid: '65dc9ec7-0663-4cf0-a35c-6a2d2cf99eee',
80
75
  factor: 10.0,
76
+ packagingUomUuid: '162396AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
77
+ packagingUomName: 'Box',
78
+ stockItemUuid: '33225466-93c8-4720-b110-4f445f3764c6',
81
79
  isDefaultStockOperationsUoM: false,
82
80
  isDispensingUnit: true,
83
81
  links: [
@@ -87,113 +85,73 @@ describe('QtyUOMSelector', () => {
87
85
  resourceAlias: 'stockitempackaginguom',
88
86
  },
89
87
  ],
90
- packagingUomName: 'Box',
91
- packagingUomUuid: '162396AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
92
88
  resourceVersion: '1.8',
93
- stockItemUuid: '33225466-93c8-4720-b110-4f445f3764c6',
94
- uuid: '65dc9ec7-0663-4cf0-a35c-6a2d2cf99eee',
95
89
  },
96
90
  ],
97
- permission: {
98
- canApprove: false,
99
- canDisplayReceivedItems: false,
100
- canEdit: true,
101
- canReceiveItems: false,
102
- canUpdateBatchInformation: false,
103
- canView: true,
104
- isRequisitionAndCanIssueStock: false,
105
- },
106
- preferredVendorName: 'Kenya Medical Supplies Authority',
107
- preferredVendorUuid: 'b7e481ef-06e7-46ba-8a7c-ab077aa3355f',
108
- purchasePrice: 100.0,
109
- purchasePriceUoMFactor: 10.0,
110
- purchasePriceUoMName: 'Box',
111
- purchasePriceUoMUuid: '65dc9ec7-0663-4cf0-a35c-6a2d2cf99eee',
112
- reorderLevel: null,
113
- reorderLevelUoMFactor: null,
114
- reorderLevelUoMName: null,
115
- reorderLevelUoMUuid: null,
91
+ references: [],
92
+ links: [
93
+ {
94
+ rel: 'self',
95
+ uri: 'http://hie.kenyahmis.org/openmrs/ws/rest/v1/stockmanagement/stockitem/33225466-93c8-4720-b110-4f445f3764c6',
96
+ resourceAlias: 'stockitem',
97
+ },
98
+ ],
116
99
  resourceVersion: '1.8',
117
- uuid: '33225466-93c8-4720-b110-4f445f3764c6',
118
- voided: false,
119
100
  };
120
101
 
121
102
  beforeEach(() => {
103
+ jest.clearAllMocks();
122
104
  mockUseStockItem.mockReturnValue({
123
105
  isLoading: false,
124
- item: mockStockItem,
125
- error: null,
106
+ item: mockitem,
126
107
  });
127
108
  });
128
-
129
109
  it('should render Skeleton when loading stock item', () => {
130
- mockUseStockItem.mockReturnValue({ isLoading: true, item: mockStockItem, error: null });
131
-
110
+ mockUseStockItem.mockReturnValue({ isLoading: true });
132
111
  render(<QtyUomSelector stockItemUuid={mockStockItemUuid} onValueChange={mockOnValueChange} />);
133
-
134
112
  expect(screen.getByRole('progressbar')).toBeInTheDocument();
135
113
  });
136
-
137
114
  it('should render Inline notification error when error ocuured while fetching item', () => {
138
115
  const errorMessage = 'error loading stock item';
139
- mockUseStockItem.mockReturnValue({ isLoading: false, error: new Error(errorMessage), item: mockStockItem });
140
-
116
+ mockUseStockItem.mockReturnValue({ isLoading: false, error: new Error(errorMessage) });
141
117
  render(<QtyUomSelector stockItemUuid={mockStockItemUuid} onValueChange={mockOnValueChange} />);
142
-
143
118
  expect(screen.getByText(errorMessage)).toBeInTheDocument();
144
119
  expect(screen.getByRole('status')).toBeInTheDocument();
145
120
  });
146
-
147
121
  it('should render Inline notification error when error ocuured while fetching item', () => {
148
122
  const errorMessage = 'error loading stock item';
149
- mockUseStockItem.mockReturnValue({ isLoading: false, error: new Error(errorMessage), item: mockStockItem });
150
-
123
+ mockUseStockItem.mockReturnValue({ isLoading: false, error: new Error(errorMessage) });
151
124
  render(<QtyUomSelector stockItemUuid={mockStockItemUuid} onValueChange={mockOnValueChange} />);
152
-
153
125
  expect(screen.getByText(errorMessage)).toBeInTheDocument();
154
126
  expect(screen.getByRole('status')).toBeInTheDocument();
155
127
  });
156
128
 
157
129
  it('should display error message when error prop is provided', () => {
158
130
  const errorMessage = 'This is an error';
159
-
160
131
  render(<QtyUomSelector stockItemUuid={mockStockItemUuid} onValueChange={mockOnValueChange} error={errorMessage} />);
161
-
162
132
  expect(screen.getByText(errorMessage)).toBeInTheDocument();
163
133
  });
164
-
165
134
  it('should display error message when error prop is provided', () => {
166
135
  const errorMessage = 'This is an error';
167
-
168
136
  render(<QtyUomSelector stockItemUuid={mockStockItemUuid} onValueChange={mockOnValueChange} error={errorMessage} />);
169
-
170
137
  expect(screen.getByText(errorMessage)).toBeInTheDocument();
171
138
  });
172
139
 
173
140
  it('should render packing uom options', async () => {
174
- const user = userEvent.setup();
175
-
176
141
  render(<QtyUomSelector stockItemUuid={mockStockItemUuid} onValueChange={mockOnValueChange} />);
177
-
178
142
  const combobox = screen.getByRole('combobox');
179
- await user.click(combobox);
180
-
181
- mockStockItem.packagingUnits.forEach(({ factor, packagingUomName }) => {
143
+ await userEvent.click(combobox);
144
+ mockitem.packagingUnits.forEach(({ factor, packagingUomName }) => {
182
145
  expect(screen.getByText(`${packagingUomName} - ${factor}`)).toBeInTheDocument();
183
146
  });
184
147
  });
185
-
186
148
  it('should packing uom selection', async () => {
187
- const user = userEvent.setup();
188
- const itemToSelect = mockStockItem.packagingUnits[1];
189
-
149
+ const itemToSelect = mockitem.packagingUnits[1];
190
150
  render(<QtyUomSelector stockItemUuid={mockStockItemUuid} onValueChange={mockOnValueChange} />);
191
-
192
151
  const combobox = screen.getByRole('combobox');
193
152
  await userEvent.click(combobox);
194
-
195
153
  const option = screen.getByText(`${itemToSelect.packagingUomName} - ${itemToSelect.factor}`);
196
- await user.click(option);
154
+ await userEvent.click(option);
197
155
  expect(mockOnValueChange).toHaveBeenCalledWith(itemToSelect.uuid);
198
156
  });
199
157
  });
@@ -1,5 +1,5 @@
1
- import React, { useMemo } from 'react';
2
1
  import { ComboBox, InlineNotification, SkeletonText } from '@carbon/react';
2
+ import React, { useMemo } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { type StockItemPackagingUOMDTO } from '../../../core/api/types/stockItem/StockItemPackagingUOM';
5
5
  import { useStockItem } from '../../../stock-items/stock-items.resource';
@@ -32,20 +32,20 @@ const QtyUomSelector: React.FC<QtyUomSelectorProps> = ({ stockItemUuid, error, i
32
32
 
33
33
  return (
34
34
  <ComboBox
35
+ titleText={t('quantityUom', 'Qty UoM')}
36
+ name={'stockItemPackagingUOMUuid'}
35
37
  id={'stockItemPackagingUOMUuid'}
36
- initialSelectedItem={initialSelectedItem}
37
- invalid={!!error}
38
- invalidText={error}
39
38
  items={item?.packagingUnits ?? []}
40
- itemToString={(s: StockItemPackagingUOMDTO) =>
41
- s.packagingUomName ? `${s?.packagingUomName} - ${s?.factor} ` : ''
42
- }
43
- name={'stockItemPackagingUOMUuid'}
44
39
  onChange={(data: { selectedItem?: StockItemPackagingUOMDTO }) => {
45
40
  onValueChange?.(data.selectedItem?.uuid);
46
41
  }}
42
+ initialSelectedItem={initialSelectedItem}
43
+ itemToString={(s: StockItemPackagingUOMDTO) =>
44
+ s.packagingUomName ? `${s?.packagingUomName} - ${s?.factor} ` : ''
45
+ }
47
46
  placeholder={t('filter', 'Filter') + '...'}
48
- titleText={t('quantityUom', 'Qty UoM')}
47
+ invalid={error}
48
+ invalidText={error}
49
49
  />
50
50
  );
51
51
  };
@@ -1,97 +1,215 @@
1
- import React from 'react';
2
- import userEvent from '@testing-library/user-event';
3
1
  import { render, screen } from '@testing-library/react';
4
- import { type FieldValues, useFormContext, type UseFormReturn } from 'react-hook-form';
2
+ import userEvent from '@testing-library/user-event';
3
+ import React from 'react';
4
+
5
5
  import { useConfig } from '@openmrs/esm-framework';
6
+ import { useFormContext } from 'react-hook-form';
6
7
  import { useConcept } from '../../../stock-lookups/stock-lookups.resource';
7
8
  import StockOperationReasonSelector from './stock-operation-reason-selector.component';
8
9
 
9
- const mockUseConfig = jest.mocked(useConfig);
10
- const mockUseConcept = jest.mocked(useConcept);
11
- const mockUseFormContext = jest.mocked(useFormContext);
10
+ // Mock the hooks
11
+ jest.mock('@openmrs/esm-framework', () => ({
12
+ useConfig: jest.fn(),
13
+ }));
12
14
 
13
15
  jest.mock('react-hook-form', () => ({
14
16
  useFormContext: jest.fn(),
15
17
  Controller: ({ render }) => render({ field: {}, fieldState: {} }),
16
18
  }));
17
-
18
- jest.mock('../../../stock-lookups/stock-lookups.resource', () => ({
19
- useConcept: jest.fn(),
19
+ jest.mock('../../../stock-lookups/stock-lookups.resource');
20
+ jest.mock('react-i18next', () => ({
21
+ useTranslation: () => ({ t: (key: string) => key }),
20
22
  }));
21
23
 
24
+ const mockUseConcept = useConcept as jest.Mock;
25
+ const mockUseConfig = useConfig as jest.Mock;
26
+ const mockUseFormContext = useFormContext as jest.Mock;
27
+
22
28
  describe('StockoperationReasonSelector', () => {
23
- const mockConcept = {
29
+ const mockConcepts = {
30
+ uuid: '3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25',
31
+ display: 'Stock Adjustment Reason',
32
+ name: {
33
+ display: 'Stock Adjustment Reason',
34
+ uuid: '4eb6556a-a2d4-4e85-9b62-4d076a1063fc',
35
+ name: 'Stock Adjustment Reason',
36
+ locale: 'en',
37
+ localePreferred: true,
38
+ conceptNameType: 'FULLY_SPECIFIED',
39
+ links: [
40
+ {
41
+ rel: 'self',
42
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25/name/4eb6556a-a2d4-4e85-9b62-4d076a1063fc',
43
+ resourceAlias: 'name',
44
+ },
45
+ {
46
+ rel: 'full',
47
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25/name/4eb6556a-a2d4-4e85-9b62-4d076a1063fc?v=full',
48
+ resourceAlias: 'name',
49
+ },
50
+ ],
51
+ resourceVersion: '1.9',
52
+ },
53
+ datatype: {
54
+ uuid: '8d4a48b6-c2cc-11de-8d13-0010c6dffd0f',
55
+ display: 'Coded',
56
+ links: [
57
+ {
58
+ rel: 'self',
59
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/conceptdatatype/8d4a48b6-c2cc-11de-8d13-0010c6dffd0f',
60
+ resourceAlias: 'conceptdatatype',
61
+ },
62
+ ],
63
+ },
64
+ conceptClass: {
65
+ uuid: '8d491e50-c2cc-11de-8d13-0010c6dffd0f',
66
+ display: 'Question',
67
+ links: [
68
+ {
69
+ rel: 'self',
70
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/conceptclass/8d491e50-c2cc-11de-8d13-0010c6dffd0f',
71
+ resourceAlias: 'conceptclass',
72
+ },
73
+ ],
74
+ },
75
+ set: false,
76
+ version: null,
77
+ retired: false,
78
+ names: [
79
+ {
80
+ uuid: '4eb6556a-a2d4-4e85-9b62-4d076a1063fc',
81
+ display: 'Stock Adjustment Reason',
82
+ links: [
83
+ {
84
+ rel: 'self',
85
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25/name/4eb6556a-a2d4-4e85-9b62-4d076a1063fc',
86
+ resourceAlias: 'name',
87
+ },
88
+ ],
89
+ },
90
+ {
91
+ uuid: '36eb0855-c810-4816-9bed-1de5c615e702',
92
+ display: 'Stock Adjustment Reason',
93
+ links: [
94
+ {
95
+ rel: 'self',
96
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25/name/36eb0855-c810-4816-9bed-1de5c615e702',
97
+ resourceAlias: 'name',
98
+ },
99
+ ],
100
+ },
101
+ ],
102
+ descriptions: [
103
+ {
104
+ uuid: '67311e07-1935-448b-8305-7d11abf0de63',
105
+ display: 'Stock Adjustment Reason',
106
+ links: [
107
+ {
108
+ rel: 'self',
109
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25/description/67311e07-1935-448b-8305-7d11abf0de63',
110
+ resourceAlias: 'description',
111
+ },
112
+ ],
113
+ },
114
+ ],
115
+ mappings: [],
24
116
  answers: [
25
117
  {
26
118
  uuid: '165420AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
27
119
  display: 'Drug not available due to expired medication',
120
+ links: [
121
+ {
122
+ rel: 'self',
123
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/165420AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
124
+ resourceAlias: 'concept',
125
+ },
126
+ ],
28
127
  },
29
128
  {
30
129
  uuid: '160584AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
31
130
  display: 'Lost or ran out of medication',
131
+ links: [
132
+ {
133
+ rel: 'self',
134
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/160584AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
135
+ resourceAlias: 'concept',
136
+ },
137
+ ],
32
138
  },
33
139
  {
34
140
  uuid: '122835AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
35
141
  display: 'Work Shift Change',
142
+ links: [
143
+ {
144
+ rel: 'self',
145
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/122835AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
146
+ resourceAlias: 'concept',
147
+ },
148
+ ],
36
149
  },
37
150
  {
38
151
  uuid: '160561AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
39
152
  display: 'New drug available',
153
+ links: [
154
+ {
155
+ rel: 'self',
156
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/160561AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
157
+ resourceAlias: 'concept',
158
+ },
159
+ ],
40
160
  },
41
161
  ],
162
+ setMembers: [],
163
+ attributes: [],
164
+ links: [
165
+ {
166
+ rel: 'self',
167
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25',
168
+ resourceAlias: 'concept',
169
+ },
170
+ {
171
+ rel: 'full',
172
+ uri: 'http://qa.kenyahmis.org/openmrs/ws/rest/v1/concept/3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25?v=full',
173
+ resourceAlias: 'concept',
174
+ },
175
+ ],
176
+ resourceVersion: '2.0',
42
177
  };
43
-
44
178
  beforeEach(() => {
45
- mockUseConfig.mockReturnValue({
46
- stockAdjustmentReasonUUID: '3bbfaa44-d5b8-404d-b4c1-2bf49ad8ce25',
47
- });
48
- mockUseFormContext.mockReturnValue({
49
- control: {},
50
- formState: { errors: {} },
51
- } as UseFormReturn<FieldValues>);
179
+ jest.clearAllMocks();
180
+ mockUseConfig.mockReturnValue({ stockAdjustmentReasonUUID: 'uuid' });
52
181
  mockUseConcept.mockReturnValue({
53
182
  isLoading: false,
54
- items: mockConcept as any,
55
- error: null,
183
+ items: mockConcepts,
56
184
  });
57
185
  });
58
186
 
59
187
  it('should display loading state while loading reason concepts', () => {
60
- mockUseFormContext.mockReturnValue({ control: {} } as UseFormReturn<FieldValues>);
188
+ mockUseFormContext.mockReturnValue({ control: {} });
61
189
  mockUseConcept.mockReturnValue({
62
190
  isLoading: true,
63
- items: mockConcept as any,
64
- error: null,
191
+ items: mockConcepts,
65
192
  });
66
-
67
193
  render(<StockOperationReasonSelector />);
68
-
69
194
  expect(screen.getByRole('progressbar')).toBeInTheDocument();
70
195
  });
71
-
72
196
  it('should display error notification when error encountered while fetching concepts', () => {
73
197
  const errorMessahe = 'Error message';
74
198
  mockUseConcept.mockReturnValue({
75
199
  isLoading: false,
76
- items: mockConcept as any,
200
+ items: mockConcepts,
77
201
  error: new Error(errorMessahe),
78
202
  });
79
-
80
203
  render(<StockOperationReasonSelector />);
81
-
82
204
  expect(screen.getByRole('status')).toBeInTheDocument();
83
205
  expect(screen.getByText(errorMessahe)).toBeInTheDocument();
84
206
  });
85
207
 
86
208
  it('renders ComboBox with reasons', async () => {
87
- const user = userEvent.setup();
88
-
89
209
  render(<StockOperationReasonSelector />);
90
-
91
210
  const combobox = screen.getByRole('combobox');
92
- await user.click(combobox);
93
-
94
- mockConcept.answers.forEach((ans) => {
211
+ await userEvent.click(combobox);
212
+ mockConcepts.answers.forEach((ans) => {
95
213
  expect(screen.getByText(`${ans?.display}`)).toBeInTheDocument();
96
214
  });
97
215
  });