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

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 (126) hide show
  1. package/.husky/pre-commit +4 -1
  2. package/__mocks__/react-i18next.js +8 -9
  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/33.js +1 -0
  16. package/dist/33.js.map +1 -0
  17. package/dist/467.js +1 -1
  18. package/dist/467.js.map +1 -1
  19. package/dist/574.js +1 -1
  20. package/dist/606.js +1 -1
  21. package/dist/606.js.map +1 -1
  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 +6 -3
  37. package/package.json +1 -1
  38. package/src/core/components/overlay/overlay.scss +1 -1
  39. package/src/core/components/privilages-component/privilages.scss +1 -1
  40. package/src/core/components/table/table.component.tsx +2 -2
  41. package/src/core/components/table/table.scss +1 -1
  42. package/src/core/components/tabs/vertical-tabs.scss +1 -1
  43. package/src/index.ts +5 -5
  44. package/src/stock-items/add-bulk-stock-item/add-stock-items-bulk-import-action-button.component.tsx +3 -3
  45. package/src/stock-items/add-bulk-stock-item/{stock-items-bulk-import.component.tsx → stock-items-bulk-import.modal.tsx} +20 -19
  46. package/src/stock-items/add-bulk-stock-item/stock-items-bulk-import.resource.ts +1 -1
  47. package/src/stock-items/add-bulk-stock-item/stock-items-bulk-import.test.tsx +59 -59
  48. package/src/stock-items/add-stock-item/add-stock-action-button.component.tsx +6 -6
  49. package/src/stock-items/add-stock-item/add-stock-item.component.tsx +6 -4
  50. package/src/stock-items/add-stock-item/add-stock-item.scss +5 -0
  51. package/src/stock-items/add-stock-item/add-stock-item.test.tsx +28 -43
  52. package/src/stock-items/add-stock-item/packaging-units/packaging-units-delete-modal.component.tsx +3 -4
  53. package/src/stock-items/add-stock-item/packaging-units/packaging-units.component.tsx +9 -10
  54. package/src/stock-items/add-stock-item/packaging-units/packaging-units.scss +4 -4
  55. package/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx +27 -19
  56. package/src/stock-items/add-stock-item/stock-item-details/stock-item-details.scss +1 -1
  57. package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.scss +4 -4
  58. package/src/stock-items/add-stock-item/stock-item-rules/add-stock-rules.component.tsx +15 -9
  59. package/src/stock-items/add-stock-item/stock-item-rules/add-stock-rules.scss +1 -0
  60. package/src/stock-items/add-stock-item/stock-item-rules/delete-stock-rule-modal.component.tsx +2 -1
  61. package/src/stock-items/add-stock-item/stock-item-rules/stock-item-rules.component.tsx +14 -16
  62. package/src/stock-items/add-stock-item/stock-item-rules/stock-item-rules.scss +7 -3
  63. package/src/stock-items/add-stock-item/transactions/printout/transactions-print-bincard-preview.modal.tsx +14 -6
  64. package/src/stock-items/add-stock-item/transactions/printout/transactions-print-stockcard-preview.modal.tsx +14 -8
  65. package/src/stock-items/edit-stock-item/edit-stock-item-action-menu.component.tsx +2 -2
  66. package/src/stock-items/stock-item.utils.tsx +3 -5
  67. package/src/stock-items/stock-items-table.component.tsx +47 -45
  68. package/src/stock-items/stock-items-table.resource.ts +2 -2
  69. package/src/stock-items/stock-items-table.scss +9 -8
  70. package/src/stock-items/stock-items-table.test.tsx +106 -65
  71. package/src/stock-items/stock-items.component.tsx +1 -1
  72. package/src/stock-locations/location-admin-form.component.tsx +5 -4
  73. package/src/stock-locations/stock-locations-table.component.tsx +10 -8
  74. package/src/stock-locations/stock-locations.component.tsx +1 -1
  75. package/src/stock-lookups/stock-lookups.resource.ts +3 -2
  76. package/src/stock-management-header/stock-management-header.scss +1 -1
  77. package/src/stock-operations/add-stock-operation/stock-operations-expanded-row/stock-operation-expanded-row.scss +1 -1
  78. package/src/stock-operations/stock-operations-dialog/stock-operations-dialog.component.tsx +2 -2
  79. package/src/stock-operations/stock-operations-filters.component.tsx +5 -5
  80. package/src/stock-operations/stock-operations-forms/input-components/batch-no-selector.component.tsx +11 -11
  81. package/src/stock-operations/stock-operations-forms/input-components/batch-no-selector.test.tsx +115 -25
  82. package/src/stock-operations/stock-operations-forms/input-components/qty-uim-selector.test.tsx +107 -65
  83. package/src/stock-operations/stock-operations-forms/input-components/quantity-uom-selector.component.tsx +9 -9
  84. package/src/stock-operations/stock-operations-forms/input-components/stock-operation-reason-selector.test.tsx +35 -153
  85. package/src/stock-operations/stock-operations-forms/input-components/user-selector.test.tsx +82 -29
  86. package/src/stock-operations/stock-operations-forms/step1.test.tsx +204 -69
  87. package/src/stock-operations/stock-operations-forms/step2.test.tsx +140 -63
  88. package/src/stock-operations/stock-operations-forms/step3.test.tsx +79 -60
  89. package/src/stock-operations/stock-operations-forms/steps/stock-operation-items-form-step.component.tsx +6 -5
  90. package/src/stock-operations/stock-operations-forms/steps/stock-operation-submission-form-step.component.tsx +12 -11
  91. package/src/stock-operations/stock-operations-forms/stock-item-form/stock-item-form.scss +1 -0
  92. package/src/stock-operations/stock-operations-forms/stock-item-form/stock-item-form.workspace.tsx +20 -12
  93. package/src/stock-operations/stock-operations-forms/stock-operation-form.scss +1 -0
  94. package/src/stock-operations/stock-operations-forms/stock-operation-stepper/stepper.scss +1 -3
  95. package/src/stock-operations/stock-operations-forms/stock-operation-stepper/stock-operation-stepper.component.tsx +2 -1
  96. package/src/stock-operations/stock-operations-table.component.tsx +66 -73
  97. package/src/stock-operations/stock-operations-table.scss +18 -9
  98. package/src/stock-operations/stock-operations.component.tsx +1 -1
  99. package/src/stock-reports/generate-report/create-stock-report.scss +3 -2
  100. package/src/stock-reports/generate-report/create-stock-report.workspace.tsx +32 -25
  101. package/src/stock-reports/report-list/stock-report-parameters.component.tsx +1 -1
  102. package/src/stock-reports/report-list/stock-report-status.component.tsx +1 -1
  103. package/src/stock-reports/report-list/stock-reports.component.tsx +24 -25
  104. package/src/stock-reports/report-list/stock-reports.scss +11 -3
  105. package/src/stock-sources/add-stock-sources/add-stock-sources.scss +12 -5
  106. package/src/stock-sources/add-stock-sources/add-stock-sources.test.tsx +38 -36
  107. package/src/stock-sources/add-stock-sources/add-stock-sources.workspace.tsx +35 -30
  108. package/src/stock-sources/delete-stock-modal.component.tsx +2 -1
  109. package/src/stock-sources/delete-stock-modal.scss +1 -1
  110. package/src/stock-sources/stock-sources-delete/stock-sources-delete.test.tsx +27 -36
  111. package/src/stock-sources/stock-sources-filter/stock-sources-filter.component.tsx +33 -21
  112. package/src/stock-sources/stock-sources-items-table.component.tsx +16 -17
  113. package/src/stock-sources/stock-sources-items-table.resource.ts +8 -6
  114. package/src/stock-sources/stock-sources-items-table.test.tsx +60 -37
  115. package/src/stock-sources/stock-sources.component.tsx +1 -1
  116. package/src/stock-sources/stock-sources.scss +6 -2
  117. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.scss +5 -13
  118. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.workspace.tsx +2 -2
  119. package/src/stock-user-role-scopes/delete-stock-user-scope-modal.component.tsx +2 -1
  120. package/src/stock-user-role-scopes/delete-stock-user-scope-modal.scss +1 -1
  121. package/src/stock-user-role-scopes/stock-user-role-scopes.component.tsx +1 -1
  122. package/src/stock-user-role-scopes/stock-user-role-scopes.scss +1 -1
  123. package/translations/en.json +5 -6
  124. package/tsconfig.json +4 -0
  125. package/dist/627.js +0 -1
  126. package/dist/627.js.map +0 -1
@@ -1,42 +1,51 @@
1
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
2
1
  import React from 'react';
3
- import { useFormContext } from 'react-hook-form';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { render, screen } from '@testing-library/react';
4
+ import { useFormContext, type Control, type FieldValues, type UseFormReturn } from 'react-hook-form';
5
+ import { otherUser } from '../../../core/utils/utils';
4
6
  import { useUser } from '../../../stock-lookups/stock-lookups.resource';
5
7
  import useSearchUser from '../hooks/useSearchUser';
6
8
  import UsersSelector from './users-selector.component';
7
- import { otherUser } from '../../../core/utils/utils';
8
- import userEvent from '@testing-library/user-event';
9
9
 
10
- jest.mock('../hooks/useSearchUser');
11
- jest.mock('../../../stock-lookups/stock-lookups.resource');
10
+ jest.mock('../hooks/useSearchUser', () => ({
11
+ __esModule: true,
12
+ default: jest.fn(),
13
+ }));
14
+
15
+ jest.mock('../../../stock-lookups/stock-lookups.resource', () => ({
16
+ useUser: jest.fn(),
17
+ }));
18
+
12
19
  jest.mock('react-hook-form', () => ({
13
20
  useFormContext: jest.fn(),
14
21
  Controller: ({ render }) => render({ field: {}, fieldState: {} }),
15
22
  }));
16
- jest.mock('react-i18next', () => ({
17
- useTranslation: () => ({ t: (key: string) => key }),
18
- }));
19
23
 
20
- const mockUseSearchUser = useSearchUser as jest.Mock;
21
- const mockUseUser = useUser as jest.Mock;
22
- const mockUseFormContext = useFormContext as jest.Mock;
24
+ const mockUseSearchUser = jest.mocked(useSearchUser);
25
+ const mockUseUser = jest.mocked(useUser);
26
+ const mockUseFormContext = jest.mocked(useFormContext);
23
27
 
24
- describe('UsersSelector', () => {
28
+ describe('User Selector', () => {
25
29
  beforeEach(() => {
26
- jest.clearAllMocks();
27
30
  mockUseFormContext.mockReturnValue({
28
- control: {},
31
+ control: {} as Control<FieldValues>,
29
32
  watch: jest.fn().mockImplementation((field) => {
30
33
  if (field === 'responsiblePersonUuid') return 'responsibleperson.uuid';
31
34
  if (field === 'responsiblePersonOther') return 'responsiblepersonother.uuid';
32
35
  return '';
33
36
  }),
34
37
  resetField: jest.fn(),
35
- });
38
+ } as Partial<UseFormReturn<FieldValues>> as UseFormReturn<FieldValues>);
36
39
  });
37
40
 
38
41
  it('renders loading state', async () => {
39
- mockUseSearchUser.mockReturnValue({ isLoading: true, userList: [], setSearchString: jest.fn() });
42
+ mockUseSearchUser.mockReturnValue({
43
+ isLoading: true,
44
+ userList: [],
45
+ setSearchString: jest.fn(),
46
+ setLimit: jest.fn(),
47
+ setRepresentation: jest.fn(),
48
+ });
40
49
  mockUseUser.mockReturnValue({ isLoading: true, data: null, error: null });
41
50
 
42
51
  render(<UsersSelector />);
@@ -46,64 +55,108 @@ describe('UsersSelector', () => {
46
55
 
47
56
  it('renders error state', () => {
48
57
  const errorMessage = 'Error message';
49
- mockUseSearchUser.mockReturnValue({ isLoading: false, userList: [], setSearchString: jest.fn() });
58
+ mockUseSearchUser.mockReturnValue({
59
+ isLoading: false,
60
+ userList: [],
61
+ setSearchString: jest.fn(),
62
+ setLimit: jest.fn(),
63
+ setRepresentation: jest.fn(),
64
+ });
50
65
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: new Error(errorMessage) });
66
+
51
67
  render(<UsersSelector />);
52
- expect(screen.getByText('responsiblePersonError')).toBeInTheDocument();
68
+
69
+ expect(screen.getByText(/error loading responsible person/i)).toBeInTheDocument();
53
70
  expect(screen.getByText(errorMessage)).toBeInTheDocument();
54
71
  });
55
72
 
56
73
  it('renders ComboBox with user list', async () => {
74
+ const user = userEvent.setup();
75
+
57
76
  mockUseSearchUser.mockReturnValue({
58
77
  isLoading: false,
59
78
  userList: [
60
- { uuid: '1', person: { display: 'User 1' } },
61
- { uuid: '2', person: { display: 'User 2' } },
79
+ {
80
+ uuid: '1',
81
+ person: { display: 'User 1', uuid: '1' },
82
+ display: 'User 1',
83
+ givenName: 'User',
84
+ familyName: '1',
85
+ firstName: 'User',
86
+ lastName: '1',
87
+ privileges: [],
88
+ },
89
+ {
90
+ uuid: '2',
91
+ person: { display: 'User 2', uuid: '2' },
92
+ display: 'User 2',
93
+ givenName: 'User',
94
+ familyName: '2',
95
+ firstName: 'User',
96
+ lastName: '2',
97
+ privileges: [],
98
+ },
62
99
  ],
63
100
  setSearchString: jest.fn(),
101
+ setLimit: jest.fn(),
102
+ setRepresentation: jest.fn(),
64
103
  });
65
104
 
66
105
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: null });
106
+
67
107
  render(<UsersSelector />);
68
- expect(screen.getByText('responsiblePerson')).toBeInTheDocument();
108
+
109
+ expect(screen.getByText(/responsible person/i)).toBeInTheDocument();
69
110
  const combobox = screen.getByRole('combobox');
70
- fireEvent.click(combobox);
111
+ await user.click(combobox);
71
112
  expect(screen.getByText('User 1')).toBeInTheDocument();
72
113
  expect(screen.getByText('User 2')).toBeInTheDocument();
73
114
  });
74
115
 
75
116
  it('renders TextInput for other user', async () => {
76
- mockUseSearchUser.mockReturnValue({ isLoading: false, userList: [], setSearchString: jest.fn() });
117
+ mockUseSearchUser.mockReturnValue({
118
+ isLoading: false,
119
+ userList: [],
120
+ setSearchString: jest.fn(),
121
+ setLimit: jest.fn(),
122
+ setRepresentation: jest.fn(),
123
+ });
77
124
  mockUseFormContext.mockReturnValue({
78
- control: {},
125
+ control: {} as Control<FieldValues>,
79
126
  watch: jest.fn().mockImplementation((field) => {
80
127
  if (field === 'responsiblePersonUuid') return otherUser.uuid;
81
128
  if (field === 'responsiblePersonOther') return '';
82
129
  return '';
83
130
  }),
84
131
  resetField: jest.fn(),
85
- });
132
+ } as Partial<UseFormReturn<FieldValues>> as UseFormReturn<FieldValues>);
86
133
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: null });
87
134
 
88
135
  render(<UsersSelector />);
136
+
89
137
  expect(screen.getByRole('textbox')).toBeInTheDocument();
90
- expect(screen.getByPlaceholderText('pleaseSpecify')).toBeInTheDocument();
138
+ expect(screen.getByPlaceholderText(/please specify/i)).toBeInTheDocument();
91
139
  });
92
140
 
93
141
  it('calls setSearchString on input change after delay simulating debounce timout', async () => {
142
+ const user = userEvent.setup();
143
+
94
144
  const setSearchString = jest.fn();
95
145
  mockUseSearchUser.mockReturnValue({
96
146
  isLoading: false,
97
147
  userList: [],
98
148
  setSearchString,
149
+ setLimit: jest.fn(),
150
+ setRepresentation: jest.fn(),
99
151
  });
100
152
 
101
153
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: null });
102
154
 
103
155
  render(<UsersSelector />);
156
+
104
157
  const combobox = screen.getByRole('combobox');
105
- await userEvent.click(combobox);
106
- await userEvent.type(combobox, 'test');
158
+ await user.click(combobox);
159
+ await user.type(combobox, 'test');
107
160
  await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate debounce
108
161
  expect(setSearchString).toHaveBeenCalledWith('test');
109
162
  });