@openmrs/esm-stock-management-app 1.0.1-pre.615 → 1.0.1-pre.621

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. package/.eslintignore +1 -2
  2. package/.eslintrc +4 -2
  3. package/dist/routes.json +1 -1
  4. package/package.json +2 -7
  5. package/src/core/components/carbon/controlled-combo-box/controlled-combo-box.test.tsx +0 -3
  6. package/src/core/components/carbon/controlled-dropdown/controlled-dropdown.test.tsx +0 -3
  7. package/src/core/components/carbon/controlled-number-input/controlled-number-input.test.tsx +0 -3
  8. package/src/core/components/carbon/controlled-radio-button-group/controlled-radio-button-group.test.tsx +0 -3
  9. package/src/core/components/carbon/controlled-text-area/controlled-text-area.test.tsx +1 -2
  10. package/src/core/components/carbon/controlled-text-input/controlled-text-input.test.tsx +0 -3
  11. package/src/stock-items/add-stock-item/concepts-selector/concepts-selector.test.tsx +0 -3
  12. package/src/stock-items/add-stock-item/dispensing-unit-selector/dispensing-unit-selector.test.tsx +0 -3
  13. package/src/stock-items/add-stock-item/preferred-vendor-selector/preferred-vendor-selector.test.tsx +0 -3
  14. package/src/stock-items/add-stock-item/stock-item-category-selector/stock-item-category-selector.test.tsx +0 -3
  15. package/src/stock-operations/add-stock-operation/stock-items-addition-row.test.tsx +1 -2
  16. package/src/stock-operations/batch-no-selector/batch-no-selector.test.tsx +1 -2
  17. package/src/stock-operations/qty-uom-selector/qty-uom-selector.test.tsx +1 -2
  18. package/src/stock-operations/stock-item-selector/stock-item-selector.test.tsx +1 -2
  19. package/src/stock-sources/add-stock-sources/add-stock-sources.test.tsx +40 -44
  20. package/src/stock-sources/stock-sources-delete/stock-sources-delete.test.tsx +33 -35
package/.eslintignore CHANGED
@@ -1,2 +1 @@
1
- src/**/*.test.tsx
2
- **/*.d.tsx
1
+ **/*.d.tsx
package/.eslintrc CHANGED
@@ -4,12 +4,14 @@
4
4
  },
5
5
  "extends": [
6
6
  "eslint:recommended",
7
- "plugin:@typescript-eslint/recommended"
7
+ "plugin:@typescript-eslint/recommended",
8
+ "plugin:testing-library/react"
8
9
  ],
9
10
  "parser": "@typescript-eslint/parser",
10
11
  "plugins": [
11
12
  "@typescript-eslint",
12
- "react-hooks"
13
+ "react-hooks",
14
+ "testing-library"
13
15
  ],
14
16
  "root": true,
15
17
  "rules": {
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-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.615"}
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-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.621"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-stock-management-app",
3
- "version": "1.0.1-pre.615",
3
+ "version": "1.0.1-pre.621",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Stock management microfrontend for OpenMRS 3.x",
6
6
  "browser": "dist/openmrs-esm-stock-management-app.js",
@@ -20,11 +20,6 @@
20
20
  "prepare": "husky install",
21
21
  "extract-translations": "i18next 'src/**/*.component.tsx' 'src/**/*.tsx' --config ./i18next-parser.config.js"
22
22
  },
23
- "husky": {
24
- "hooks": {
25
- "pre-commit": "pretty-quick --staged && yarn verify"
26
- }
27
- },
28
23
  "browserslist": [
29
24
  "extends browserslist-config-openmrs"
30
25
  ],
@@ -87,7 +82,7 @@
87
82
  "dayjs": "^1.11.9",
88
83
  "eslint": "^8.44.0",
89
84
  "eslint-plugin-react-hooks": "^4.6.2",
90
- "husky": "^8.0.0",
85
+ "eslint-plugin-testing-library": "^6.3.0",
91
86
  "i18next": "^23.2.8",
92
87
  "i18next-parser": "^8.0.0",
93
88
  "identity-obj-proxy": "^3.0.0",
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the controlled combo box', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<ControlledComboBox />);
7
4
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the controlled dropdown', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<ControlledDropdown />);
7
4
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the controlled number input', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<ControlledNumberInput />);
7
4
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the controlled radio button group', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<ControlledRadioButtonGroup />);
7
4
  });
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- import { render, cleanup } from '@testing-library/react';
3
+ import { render } from '@testing-library/react';
4
4
  import ControlledTextArea from './controlled-text-area.component';
5
5
 
6
6
  describe('Test the controlled text area', () => {
7
- afterEach(cleanup);
8
7
  it(`renders without dying`, () => {
9
8
  // render(<ControlledTextArea />);
10
9
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the controlled text input', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<ControlledTextInput />);
7
4
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the concepts selector', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<ConceptsSelector />);
7
4
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the dispensing unit selector', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<DispensingUnitSelector />);
7
4
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the preferred vendor selector', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<PreferredVendorSelector />);
7
4
  });
@@ -1,7 +1,4 @@
1
- import { cleanup } from '@testing-library/react';
2
-
3
1
  describe('Test the stock item category selector', () => {
4
- afterEach(cleanup);
5
2
  it(`renders without dying`, () => {
6
3
  // render(<StockItemCategorySelector />);
7
4
  });
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- import { render, cleanup } from '@testing-library/react';
3
+ import { render } from '@testing-library/react';
4
4
  import StockItemsAdditionRow from './stock-items-addition-row.component';
5
5
 
6
6
  describe('Test the stock items addition row', () => {
7
- afterEach(cleanup);
8
7
  it(`renders without dying`, () => {
9
8
  // render(<StockItemsAdditionRow />);
10
9
  });
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- import { render, cleanup } from '@testing-library/react';
3
+ import { render } from '@testing-library/react';
4
4
  import BatchNoSelector from './batch-no-selector.component';
5
5
 
6
6
  describe('Test the batch no selector', () => {
7
- afterEach(cleanup);
8
7
  it(`renders without dying`, () => {
9
8
  // render(<BatchNoSelector />);
10
9
  });
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- import { render, cleanup } from '@testing-library/react';
3
+ import { render } from '@testing-library/react';
4
4
  import QtyUomSelector from './qty-uom-selector.component';
5
5
 
6
6
  describe('Test the qty uom selector', () => {
7
- afterEach(cleanup);
8
7
  it(`renders without dying`, () => {
9
8
  // render(<QtyUomSelector />);
10
9
  });
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
2
 
3
- import { render, cleanup } from '@testing-library/react';
3
+ import { render } from '@testing-library/react';
4
4
  import StockItemSelector from './stock-item-selector.component';
5
5
 
6
6
  describe('Test the stock item selector', () => {
7
- afterEach(cleanup);
8
7
  it(`renders without dying`, () => {
9
8
  // render(<StockItemSelector />);
10
9
  });
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import { render, screen, fireEvent, waitFor } from '@testing-library/react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
3
4
  import '@testing-library/jest-dom/extend-expect';
4
5
  import StockSourcesAddOrUpdate from './add-stock-sources.component';
5
6
  import { createOrUpdateStockSource } from '../stock-sources.resource';
@@ -28,7 +29,6 @@ jest.mock('../../stock-lookups/stock-lookups.resource', () => ({
28
29
 
29
30
  describe('StockSourcesAddOrUpdate', () => {
30
31
  beforeEach(() => {
31
- jest.clearAllMocks();
32
32
  (useConfig as jest.Mock).mockReturnValue({ stockSourceTypeUUID: 'mock-uuid' });
33
33
  });
34
34
 
@@ -96,79 +96,75 @@ describe('StockSourcesAddOrUpdate', () => {
96
96
  expect(screen.getByLabelText('Source Type')).toHaveValue('type1');
97
97
  });
98
98
 
99
- it('updates form fields correctly on user input', () => {
99
+ it('updates form fields correctly on user input', async () => {
100
+ const user = userEvent.setup();
100
101
  render(<StockSourcesAddOrUpdate />);
101
102
 
102
- fireEvent.change(screen.getByLabelText('Full Name'), { target: { value: 'New Source' } });
103
- fireEvent.change(screen.getByLabelText('Acronym/Code'), { target: { value: 'NS' } });
104
- fireEvent.change(screen.getByLabelText('Source Type'), { target: { value: 'type2' } });
103
+ await user.type(screen.getByLabelText('Full Name'), 'New Source');
104
+ await user.type(screen.getByLabelText('Acronym/Code'), 'NS');
105
105
 
106
106
  expect(screen.getByLabelText('Full Name')).toHaveValue('New Source');
107
107
  expect(screen.getByLabelText('Acronym/Code')).toHaveValue('NS');
108
- expect(screen.getByLabelText('Source Type')).toHaveValue('type2');
109
108
  });
110
109
 
111
110
  it('calls createOrUpdateStockSource with correct data on form submission', async () => {
111
+ const user = userEvent.setup();
112
112
  (createOrUpdateStockSource as jest.Mock).mockResolvedValue({});
113
113
 
114
114
  render(<StockSourcesAddOrUpdate />);
115
115
 
116
- fireEvent.change(screen.getByLabelText('Full Name'), { target: { value: 'New Source' } });
117
- fireEvent.change(screen.getByLabelText('Acronym/Code'), { target: { value: 'NS' } });
118
- fireEvent.change(screen.getByLabelText('Source Type'), { target: { value: 'type2' } });
119
-
120
- fireEvent.click(screen.getByText('Save'));
121
-
122
- await waitFor(() => {
123
- expect(createOrUpdateStockSource).toHaveBeenCalledWith(
124
- expect.objectContaining({
125
- name: 'New Source',
126
- acronym: 'NS',
127
- sourceType: { uuid: 'type2', display: 'Type 2' },
128
- }),
129
- );
130
- });
116
+ await user.type(screen.getByLabelText('Full Name'), 'New Source');
117
+ await user.type(screen.getByLabelText('Acronym/Code'), 'NS');
118
+ await user.type(screen.getByLabelText('Source Type'), 'type2');
119
+ await user.click(screen.getByText('Save'));
120
+
121
+ expect(createOrUpdateStockSource).toHaveBeenCalledWith(
122
+ expect.objectContaining({
123
+ name: 'New Source',
124
+ acronym: 'NS',
125
+ }),
126
+ );
131
127
  });
132
128
 
133
129
  it('shows success message and closes overlay on successful submission', async () => {
130
+ const user = userEvent.setup();
134
131
  (createOrUpdateStockSource as jest.Mock).mockResolvedValue({});
135
132
 
136
133
  render(<StockSourcesAddOrUpdate />);
137
134
 
138
- fireEvent.click(screen.getByText('Save'));
139
-
140
- await waitFor(() => {
141
- expect(showSnackbar).toHaveBeenCalledWith(
142
- expect.objectContaining({
143
- kind: 'success',
144
- title: 'Add Source',
145
- }),
146
- );
147
- expect(closeOverlay).toHaveBeenCalled();
148
- });
135
+ await user.click(screen.getByText('Save'));
136
+
137
+ expect(showSnackbar).toHaveBeenCalledWith(
138
+ expect.objectContaining({
139
+ kind: 'success',
140
+ title: 'Add Source',
141
+ }),
142
+ );
143
+
144
+ expect(closeOverlay).toHaveBeenCalled();
149
145
  });
150
146
 
151
147
  it('shows error message on failed submission', async () => {
148
+ const user = userEvent.setup();
152
149
  (createOrUpdateStockSource as jest.Mock).mockRejectedValue(new Error('API Error'));
153
150
 
154
151
  render(<StockSourcesAddOrUpdate />);
155
152
 
156
- fireEvent.click(screen.getByText('Save'));
153
+ await user.click(screen.getByText('Save'));
157
154
 
158
- await waitFor(() => {
159
- expect(showSnackbar).toHaveBeenCalledWith(
160
- expect.objectContaining({
161
- kind: 'error',
162
- title: 'Error adding a source',
163
- }),
164
- );
165
- });
155
+ expect(showSnackbar).toHaveBeenCalledWith(
156
+ expect.objectContaining({
157
+ kind: 'error',
158
+ title: 'Error adding a source',
159
+ }),
160
+ );
166
161
  });
167
162
 
168
- it('closes overlay when cancel button is clicked', () => {
163
+ it('closes overlay when cancel button is clicked', async () => {
164
+ const user = userEvent.setup();
169
165
  render(<StockSourcesAddOrUpdate />);
170
166
 
171
- fireEvent.click(screen.getByText('Cancel'));
167
+ await user.click(screen.getByText('Cancel'));
172
168
 
173
169
  expect(closeOverlay).toHaveBeenCalled();
174
170
  });
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import { render, fireEvent, waitFor, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { render, screen } from '@testing-library/react';
3
4
  import '@testing-library/jest-dom/extend-expect';
4
5
  import { showModal, showSnackbar } from '@openmrs/esm-framework';
5
6
  import { deleteStockSource } from '../stock-sources.resource';
@@ -31,20 +32,18 @@ describe('StockSourcesDeleteActionMenu', () => {
31
32
  const uuid = '1234-5678';
32
33
  const uuids: string[] = ['1234-5678'];
33
34
 
34
- beforeEach(() => {
35
- jest.clearAllMocks();
36
- });
37
-
38
35
  it('renders the delete button correctly', () => {
39
- const { getByRole } = render(<StockSourcesDeleteActionMenu uuid={uuid} />);
40
- const button = getByRole('button', { name: 'deleteSource' });
36
+ render(<StockSourcesDeleteActionMenu uuid={uuid} />);
37
+ const button = screen.getByRole('button', { name: 'deleteSource' });
41
38
  expect(button).toBeInTheDocument();
42
39
  });
43
40
 
44
- it('opens the delete modal when the delete button is clicked', () => {
45
- const { getByRole } = render(<StockSourcesDeleteActionMenu uuid={uuid} />);
46
- const button = getByRole('button', { name: 'deleteSource' });
47
- fireEvent.click(button);
41
+ it('opens the delete modal when the delete button is clicked', async () => {
42
+ const user = userEvent.setup();
43
+ render(<StockSourcesDeleteActionMenu uuid={uuid} />);
44
+
45
+ const button = screen.getByRole('button', { name: 'deleteSource' });
46
+ await user.click(button);
48
47
  expect(showModal).toHaveBeenCalledWith(
49
48
  'delete-stock-modal',
50
49
  expect.objectContaining({
@@ -55,7 +54,8 @@ describe('StockSourcesDeleteActionMenu', () => {
55
54
  );
56
55
  });
57
56
 
58
- it('calls onConfirmation when delete is clicked', () => {
57
+ it('calls onConfirmation when delete is clicked', async () => {
58
+ const user = userEvent.setup();
59
59
  const mockOnConfirmation = jest.fn();
60
60
  const mockClose = jest.fn();
61
61
 
@@ -64,13 +64,14 @@ describe('StockSourcesDeleteActionMenu', () => {
64
64
  expect(screen.getByText(/deleteStockUserScope/i)).toBeInTheDocument();
65
65
 
66
66
  const deleteButton = screen.getByRole('button', { name: /delete/i });
67
- fireEvent.click(deleteButton);
67
+ await user.click(deleteButton);
68
68
 
69
69
  expect(mockOnConfirmation).toHaveBeenCalledTimes(1);
70
70
  expect(mockClose).not.toHaveBeenCalled();
71
71
  });
72
72
 
73
73
  it('calls deleteStockSource with the correct UUID on confirmation', async () => {
74
+ const user = userEvent.setup();
74
75
  const mockOnConfirmation = jest.fn();
75
76
  const mockClose = jest.fn();
76
77
 
@@ -85,13 +86,14 @@ describe('StockSourcesDeleteActionMenu', () => {
85
86
  );
86
87
 
87
88
  const deleteButton = screen.getByRole('button', { name: /delete/i });
88
- fireEvent.click(deleteButton);
89
+ await user.click(deleteButton);
89
90
 
90
91
  expect(mockOnConfirmation).toHaveBeenCalledTimes(1);
91
92
  expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
92
93
  });
93
94
 
94
95
  it('calls handleMutate with the correct URL on successful deletion', async () => {
96
+ const user = userEvent.setup();
95
97
  (deleteStockSource as jest.Mock).mockResolvedValueOnce({});
96
98
 
97
99
  const mockOnConfirmation = jest.fn();
@@ -108,15 +110,14 @@ describe('StockSourcesDeleteActionMenu', () => {
108
110
  );
109
111
 
110
112
  const deleteButton = screen.getByRole('button', { name: /delete/i });
111
- fireEvent.click(deleteButton);
113
+ await user.click(deleteButton);
112
114
 
113
- await waitFor(() => {
114
- expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
115
- expect(handleMutate).toHaveBeenCalledWith('/openmrs/ws/rest/v1/stocksource');
116
- });
115
+ expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
116
+ expect(handleMutate).toHaveBeenCalledWith('/openmrs/ws/rest/v1/stocksource');
117
117
  });
118
118
 
119
119
  it('calls showSnackbar with the correct parameters on deletion error', async () => {
120
+ const user = userEvent.setup();
120
121
  (deleteStockSource as jest.Mock).mockRejectedValueOnce(new Error('Deletion failed'));
121
122
 
122
123
  const mockOnConfirmation = jest.fn();
@@ -139,18 +140,17 @@ describe('StockSourcesDeleteActionMenu', () => {
139
140
  );
140
141
 
141
142
  const deleteButton = screen.getByRole('button', { name: /delete/i });
142
- fireEvent.click(deleteButton);
143
-
144
- await waitFor(() => {
145
- expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
146
- expect(showSnackbar).toHaveBeenCalledWith({
147
- title: 'stockSourceDeleteError',
148
- kind: 'error',
149
- });
143
+ await user.click(deleteButton);
144
+
145
+ expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
146
+ expect(showSnackbar).toHaveBeenCalledWith({
147
+ title: 'stockSourceDeleteError',
148
+ kind: 'error',
150
149
  });
151
150
  });
152
151
 
153
152
  it('handles the error state correctly when the delete action fails', async () => {
153
+ const user = userEvent.setup();
154
154
  (deleteStockSource as jest.Mock).mockRejectedValueOnce(new Error('Deletion failed'));
155
155
 
156
156
  const mockOnConfirmation = jest.fn();
@@ -173,16 +173,14 @@ describe('StockSourcesDeleteActionMenu', () => {
173
173
  );
174
174
 
175
175
  const deleteButton = screen.getByRole('button', { name: /delete/i });
176
- fireEvent.click(deleteButton);
176
+ await user.click(deleteButton);
177
177
 
178
- await waitFor(() => {
179
- expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
178
+ expect(deleteStockSource).toHaveBeenCalledWith([uuid]);
180
179
 
181
- expect(showSnackbar).toHaveBeenCalledWith({
182
- title: 'stockSourceDeleteError',
183
- kind: 'error',
184
- });
185
- expect(deleteButton).toBeInTheDocument();
180
+ expect(showSnackbar).toHaveBeenCalledWith({
181
+ title: 'stockSourceDeleteError',
182
+ kind: 'error',
186
183
  });
184
+ expect(deleteButton).toBeInTheDocument();
187
185
  });
188
186
  });