@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,51 +1,42 @@
1
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
1
2
  import React from 'react';
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';
3
+ import { useFormContext } from 'react-hook-form';
6
4
  import { useUser } from '../../../stock-lookups/stock-lookups.resource';
7
5
  import useSearchUser from '../hooks/useSearchUser';
8
6
  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
- __esModule: true,
12
- default: jest.fn(),
13
- }));
14
-
15
- jest.mock('../../../stock-lookups/stock-lookups.resource', () => ({
16
- useUser: jest.fn(),
17
- }));
18
-
10
+ jest.mock('../hooks/useSearchUser');
11
+ jest.mock('../../../stock-lookups/stock-lookups.resource');
19
12
  jest.mock('react-hook-form', () => ({
20
13
  useFormContext: jest.fn(),
21
14
  Controller: ({ render }) => render({ field: {}, fieldState: {} }),
22
15
  }));
16
+ jest.mock('react-i18next', () => ({
17
+ useTranslation: () => ({ t: (key: string) => key }),
18
+ }));
23
19
 
24
- const mockUseSearchUser = jest.mocked(useSearchUser);
25
- const mockUseUser = jest.mocked(useUser);
26
- const mockUseFormContext = jest.mocked(useFormContext);
20
+ const mockUseSearchUser = useSearchUser as jest.Mock;
21
+ const mockUseUser = useUser as jest.Mock;
22
+ const mockUseFormContext = useFormContext as jest.Mock;
27
23
 
28
- describe('User Selector', () => {
24
+ describe('UsersSelector', () => {
29
25
  beforeEach(() => {
26
+ jest.clearAllMocks();
30
27
  mockUseFormContext.mockReturnValue({
31
- control: {} as Control<FieldValues>,
28
+ control: {},
32
29
  watch: jest.fn().mockImplementation((field) => {
33
30
  if (field === 'responsiblePersonUuid') return 'responsibleperson.uuid';
34
31
  if (field === 'responsiblePersonOther') return 'responsiblepersonother.uuid';
35
32
  return '';
36
33
  }),
37
34
  resetField: jest.fn(),
38
- } as Partial<UseFormReturn<FieldValues>> as UseFormReturn<FieldValues>);
35
+ });
39
36
  });
40
37
 
41
38
  it('renders loading state', async () => {
42
- mockUseSearchUser.mockReturnValue({
43
- isLoading: true,
44
- userList: [],
45
- setSearchString: jest.fn(),
46
- setLimit: jest.fn(),
47
- setRepresentation: jest.fn(),
48
- });
39
+ mockUseSearchUser.mockReturnValue({ isLoading: true, userList: [], setSearchString: jest.fn() });
49
40
  mockUseUser.mockReturnValue({ isLoading: true, data: null, error: null });
50
41
 
51
42
  render(<UsersSelector />);
@@ -55,108 +46,64 @@ describe('User Selector', () => {
55
46
 
56
47
  it('renders error state', () => {
57
48
  const errorMessage = 'Error message';
58
- mockUseSearchUser.mockReturnValue({
59
- isLoading: false,
60
- userList: [],
61
- setSearchString: jest.fn(),
62
- setLimit: jest.fn(),
63
- setRepresentation: jest.fn(),
64
- });
49
+ mockUseSearchUser.mockReturnValue({ isLoading: false, userList: [], setSearchString: jest.fn() });
65
50
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: new Error(errorMessage) });
66
-
67
51
  render(<UsersSelector />);
68
-
69
- expect(screen.getByText(/error loading responsible person/i)).toBeInTheDocument();
52
+ expect(screen.getByText('responsiblePersonError')).toBeInTheDocument();
70
53
  expect(screen.getByText(errorMessage)).toBeInTheDocument();
71
54
  });
72
55
 
73
56
  it('renders ComboBox with user list', async () => {
74
- const user = userEvent.setup();
75
-
76
57
  mockUseSearchUser.mockReturnValue({
77
58
  isLoading: false,
78
59
  userList: [
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
- },
60
+ { uuid: '1', person: { display: 'User 1' } },
61
+ { uuid: '2', person: { display: 'User 2' } },
99
62
  ],
100
63
  setSearchString: jest.fn(),
101
- setLimit: jest.fn(),
102
- setRepresentation: jest.fn(),
103
64
  });
104
65
 
105
66
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: null });
106
-
107
67
  render(<UsersSelector />);
108
-
109
- expect(screen.getByText(/responsible person/i)).toBeInTheDocument();
68
+ expect(screen.getByText('responsiblePerson')).toBeInTheDocument();
110
69
  const combobox = screen.getByRole('combobox');
111
- await user.click(combobox);
70
+ fireEvent.click(combobox);
112
71
  expect(screen.getByText('User 1')).toBeInTheDocument();
113
72
  expect(screen.getByText('User 2')).toBeInTheDocument();
114
73
  });
115
74
 
116
75
  it('renders TextInput for other user', async () => {
117
- mockUseSearchUser.mockReturnValue({
118
- isLoading: false,
119
- userList: [],
120
- setSearchString: jest.fn(),
121
- setLimit: jest.fn(),
122
- setRepresentation: jest.fn(),
123
- });
76
+ mockUseSearchUser.mockReturnValue({ isLoading: false, userList: [], setSearchString: jest.fn() });
124
77
  mockUseFormContext.mockReturnValue({
125
- control: {} as Control<FieldValues>,
78
+ control: {},
126
79
  watch: jest.fn().mockImplementation((field) => {
127
80
  if (field === 'responsiblePersonUuid') return otherUser.uuid;
128
81
  if (field === 'responsiblePersonOther') return '';
129
82
  return '';
130
83
  }),
131
84
  resetField: jest.fn(),
132
- } as Partial<UseFormReturn<FieldValues>> as UseFormReturn<FieldValues>);
85
+ });
133
86
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: null });
134
87
 
135
88
  render(<UsersSelector />);
136
-
137
89
  expect(screen.getByRole('textbox')).toBeInTheDocument();
138
- expect(screen.getByPlaceholderText(/please specify/i)).toBeInTheDocument();
90
+ expect(screen.getByPlaceholderText('pleaseSpecify')).toBeInTheDocument();
139
91
  });
140
92
 
141
93
  it('calls setSearchString on input change after delay simulating debounce timout', async () => {
142
- const user = userEvent.setup();
143
-
144
94
  const setSearchString = jest.fn();
145
95
  mockUseSearchUser.mockReturnValue({
146
96
  isLoading: false,
147
97
  userList: [],
148
98
  setSearchString,
149
- setLimit: jest.fn(),
150
- setRepresentation: jest.fn(),
151
99
  });
152
100
 
153
101
  mockUseUser.mockReturnValue({ isLoading: false, data: null, error: null });
154
102
 
155
103
  render(<UsersSelector />);
156
-
157
104
  const combobox = screen.getByRole('combobox');
158
- await user.click(combobox);
159
- await user.type(combobox, 'test');
105
+ await userEvent.click(combobox);
106
+ await userEvent.type(combobox, 'test');
160
107
  await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate debounce
161
108
  expect(setSearchString).toHaveBeenCalledWith('test');
162
109
  });