@openmrs/esm-billing-app 1.0.2-pre.92 → 1.0.2-pre.933
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/.eslintrc +16 -2
- package/README.md +54 -9
- package/__mocks__/bills.mock.ts +12 -0
- package/__mocks__/react-i18next.js +6 -5
- package/dist/1119.js +1 -1
- package/dist/1146.js +1 -2
- package/dist/1146.js.map +1 -1
- package/dist/1197.js +1 -1
- package/dist/1537.js +1 -0
- package/dist/1537.js.map +1 -0
- package/dist/1856.js +1 -0
- package/dist/1856.js.map +1 -0
- package/dist/2146.js +1 -1
- package/dist/2524.js +1 -0
- package/dist/2524.js.map +1 -0
- package/dist/2690.js +1 -1
- package/dist/3099.js +1 -1
- package/dist/3584.js +1 -1
- package/dist/3717.js +2 -0
- package/dist/3717.js.map +1 -0
- package/dist/4055.js +1 -1
- package/dist/4132.js +1 -1
- package/dist/4300.js +1 -1
- package/dist/4335.js +1 -1
- package/dist/4618.js +1 -1
- package/dist/4652.js +1 -1
- package/dist/4724.js +1 -0
- package/dist/4724.js.map +1 -0
- package/dist/4739.js +1 -1
- package/dist/4739.js.map +1 -1
- package/dist/4944.js +1 -1
- package/dist/5173.js +1 -1
- package/dist/5241.js +1 -1
- package/dist/5442.js +1 -1
- package/dist/5661.js +1 -1
- package/dist/6022.js +1 -1
- package/dist/6468.js +1 -1
- package/dist/6540.js +1 -1
- package/dist/6540.js.map +1 -1
- package/dist/6679.js +1 -1
- package/dist/6840.js +1 -1
- package/dist/6859.js +1 -1
- package/dist/7097.js +1 -1
- package/dist/7159.js +1 -1
- package/dist/723.js +1 -1
- package/dist/7255.js +1 -1
- package/dist/7255.js.map +1 -1
- package/dist/7617.js +1 -1
- package/dist/795.js +1 -1
- package/dist/8163.js +1 -1
- package/dist/8349.js +1 -1
- package/dist/8572.js +1 -0
- package/dist/8572.js.map +1 -0
- package/dist/8618.js +1 -1
- package/dist/8708.js +2 -0
- package/dist/{6557.js.LICENSE.txt → 8708.js.LICENSE.txt} +22 -0
- package/dist/8708.js.map +1 -0
- package/dist/890.js +1 -1
- package/dist/9214.js +1 -1
- package/dist/9538.js +1 -1
- package/dist/9569.js +1 -1
- package/dist/961.js +1 -1
- package/dist/961.js.map +1 -1
- package/dist/986.js +1 -1
- package/dist/9879.js +1 -1
- package/dist/9895.js +1 -1
- package/dist/9900.js +1 -1
- package/dist/9913.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-billing-app.js +1 -1
- package/dist/openmrs-esm-billing-app.js.buildmanifest.json +271 -285
- package/dist/openmrs-esm-billing-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/e2e/README.md +19 -18
- package/e2e/core/test.ts +1 -1
- package/e2e/fixtures/api.ts +1 -1
- package/e2e/specs/sample-test.spec.ts +0 -1
- package/e2e/support/github/Dockerfile +1 -1
- package/package.json +18 -15
- package/src/bill-history/bill-history.component.tsx +20 -28
- package/src/bill-history/bill-history.scss +4 -94
- package/src/bill-history/bill-history.test.tsx +37 -78
- package/src/bill-item-actions/bill-item-actions.scss +21 -5
- package/src/bill-item-actions/edit-bill-item.modal.tsx +225 -0
- package/src/bill-item-actions/edit-bill-item.test.tsx +214 -40
- package/src/billable-services/bill-waiver/bill-selection.component.tsx +5 -5
- package/src/billable-services/bill-waiver/bill-waiver-form.component.tsx +28 -32
- package/src/billable-services/bill-waiver/patient-bills.component.tsx +7 -7
- package/src/billable-services/bill-waiver/utils.ts +13 -3
- package/src/billable-services/{create-edit/add-billable-service.scss → billable-service-form/billable-service-form.scss} +32 -64
- package/src/billable-services/billable-service-form/billable-service-form.test.tsx +898 -0
- package/src/billable-services/billable-service-form/billable-service-form.workspace.tsx +504 -0
- package/src/billable-services/billable-service.resource.ts +71 -27
- package/src/billable-services/billable-services-home.component.tsx +13 -42
- package/src/billable-services/billable-services-left-panel-link.component.tsx +48 -0
- package/src/billable-services/billable-services-left-panel-menu.component.tsx +46 -0
- package/src/billable-services/billable-services-menu-item/item.component.tsx +5 -4
- package/src/billable-services/billable-services.component.tsx +156 -152
- package/src/billable-services/billable-services.scss +29 -0
- package/src/billable-services/billable-services.test.tsx +6 -49
- package/src/billable-services/cash-point/add-cash-point.modal.tsx +170 -0
- package/src/billable-services/cash-point/cash-point-configuration.component.tsx +19 -193
- package/src/billable-services/cash-point/cash-point-configuration.scss +1 -5
- package/src/billable-services/dashboard/dashboard.component.tsx +0 -2
- package/src/billable-services/payment-modes/delete-payment-mode.modal.tsx +77 -0
- package/src/billable-services/payment-modes/payment-mode-form.modal.tsx +131 -0
- package/src/billable-services/payment-modes/payment-modes-config.component.tsx +139 -0
- package/src/billable-services/{payyment-modes → payment-modes}/payment-modes-config.scss +5 -4
- package/src/billable-services-admin-card-link.component.test.tsx +2 -2
- package/src/billable-services-admin-card-link.component.tsx +1 -1
- package/src/billing-dashboard/billing-dashboard.scss +1 -1
- package/src/billing-form/billing-checkin-form.component.tsx +21 -17
- package/src/billing-form/billing-checkin-form.test.tsx +99 -26
- package/src/billing-form/billing-form.component.tsx +222 -292
- package/src/billing-form/billing-form.scss +143 -0
- package/src/billing-form/visit-attributes/visit-attributes-form.component.tsx +1 -1
- package/src/billing.resource.ts +69 -74
- package/src/bills-table/bills-table.component.tsx +3 -3
- package/src/bills-table/bills-table.test.tsx +98 -54
- package/src/config-schema.ts +52 -24
- package/src/dashboard.meta.ts +4 -2
- package/src/helpers/functions.ts +5 -4
- package/src/index.ts +71 -9
- package/src/invoice/invoice-table.component.tsx +36 -70
- package/src/invoice/invoice-table.scss +8 -5
- package/src/invoice/invoice-table.test.tsx +273 -62
- package/src/invoice/invoice.component.tsx +39 -32
- package/src/invoice/invoice.scss +11 -4
- package/src/invoice/invoice.test.tsx +324 -120
- package/src/invoice/payments/invoice-breakdown/invoice-breakdown.scss +9 -9
- package/src/invoice/payments/payment-form/payment-form.component.tsx +43 -34
- package/src/invoice/payments/payment-form/payment-form.scss +5 -6
- package/src/invoice/payments/payment-form/payment-form.test.tsx +216 -66
- package/src/invoice/payments/payment-history/payment-history.component.tsx +6 -4
- package/src/invoice/payments/payment-history/payment-history.test.tsx +9 -14
- package/src/invoice/payments/payments.component.tsx +55 -67
- package/src/invoice/payments/payments.scss +4 -3
- package/src/invoice/payments/payments.test.tsx +282 -0
- package/src/invoice/payments/utils.ts +15 -27
- package/src/invoice/printable-invoice/print-receipt.component.tsx +3 -2
- package/src/invoice/printable-invoice/print-receipt.test.tsx +14 -25
- package/src/invoice/printable-invoice/printable-footer.component.tsx +2 -2
- package/src/invoice/printable-invoice/printable-footer.test.tsx +4 -13
- package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +12 -11
- package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +16 -14
- package/src/invoice/printable-invoice/printable-invoice.component.tsx +20 -34
- package/src/left-panel-link.test.tsx +1 -4
- package/src/metrics-cards/metrics-cards.component.tsx +16 -6
- package/src/metrics-cards/metrics-cards.scss +4 -0
- package/src/metrics-cards/metrics-cards.test.tsx +18 -5
- package/src/modal/require-payment-modal.test.tsx +27 -22
- package/src/modal/{require-payment-modal.component.tsx → require-payment.modal.tsx} +18 -19
- package/src/routes.json +44 -20
- package/src/types/index.ts +86 -23
- package/translations/am.json +132 -77
- package/translations/ar.json +133 -78
- package/translations/ar_SY.json +133 -78
- package/translations/bn.json +135 -80
- package/translations/de.json +133 -78
- package/translations/en.json +134 -79
- package/translations/en_US.json +133 -78
- package/translations/es.json +132 -77
- package/translations/es_MX.json +133 -78
- package/translations/fr.json +138 -83
- package/translations/he.json +132 -77
- package/translations/hi.json +133 -78
- package/translations/hi_IN.json +133 -78
- package/translations/id.json +133 -78
- package/translations/it.json +159 -104
- package/translations/ka.json +133 -78
- package/translations/km.json +132 -77
- package/translations/ku.json +133 -78
- package/translations/ky.json +133 -78
- package/translations/lg.json +133 -78
- package/translations/ne.json +133 -78
- package/translations/pl.json +133 -78
- package/translations/pt.json +133 -78
- package/translations/pt_BR.json +133 -78
- package/translations/qu.json +133 -78
- package/translations/ro_RO.json +220 -165
- package/translations/ru_RU.json +133 -78
- package/translations/si.json +133 -78
- package/translations/sw.json +133 -78
- package/translations/sw_KE.json +133 -78
- package/translations/tr.json +133 -78
- package/translations/tr_TR.json +133 -78
- package/translations/uk.json +133 -78
- package/translations/uz.json +133 -78
- package/translations/uz@Latn.json +133 -78
- package/translations/uz_UZ.json +133 -78
- package/translations/vi.json +133 -78
- package/translations/zh.json +133 -78
- package/translations/zh_CN.json +163 -108
- package/dist/1146.js.LICENSE.txt +0 -21
- package/dist/2352.js +0 -1
- package/dist/2352.js.map +0 -1
- package/dist/246.js +0 -1
- package/dist/246.js.map +0 -1
- package/dist/4689.js +0 -2
- package/dist/4689.js.map +0 -1
- package/dist/6557.js +0 -2
- package/dist/6557.js.map +0 -1
- package/dist/8638.js +0 -1
- package/dist/8638.js.map +0 -1
- package/dist/9968.js +0 -1
- package/dist/9968.js.map +0 -1
- package/src/bill-item-actions/edit-bill-item.component.tsx +0 -221
- package/src/billable-services/create-edit/add-billable-service.component.tsx +0 -401
- package/src/billable-services/create-edit/add-billable-service.test.tsx +0 -154
- package/src/billable-services/dashboard/service-metrics.component.tsx +0 -41
- package/src/billable-services/payyment-modes/payment-modes-config.component.tsx +0 -280
- package/src/invoice/payments/payments.component.test.tsx +0 -121
- /package/dist/{4689.js.LICENSE.txt → 3717.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,898 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
4
|
+
import { type FetchResponse } from '@openmrs/esm-framework';
|
|
5
|
+
import {
|
|
6
|
+
createBillableService,
|
|
7
|
+
updateBillableService,
|
|
8
|
+
useBillableServices,
|
|
9
|
+
useConceptsSearch,
|
|
10
|
+
usePaymentModes,
|
|
11
|
+
useServiceTypes,
|
|
12
|
+
} from '../billable-service.resource';
|
|
13
|
+
import BillableServiceFormWorkspace, {
|
|
14
|
+
transformServiceToFormData,
|
|
15
|
+
normalizePrice,
|
|
16
|
+
} from './billable-service-form.workspace';
|
|
17
|
+
import type { BillableService } from '../../types';
|
|
18
|
+
|
|
19
|
+
const mockUseBillableServices = jest.mocked(useBillableServices);
|
|
20
|
+
const mockUsePaymentModes = jest.mocked(usePaymentModes);
|
|
21
|
+
const mockUseServiceTypes = jest.mocked(useServiceTypes);
|
|
22
|
+
const mockCreateBillableService = jest.mocked(createBillableService);
|
|
23
|
+
const mockUpdateBillableService = jest.mocked(updateBillableService);
|
|
24
|
+
const mockUseConceptsSearch = jest.mocked(useConceptsSearch);
|
|
25
|
+
|
|
26
|
+
jest.mock('../billable-service.resource', () => ({
|
|
27
|
+
useBillableServices: jest.fn(),
|
|
28
|
+
usePaymentModes: jest.fn(),
|
|
29
|
+
useServiceTypes: jest.fn(),
|
|
30
|
+
createBillableService: jest.fn(),
|
|
31
|
+
updateBillableService: jest.fn(),
|
|
32
|
+
useConceptsSearch: jest.fn(),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
const mockPaymentModes = [
|
|
36
|
+
{ uuid: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74', name: 'Cash', description: 'Cash Payment', retired: false },
|
|
37
|
+
{
|
|
38
|
+
uuid: 'beac329b-f1dc-4a33-9e7c-d95821a137a6',
|
|
39
|
+
name: 'Insurance',
|
|
40
|
+
description: 'Insurance method of payment',
|
|
41
|
+
retired: false,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
uuid: '28989582-e8c3-46b0-96d0-c249cb06d5c6',
|
|
45
|
+
name: 'MPESA',
|
|
46
|
+
description: 'Mobile money method of payment',
|
|
47
|
+
retired: false,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const mockServiceTypes = [
|
|
52
|
+
{ uuid: 'c9604249-db0a-4d03-b074-fc6bc2fa13e6', display: 'Lab service' },
|
|
53
|
+
{ uuid: 'b75e466f-a6f5-4d5e-849a-84424d3c85cd', display: 'Pharmacy service' },
|
|
54
|
+
{ uuid: 'ce914b2d-44f6-4b6c-933f-c57a3938e35b', display: 'Peer educator service' },
|
|
55
|
+
{ uuid: 'c23d3224-2218-4007-8f22-e1f3d5a8e58a', display: 'Nutrition service' },
|
|
56
|
+
{ uuid: '65487ff4-63b3-452a-8985-6a1f4a0cc08d', display: 'TB service' },
|
|
57
|
+
{ uuid: '9db142d5-5cc4-4c05-9f83-06ed294caa67', display: 'Family planning service' },
|
|
58
|
+
{ uuid: 'a487a743-62ce-4f93-a66b-c5154ee8987d', display: 'Adherence counselling service' },
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
// Test helpers
|
|
62
|
+
const setupMocks = () => {
|
|
63
|
+
mockUseBillableServices.mockReturnValue({
|
|
64
|
+
billableServices: [],
|
|
65
|
+
isLoading: false,
|
|
66
|
+
error: null,
|
|
67
|
+
mutate: jest.fn(),
|
|
68
|
+
isValidating: false,
|
|
69
|
+
});
|
|
70
|
+
mockUsePaymentModes.mockReturnValue({
|
|
71
|
+
paymentModes: mockPaymentModes,
|
|
72
|
+
error: null,
|
|
73
|
+
isLoadingPaymentModes: false,
|
|
74
|
+
mutate: jest.fn(),
|
|
75
|
+
});
|
|
76
|
+
mockUseServiceTypes.mockReturnValue({ serviceTypes: mockServiceTypes, error: false, isLoadingServiceTypes: false });
|
|
77
|
+
mockUseConceptsSearch.mockReturnValue({ searchResults: [], isSearching: false, error: null });
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const renderBillableServicesForm = (props = {}) => {
|
|
81
|
+
const defaultProps = {
|
|
82
|
+
closeWorkspace: jest.fn(),
|
|
83
|
+
closeWorkspaceWithSavedChanges: jest.fn(),
|
|
84
|
+
...props,
|
|
85
|
+
};
|
|
86
|
+
setupMocks();
|
|
87
|
+
return render(<BillableServiceFormWorkspace {...defaultProps} />);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
interface FillOptions {
|
|
91
|
+
serviceName?: string;
|
|
92
|
+
shortName?: string;
|
|
93
|
+
skipPrice?: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const fillRequiredFields = async (user, options: FillOptions = {}) => {
|
|
97
|
+
const { serviceName = 'Test Service Name', shortName = 'Test Short Name', skipPrice = false } = options;
|
|
98
|
+
|
|
99
|
+
if (serviceName) {
|
|
100
|
+
await user.type(screen.getByRole('textbox', { name: /Service name/i }), serviceName);
|
|
101
|
+
}
|
|
102
|
+
if (shortName) {
|
|
103
|
+
await user.type(screen.getByRole('textbox', { name: /Short name/i }), shortName);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await user.click(screen.getByRole('combobox', { name: /Service type/i }));
|
|
107
|
+
await user.click(screen.getByRole('option', { name: /Lab service/i }));
|
|
108
|
+
|
|
109
|
+
await user.click(screen.getByRole('combobox', { name: /Payment mode/i }));
|
|
110
|
+
await user.click(screen.getByRole('option', { name: /Cash/i }));
|
|
111
|
+
|
|
112
|
+
if (!skipPrice) {
|
|
113
|
+
const priceInput = screen.getByRole('spinbutton', { name: /Selling Price/i });
|
|
114
|
+
await user.type(priceInput, '100');
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const submitForm = async () => {
|
|
119
|
+
const user = userEvent.setup();
|
|
120
|
+
const saveButton = screen.getByRole('button', { name: /save/i });
|
|
121
|
+
await user.click(saveButton);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
describe('BillableServiceFormWorkspace', () => {
|
|
125
|
+
test('should render billable services form and generate correct payload', async () => {
|
|
126
|
+
const user = userEvent.setup();
|
|
127
|
+
const mockCloseWorkspace = jest.fn();
|
|
128
|
+
renderBillableServicesForm({ closeWorkspace: mockCloseWorkspace });
|
|
129
|
+
|
|
130
|
+
await fillRequiredFields(user);
|
|
131
|
+
mockCreateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
132
|
+
|
|
133
|
+
await submitForm();
|
|
134
|
+
|
|
135
|
+
expect(mockCreateBillableService).toHaveBeenCalledTimes(1);
|
|
136
|
+
expect(mockCreateBillableService).toHaveBeenCalledWith({
|
|
137
|
+
name: 'Test Service Name',
|
|
138
|
+
shortName: 'Test Short Name',
|
|
139
|
+
serviceType: 'c9604249-db0a-4d03-b074-fc6bc2fa13e6',
|
|
140
|
+
servicePrices: [
|
|
141
|
+
{
|
|
142
|
+
paymentMode: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74',
|
|
143
|
+
price: 100,
|
|
144
|
+
name: 'Cash',
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
serviceStatus: 'ENABLED',
|
|
148
|
+
concept: undefined,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('Workspace Interactions', () => {
|
|
153
|
+
test('should call closeWorkspace when Cancel button is clicked', async () => {
|
|
154
|
+
const user = userEvent.setup();
|
|
155
|
+
const mockCloseWorkspace = jest.fn();
|
|
156
|
+
renderBillableServicesForm({ closeWorkspace: mockCloseWorkspace });
|
|
157
|
+
|
|
158
|
+
const cancelButton = screen.getByRole('button', { name: /cancel/i });
|
|
159
|
+
await user.click(cancelButton);
|
|
160
|
+
|
|
161
|
+
expect(mockCloseWorkspace).toHaveBeenCalledTimes(1);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('should call closeWorkspaceWithSavedChanges after successful save', async () => {
|
|
165
|
+
const user = userEvent.setup();
|
|
166
|
+
const mockCloseWorkspaceWithSavedChanges = jest.fn();
|
|
167
|
+
renderBillableServicesForm({ closeWorkspaceWithSavedChanges: mockCloseWorkspaceWithSavedChanges });
|
|
168
|
+
|
|
169
|
+
await fillRequiredFields(user);
|
|
170
|
+
mockCreateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
171
|
+
await submitForm();
|
|
172
|
+
|
|
173
|
+
// Wait for async submission
|
|
174
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
175
|
+
|
|
176
|
+
expect(mockCloseWorkspaceWithSavedChanges).toHaveBeenCalledTimes(1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('should disable buttons during submission', async () => {
|
|
180
|
+
const user = userEvent.setup();
|
|
181
|
+
let resolveCreate: (value: any) => void;
|
|
182
|
+
const createPromise = new Promise((resolve) => {
|
|
183
|
+
resolveCreate = resolve;
|
|
184
|
+
});
|
|
185
|
+
mockCreateBillableService.mockReturnValue(createPromise as any);
|
|
186
|
+
|
|
187
|
+
renderBillableServicesForm();
|
|
188
|
+
|
|
189
|
+
await fillRequiredFields(user);
|
|
190
|
+
const saveButton = screen.getByRole('button', { name: /save/i });
|
|
191
|
+
const cancelButton = screen.getByRole('button', { name: /cancel/i });
|
|
192
|
+
|
|
193
|
+
// Click save to trigger submission
|
|
194
|
+
await user.click(saveButton);
|
|
195
|
+
|
|
196
|
+
// Buttons should be disabled during submission
|
|
197
|
+
expect(saveButton).toBeDisabled();
|
|
198
|
+
expect(cancelButton).toBeDisabled();
|
|
199
|
+
|
|
200
|
+
// Resolve the promise to complete submission
|
|
201
|
+
resolveCreate!({} as FetchResponse<any>);
|
|
202
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('should show loading indicator in save button during submission', async () => {
|
|
206
|
+
const user = userEvent.setup();
|
|
207
|
+
let resolveCreate: (value: any) => void;
|
|
208
|
+
const createPromise = new Promise((resolve) => {
|
|
209
|
+
resolveCreate = resolve;
|
|
210
|
+
});
|
|
211
|
+
mockCreateBillableService.mockReturnValue(createPromise as any);
|
|
212
|
+
|
|
213
|
+
renderBillableServicesForm();
|
|
214
|
+
|
|
215
|
+
await fillRequiredFields(user);
|
|
216
|
+
const saveButton = screen.getByRole('button', { name: /save/i });
|
|
217
|
+
|
|
218
|
+
await user.click(saveButton);
|
|
219
|
+
|
|
220
|
+
// Should show loading indicator
|
|
221
|
+
expect(await screen.findByText(/saving/i)).toBeInTheDocument();
|
|
222
|
+
|
|
223
|
+
// Resolve the promise
|
|
224
|
+
resolveCreate!({} as FetchResponse<any>);
|
|
225
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('should call onWorkspaceClose callback after successful edit', async () => {
|
|
229
|
+
const mockOnWorkspaceClose = jest.fn();
|
|
230
|
+
const mockServiceToEdit: BillableService = {
|
|
231
|
+
uuid: 'test-uuid',
|
|
232
|
+
name: 'Test Service',
|
|
233
|
+
shortName: 'TS',
|
|
234
|
+
serviceStatus: 'ENABLED',
|
|
235
|
+
serviceType: {
|
|
236
|
+
uuid: 'type-uuid',
|
|
237
|
+
display: 'Lab service',
|
|
238
|
+
},
|
|
239
|
+
concept: null,
|
|
240
|
+
servicePrices: [
|
|
241
|
+
{
|
|
242
|
+
uuid: 'price-uuid',
|
|
243
|
+
name: 'Cash',
|
|
244
|
+
price: 100,
|
|
245
|
+
paymentMode: {
|
|
246
|
+
uuid: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74',
|
|
247
|
+
name: 'Cash',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
renderBillableServicesForm({ serviceToEdit: mockServiceToEdit, onWorkspaceClose: mockOnWorkspaceClose });
|
|
254
|
+
|
|
255
|
+
mockUpdateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
256
|
+
await submitForm();
|
|
257
|
+
|
|
258
|
+
// Wait for async submission
|
|
259
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
260
|
+
|
|
261
|
+
expect(mockOnWorkspaceClose).toHaveBeenCalledTimes(1);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe('Form Validation', () => {
|
|
266
|
+
test('should accept form submission without short name (short name is optional)', async () => {
|
|
267
|
+
const user = userEvent.setup();
|
|
268
|
+
renderBillableServicesForm();
|
|
269
|
+
|
|
270
|
+
// Fill required fields but skip short name
|
|
271
|
+
await user.type(screen.getByRole('textbox', { name: /Service name/i }), 'Lab Test');
|
|
272
|
+
|
|
273
|
+
await user.click(screen.getByRole('combobox', { name: /Service type/i }));
|
|
274
|
+
await user.click(screen.getByRole('option', { name: /Lab service/i }));
|
|
275
|
+
|
|
276
|
+
await user.click(screen.getByRole('combobox', { name: /Payment mode/i }));
|
|
277
|
+
await user.click(screen.getByRole('option', { name: /Cash/i }));
|
|
278
|
+
|
|
279
|
+
const priceInput = screen.getByRole('spinbutton', { name: /Selling Price/i });
|
|
280
|
+
await user.type(priceInput, '50');
|
|
281
|
+
|
|
282
|
+
mockCreateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
283
|
+
|
|
284
|
+
await submitForm();
|
|
285
|
+
|
|
286
|
+
expect(mockCreateBillableService).toHaveBeenCalledWith(
|
|
287
|
+
expect.objectContaining({
|
|
288
|
+
name: 'Lab Test',
|
|
289
|
+
shortName: '', // Empty string is valid
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('should enforce 255 character limit on service name input', async () => {
|
|
295
|
+
const user = userEvent.setup();
|
|
296
|
+
renderBillableServicesForm();
|
|
297
|
+
|
|
298
|
+
const longName = 'A'.repeat(300); // Try to type 300 characters
|
|
299
|
+
const input = screen.getByRole('textbox', { name: /Service name/i });
|
|
300
|
+
await user.type(input, longName);
|
|
301
|
+
|
|
302
|
+
// Input should be truncated to 255 chars due to maxLength attribute
|
|
303
|
+
expect(input).toHaveValue('A'.repeat(255));
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('should enforce 255 character limit on short name input', async () => {
|
|
307
|
+
const user = userEvent.setup();
|
|
308
|
+
renderBillableServicesForm();
|
|
309
|
+
|
|
310
|
+
const longShortName = 'B'.repeat(300); // Try to type 300 characters
|
|
311
|
+
const input = screen.getByRole('textbox', { name: /Short name/i });
|
|
312
|
+
await user.type(input, longShortName);
|
|
313
|
+
|
|
314
|
+
// Input should be truncated to 255 chars due to maxLength attribute
|
|
315
|
+
expect(input).toHaveValue('B'.repeat(255));
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('should show "Price must be greater than 0" error for zero price', async () => {
|
|
319
|
+
const user = userEvent.setup();
|
|
320
|
+
renderBillableServicesForm();
|
|
321
|
+
|
|
322
|
+
await fillRequiredFields(user, { skipPrice: true });
|
|
323
|
+
|
|
324
|
+
const priceInput = screen.getByRole('spinbutton', { name: /selling price/i });
|
|
325
|
+
await user.type(priceInput, '0');
|
|
326
|
+
|
|
327
|
+
await submitForm();
|
|
328
|
+
|
|
329
|
+
expect(screen.getByText('Price must be greater than 0')).toBeInTheDocument();
|
|
330
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('should show "Price must be greater than 0" error for negative price', async () => {
|
|
334
|
+
const user = userEvent.setup();
|
|
335
|
+
renderBillableServicesForm();
|
|
336
|
+
|
|
337
|
+
await fillRequiredFields(user, { skipPrice: true });
|
|
338
|
+
|
|
339
|
+
const priceInput = screen.getByRole('spinbutton', { name: /Selling Price/i });
|
|
340
|
+
await user.type(priceInput, '-10');
|
|
341
|
+
|
|
342
|
+
await submitForm();
|
|
343
|
+
|
|
344
|
+
expect(screen.getByText('Price must be greater than 0')).toBeInTheDocument();
|
|
345
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test('should show "Service name is required" error when service name is empty', async () => {
|
|
349
|
+
const user = userEvent.setup();
|
|
350
|
+
renderBillableServicesForm();
|
|
351
|
+
|
|
352
|
+
// Fill all fields except service name
|
|
353
|
+
await user.type(screen.getByRole('textbox', { name: /Short name/i }), 'Test Short Name');
|
|
354
|
+
|
|
355
|
+
await user.click(screen.getByRole('combobox', { name: /Service type/i }));
|
|
356
|
+
await user.click(screen.getByRole('option', { name: /Lab service/i }));
|
|
357
|
+
|
|
358
|
+
await user.click(screen.getByRole('combobox', { name: /Payment mode/i }));
|
|
359
|
+
await user.click(screen.getByRole('option', { name: /Cash/i }));
|
|
360
|
+
|
|
361
|
+
const priceInput = screen.getByRole('spinbutton', { name: /Selling Price/i });
|
|
362
|
+
await user.type(priceInput, '100');
|
|
363
|
+
|
|
364
|
+
await submitForm();
|
|
365
|
+
|
|
366
|
+
expect(await screen.findByText('Service name is required')).toBeInTheDocument();
|
|
367
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('should accept valid decimal price values', async () => {
|
|
371
|
+
const user = userEvent.setup();
|
|
372
|
+
renderBillableServicesForm();
|
|
373
|
+
|
|
374
|
+
await fillRequiredFields(user, { skipPrice: true });
|
|
375
|
+
|
|
376
|
+
const priceInput = screen.getByRole('spinbutton', { name: /selling price/i });
|
|
377
|
+
await user.type(priceInput, '10.50');
|
|
378
|
+
|
|
379
|
+
mockCreateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
380
|
+
|
|
381
|
+
await submitForm();
|
|
382
|
+
|
|
383
|
+
expect(screen.queryByText('Price is required')).not.toBeInTheDocument();
|
|
384
|
+
expect(screen.queryByText('Price must be greater than 0')).not.toBeInTheDocument();
|
|
385
|
+
expect(mockCreateBillableService).toHaveBeenCalledTimes(1);
|
|
386
|
+
expect(mockCreateBillableService).toHaveBeenCalledWith({
|
|
387
|
+
name: 'Test Service Name',
|
|
388
|
+
shortName: 'Test Short Name',
|
|
389
|
+
serviceType: 'c9604249-db0a-4d03-b074-fc6bc2fa13e6',
|
|
390
|
+
servicePrices: [
|
|
391
|
+
{
|
|
392
|
+
paymentMode: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74',
|
|
393
|
+
price: 10.5,
|
|
394
|
+
name: 'Cash',
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
serviceStatus: 'ENABLED',
|
|
398
|
+
concept: undefined,
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test('should show "Service type is required" error when not selected', async () => {
|
|
403
|
+
const user = userEvent.setup();
|
|
404
|
+
renderBillableServicesForm();
|
|
405
|
+
|
|
406
|
+
await user.type(screen.getByRole('textbox', { name: /Service name/i }), 'Test Service');
|
|
407
|
+
await user.type(screen.getByRole('textbox', { name: /Short name/i }), 'Test Short Name');
|
|
408
|
+
|
|
409
|
+
await user.click(screen.getByRole('combobox', { name: /Payment mode/i }));
|
|
410
|
+
await user.click(screen.getByRole('option', { name: /Cash/i }));
|
|
411
|
+
|
|
412
|
+
const priceInput = screen.getByRole('spinbutton', { name: /Selling Price/i });
|
|
413
|
+
await user.type(priceInput, '100');
|
|
414
|
+
|
|
415
|
+
await submitForm();
|
|
416
|
+
|
|
417
|
+
expect(await screen.findByText('Service type is required')).toBeInTheDocument();
|
|
418
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test('should show "Payment mode is required" error when not selected', async () => {
|
|
422
|
+
const user = userEvent.setup();
|
|
423
|
+
renderBillableServicesForm();
|
|
424
|
+
|
|
425
|
+
await user.type(screen.getByRole('textbox', { name: /Service name/i }), 'Test Service');
|
|
426
|
+
await user.type(screen.getByRole('textbox', { name: /Short name/i }), 'Test Short Name');
|
|
427
|
+
|
|
428
|
+
await user.click(screen.getByRole('combobox', { name: /Service type/i }));
|
|
429
|
+
await user.click(screen.getByRole('option', { name: /Lab service/i }));
|
|
430
|
+
|
|
431
|
+
const priceInput = screen.getByRole('spinbutton', { name: /Selling Price/i });
|
|
432
|
+
await user.type(priceInput, '100');
|
|
433
|
+
|
|
434
|
+
await submitForm();
|
|
435
|
+
|
|
436
|
+
expect(await screen.findByText('Payment mode is required')).toBeInTheDocument();
|
|
437
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('should show "Price is required" error when price field is empty', async () => {
|
|
441
|
+
const user = userEvent.setup();
|
|
442
|
+
renderBillableServicesForm();
|
|
443
|
+
|
|
444
|
+
await fillRequiredFields(user, { skipPrice: true });
|
|
445
|
+
|
|
446
|
+
await submitForm();
|
|
447
|
+
|
|
448
|
+
expect(await screen.findByText('Price is required')).toBeInTheDocument();
|
|
449
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
describe('Edit Mode', () => {
|
|
454
|
+
const mockServiceToEdit: BillableService = {
|
|
455
|
+
uuid: 'existing-service-uuid',
|
|
456
|
+
name: 'X-Ray Service',
|
|
457
|
+
shortName: 'XRay',
|
|
458
|
+
serviceStatus: 'ENABLED',
|
|
459
|
+
serviceType: {
|
|
460
|
+
uuid: 'c9604249-db0a-4d03-b074-fc6bc2fa13e6',
|
|
461
|
+
display: 'Lab service',
|
|
462
|
+
},
|
|
463
|
+
concept: null,
|
|
464
|
+
servicePrices: [
|
|
465
|
+
{
|
|
466
|
+
uuid: 'price-uuid',
|
|
467
|
+
name: 'Cash',
|
|
468
|
+
price: 150,
|
|
469
|
+
paymentMode: {
|
|
470
|
+
uuid: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74',
|
|
471
|
+
name: 'Cash',
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
],
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
test('should populate form with existing service data', () => {
|
|
478
|
+
renderBillableServicesForm({ serviceToEdit: mockServiceToEdit });
|
|
479
|
+
|
|
480
|
+
expect(screen.getByText('X-Ray Service')).toBeInTheDocument(); // Service name shown as label
|
|
481
|
+
expect(screen.getByDisplayValue('XRay')).toBeInTheDocument(); // Short name
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
test('should call updateBillableService instead of createBillableService', async () => {
|
|
485
|
+
const user = userEvent.setup();
|
|
486
|
+
const mockCloseWorkspace = jest.fn();
|
|
487
|
+
renderBillableServicesForm({ serviceToEdit: mockServiceToEdit, closeWorkspace: mockCloseWorkspace });
|
|
488
|
+
|
|
489
|
+
const shortNameInput = screen.getByDisplayValue('XRay');
|
|
490
|
+
await user.clear(shortNameInput);
|
|
491
|
+
await user.type(shortNameInput, 'X-RAY');
|
|
492
|
+
|
|
493
|
+
mockUpdateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
494
|
+
|
|
495
|
+
await submitForm();
|
|
496
|
+
|
|
497
|
+
expect(mockUpdateBillableService).toHaveBeenCalledTimes(1);
|
|
498
|
+
expect(mockUpdateBillableService).toHaveBeenCalledWith('existing-service-uuid', {
|
|
499
|
+
name: 'X-Ray Service',
|
|
500
|
+
shortName: 'X-RAY',
|
|
501
|
+
serviceType: 'c9604249-db0a-4d03-b074-fc6bc2fa13e6',
|
|
502
|
+
servicePrices: [
|
|
503
|
+
{
|
|
504
|
+
paymentMode: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74',
|
|
505
|
+
price: 150,
|
|
506
|
+
name: 'Cash',
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
serviceStatus: 'ENABLED',
|
|
510
|
+
concept: undefined,
|
|
511
|
+
});
|
|
512
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
test('should call onWorkspaceClose callback after successful edit', async () => {
|
|
516
|
+
const mockOnWorkspaceClose = jest.fn();
|
|
517
|
+
renderBillableServicesForm({ serviceToEdit: mockServiceToEdit, onWorkspaceClose: mockOnWorkspaceClose });
|
|
518
|
+
|
|
519
|
+
mockUpdateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
520
|
+
|
|
521
|
+
await submitForm();
|
|
522
|
+
|
|
523
|
+
expect(mockOnWorkspaceClose).toHaveBeenCalledTimes(1);
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
test('should not allow editing service name in edit mode', () => {
|
|
527
|
+
renderBillableServicesForm({ serviceToEdit: mockServiceToEdit });
|
|
528
|
+
|
|
529
|
+
// Service name should be displayed as a label, not an editable input
|
|
530
|
+
expect(screen.getByText('X-Ray Service')).toBeInTheDocument();
|
|
531
|
+
expect(screen.queryByRole('textbox', { name: /Service name/i })).not.toBeInTheDocument();
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
test('should handle asynchronous loading of dependencies and populate form correctly', async () => {
|
|
535
|
+
// Scenario: User opens edit form, but payment modes/service types haven't loaded yet
|
|
536
|
+
// The form should wait for dependencies to load, then populate correctly
|
|
537
|
+
|
|
538
|
+
renderBillableServicesForm({ serviceToEdit: mockServiceToEdit });
|
|
539
|
+
|
|
540
|
+
// After dependencies load (handled by renderBillableServicesForm's setupMocks),
|
|
541
|
+
// form should display with populated data
|
|
542
|
+
expect(await screen.findByText('X-Ray Service')).toBeInTheDocument();
|
|
543
|
+
expect(screen.getByDisplayValue('XRay')).toBeInTheDocument();
|
|
544
|
+
|
|
545
|
+
// This test verifies the useEffect that calls reset() when dependencies load
|
|
546
|
+
// The behavior is: even if payment modes/types load after initial render,
|
|
547
|
+
// the form will update to show the service data
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
describe('Dynamic Payment Options', () => {
|
|
552
|
+
test('should add new payment option when clicking "Add payment option" button', async () => {
|
|
553
|
+
const user = userEvent.setup();
|
|
554
|
+
renderBillableServicesForm();
|
|
555
|
+
|
|
556
|
+
const addButton = screen.getByRole('button', { name: /Add payment option/i });
|
|
557
|
+
await user.click(addButton);
|
|
558
|
+
|
|
559
|
+
const paymentModeDropdowns = screen.getAllByRole('combobox', { name: /Payment mode/i });
|
|
560
|
+
expect(paymentModeDropdowns).toHaveLength(2);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
test('should be able to add multiple payment options', async () => {
|
|
564
|
+
const user = userEvent.setup();
|
|
565
|
+
renderBillableServicesForm();
|
|
566
|
+
|
|
567
|
+
// Add a second payment option
|
|
568
|
+
const addButton = screen.getByRole('button', { name: /Add payment option/i });
|
|
569
|
+
await user.click(addButton);
|
|
570
|
+
|
|
571
|
+
const paymentModeDropdowns = screen.getAllByRole('combobox', { name: /Payment mode/i });
|
|
572
|
+
expect(paymentModeDropdowns).toHaveLength(2);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
test('should allow adding multiple payment options with different payment modes', async () => {
|
|
576
|
+
const user = userEvent.setup();
|
|
577
|
+
renderBillableServicesForm();
|
|
578
|
+
|
|
579
|
+
// Add second payment option
|
|
580
|
+
const addButton = screen.getByRole('button', { name: /Add payment option/i });
|
|
581
|
+
await user.click(addButton);
|
|
582
|
+
|
|
583
|
+
// Fill in first payment option
|
|
584
|
+
const paymentModeDropdowns = screen.getAllByRole('combobox', { name: /Payment mode/i });
|
|
585
|
+
await user.click(paymentModeDropdowns[0]);
|
|
586
|
+
await user.click(screen.getByRole('option', { name: /Cash/i }));
|
|
587
|
+
|
|
588
|
+
const priceInputs = screen.getAllByRole('spinbutton', { name: /Selling Price/i });
|
|
589
|
+
await user.type(priceInputs[0], '100');
|
|
590
|
+
|
|
591
|
+
// Fill in second payment option
|
|
592
|
+
await user.click(paymentModeDropdowns[1]);
|
|
593
|
+
await user.click(screen.getByRole('option', { name: /Insurance/i }));
|
|
594
|
+
await user.type(priceInputs[1], '80');
|
|
595
|
+
|
|
596
|
+
// Fill other required fields
|
|
597
|
+
await user.type(screen.getByRole('textbox', { name: /Service name/i }), 'Multi-price Service');
|
|
598
|
+
await user.type(screen.getByRole('textbox', { name: /Short name/i }), 'MPS');
|
|
599
|
+
await user.click(screen.getByRole('combobox', { name: /Service type/i }));
|
|
600
|
+
await user.click(screen.getByRole('option', { name: /Lab service/i }));
|
|
601
|
+
|
|
602
|
+
mockCreateBillableService.mockResolvedValue({} as FetchResponse<any>);
|
|
603
|
+
await submitForm();
|
|
604
|
+
|
|
605
|
+
expect(mockCreateBillableService).toHaveBeenCalledWith(
|
|
606
|
+
expect.objectContaining({
|
|
607
|
+
servicePrices: [
|
|
608
|
+
{
|
|
609
|
+
paymentMode: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74',
|
|
610
|
+
price: 100,
|
|
611
|
+
name: 'Cash',
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
paymentMode: 'beac329b-f1dc-4a33-9e7c-d95821a137a6',
|
|
615
|
+
price: 80,
|
|
616
|
+
name: 'Insurance',
|
|
617
|
+
},
|
|
618
|
+
],
|
|
619
|
+
}),
|
|
620
|
+
);
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
test('should validate each payment option independently', async () => {
|
|
624
|
+
const user = userEvent.setup();
|
|
625
|
+
renderBillableServicesForm();
|
|
626
|
+
|
|
627
|
+
// Add second payment option
|
|
628
|
+
const addButton = screen.getByRole('button', { name: /Add payment option/i });
|
|
629
|
+
await user.click(addButton);
|
|
630
|
+
|
|
631
|
+
// Fill first payment option correctly
|
|
632
|
+
const paymentModeDropdowns = screen.getAllByRole('combobox', { name: /Payment mode/i });
|
|
633
|
+
await user.click(paymentModeDropdowns[0]);
|
|
634
|
+
await user.click(screen.getByRole('option', { name: /Cash/i }));
|
|
635
|
+
|
|
636
|
+
const priceInputs = screen.getAllByRole('spinbutton', { name: /Selling Price/i });
|
|
637
|
+
await user.type(priceInputs[0], '100');
|
|
638
|
+
|
|
639
|
+
// Leave second payment option incomplete (no price)
|
|
640
|
+
await user.click(paymentModeDropdowns[1]);
|
|
641
|
+
await user.click(screen.getByRole('option', { name: /Insurance/i }));
|
|
642
|
+
|
|
643
|
+
// Fill other required fields
|
|
644
|
+
await user.type(screen.getByRole('textbox', { name: /Service name/i }), 'Test Service');
|
|
645
|
+
await user.type(screen.getByRole('textbox', { name: /Short name/i }), 'TS');
|
|
646
|
+
await user.click(screen.getByRole('combobox', { name: /Service type/i }));
|
|
647
|
+
await user.click(screen.getByRole('option', { name: /Lab service/i }));
|
|
648
|
+
|
|
649
|
+
await submitForm();
|
|
650
|
+
|
|
651
|
+
// Should show error for the second payment option's missing price
|
|
652
|
+
const priceErrors = await screen.findAllByText('Price is required');
|
|
653
|
+
expect(priceErrors.length).toBeGreaterThan(0);
|
|
654
|
+
expect(mockCreateBillableService).not.toHaveBeenCalled();
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
describe('Error Handling', () => {
|
|
659
|
+
test('should display error snackbar when create API call fails', async () => {
|
|
660
|
+
const user = userEvent.setup();
|
|
661
|
+
renderBillableServicesForm();
|
|
662
|
+
|
|
663
|
+
await fillRequiredFields(user);
|
|
664
|
+
|
|
665
|
+
const errorMessage = 'Network error';
|
|
666
|
+
mockCreateBillableService.mockRejectedValue(new Error(errorMessage));
|
|
667
|
+
|
|
668
|
+
await submitForm();
|
|
669
|
+
|
|
670
|
+
// Wait for async operations to complete
|
|
671
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
672
|
+
|
|
673
|
+
expect(mockCreateBillableService).toHaveBeenCalledTimes(1);
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
test('should display error snackbar when update API call fails', async () => {
|
|
677
|
+
const user = userEvent.setup();
|
|
678
|
+
const mockServiceToEdit: BillableService = {
|
|
679
|
+
uuid: 'service-uuid',
|
|
680
|
+
name: 'Test Service',
|
|
681
|
+
shortName: 'TS',
|
|
682
|
+
serviceStatus: 'ENABLED',
|
|
683
|
+
serviceType: {
|
|
684
|
+
uuid: 'c9604249-db0a-4d03-b074-fc6bc2fa13e6',
|
|
685
|
+
display: 'Lab service',
|
|
686
|
+
},
|
|
687
|
+
concept: null,
|
|
688
|
+
servicePrices: [
|
|
689
|
+
{
|
|
690
|
+
uuid: 'price-uuid',
|
|
691
|
+
name: 'Cash',
|
|
692
|
+
price: 100,
|
|
693
|
+
paymentMode: {
|
|
694
|
+
uuid: '63eff7a4-6f82-43c4-a333-dbcc58fe9f74',
|
|
695
|
+
name: 'Cash',
|
|
696
|
+
},
|
|
697
|
+
},
|
|
698
|
+
],
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
renderBillableServicesForm({ serviceToEdit: mockServiceToEdit });
|
|
702
|
+
|
|
703
|
+
const errorMessage = 'Update failed';
|
|
704
|
+
mockUpdateBillableService.mockRejectedValue(new Error(errorMessage));
|
|
705
|
+
|
|
706
|
+
await submitForm();
|
|
707
|
+
|
|
708
|
+
// Wait for async operations to complete
|
|
709
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
710
|
+
|
|
711
|
+
expect(mockUpdateBillableService).toHaveBeenCalledTimes(1);
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
describe('Helper Functions', () => {
|
|
717
|
+
describe('transformServiceToFormData', () => {
|
|
718
|
+
test('should return default form data when no service is provided', () => {
|
|
719
|
+
const result = transformServiceToFormData();
|
|
720
|
+
|
|
721
|
+
expect(result).toEqual({
|
|
722
|
+
name: '',
|
|
723
|
+
shortName: '',
|
|
724
|
+
serviceType: null,
|
|
725
|
+
concept: null,
|
|
726
|
+
payment: [{ paymentMode: '', price: '' }],
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
test('should return default form data when undefined service is provided', () => {
|
|
731
|
+
const result = transformServiceToFormData(undefined);
|
|
732
|
+
|
|
733
|
+
expect(result).toEqual({
|
|
734
|
+
name: '',
|
|
735
|
+
shortName: '',
|
|
736
|
+
serviceType: null,
|
|
737
|
+
concept: null,
|
|
738
|
+
payment: [{ paymentMode: '', price: '' }],
|
|
739
|
+
});
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
test('should transform a complete service to form data', () => {
|
|
743
|
+
const service: BillableService = {
|
|
744
|
+
uuid: 'service-uuid',
|
|
745
|
+
name: 'X-Ray',
|
|
746
|
+
shortName: 'XRay',
|
|
747
|
+
serviceStatus: 'ENABLED',
|
|
748
|
+
serviceType: {
|
|
749
|
+
uuid: 'type-uuid',
|
|
750
|
+
display: 'Lab service',
|
|
751
|
+
},
|
|
752
|
+
concept: {
|
|
753
|
+
uuid: 'concept-search-result-uuid',
|
|
754
|
+
concept: {
|
|
755
|
+
uuid: 'concept-uuid',
|
|
756
|
+
display: 'Radiology',
|
|
757
|
+
},
|
|
758
|
+
display: 'Radiology',
|
|
759
|
+
},
|
|
760
|
+
servicePrices: [
|
|
761
|
+
{
|
|
762
|
+
uuid: 'price-uuid-1',
|
|
763
|
+
name: 'Cash',
|
|
764
|
+
price: 100,
|
|
765
|
+
paymentMode: {
|
|
766
|
+
uuid: 'payment-mode-uuid-1',
|
|
767
|
+
name: 'Cash',
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
uuid: 'price-uuid-2',
|
|
772
|
+
name: 'Insurance',
|
|
773
|
+
price: 80,
|
|
774
|
+
paymentMode: {
|
|
775
|
+
uuid: 'payment-mode-uuid-2',
|
|
776
|
+
name: 'Insurance',
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
],
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
const result = transformServiceToFormData(service);
|
|
783
|
+
|
|
784
|
+
expect(result).toEqual({
|
|
785
|
+
name: 'X-Ray',
|
|
786
|
+
shortName: 'XRay',
|
|
787
|
+
serviceType: {
|
|
788
|
+
uuid: 'type-uuid',
|
|
789
|
+
display: 'Lab service',
|
|
790
|
+
},
|
|
791
|
+
concept: {
|
|
792
|
+
uuid: 'concept-search-result-uuid',
|
|
793
|
+
display: 'Radiology',
|
|
794
|
+
},
|
|
795
|
+
payment: [
|
|
796
|
+
{
|
|
797
|
+
paymentMode: 'payment-mode-uuid-1',
|
|
798
|
+
price: 100,
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
paymentMode: 'payment-mode-uuid-2',
|
|
802
|
+
price: 80,
|
|
803
|
+
},
|
|
804
|
+
],
|
|
805
|
+
});
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
test('should handle service without concept', () => {
|
|
809
|
+
const service: BillableService = {
|
|
810
|
+
uuid: 'service-uuid',
|
|
811
|
+
name: 'Basic Service',
|
|
812
|
+
shortName: 'BS',
|
|
813
|
+
serviceStatus: 'ENABLED',
|
|
814
|
+
serviceType: {
|
|
815
|
+
uuid: 'type-uuid',
|
|
816
|
+
display: 'General',
|
|
817
|
+
},
|
|
818
|
+
concept: null,
|
|
819
|
+
servicePrices: [
|
|
820
|
+
{
|
|
821
|
+
uuid: 'price-uuid',
|
|
822
|
+
name: 'Cash',
|
|
823
|
+
price: 50,
|
|
824
|
+
paymentMode: {
|
|
825
|
+
uuid: 'payment-mode-uuid',
|
|
826
|
+
name: 'Cash',
|
|
827
|
+
},
|
|
828
|
+
},
|
|
829
|
+
],
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
const result = transformServiceToFormData(service);
|
|
833
|
+
|
|
834
|
+
expect(result.concept).toBeNull();
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
test('should handle service with missing or empty price using nullish coalescing', () => {
|
|
838
|
+
const service: BillableService = {
|
|
839
|
+
uuid: 'service-uuid',
|
|
840
|
+
name: 'Test Service',
|
|
841
|
+
shortName: 'TS',
|
|
842
|
+
serviceStatus: 'ENABLED',
|
|
843
|
+
serviceType: {
|
|
844
|
+
uuid: 'type-uuid',
|
|
845
|
+
display: 'General',
|
|
846
|
+
},
|
|
847
|
+
concept: null,
|
|
848
|
+
servicePrices: [
|
|
849
|
+
{
|
|
850
|
+
uuid: 'price-uuid',
|
|
851
|
+
name: 'Cash',
|
|
852
|
+
price: 0, // Falsy but valid
|
|
853
|
+
paymentMode: {
|
|
854
|
+
uuid: 'payment-mode-uuid',
|
|
855
|
+
name: 'Cash',
|
|
856
|
+
},
|
|
857
|
+
},
|
|
858
|
+
],
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
const result = transformServiceToFormData(service);
|
|
862
|
+
|
|
863
|
+
// Price 0 should be preserved (not converted to empty string)
|
|
864
|
+
expect(result.payment[0].price).toBe(0);
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
describe('normalizePrice', () => {
|
|
869
|
+
test('should return number as-is', () => {
|
|
870
|
+
expect(normalizePrice(100)).toBe(100);
|
|
871
|
+
expect(normalizePrice(10.5)).toBe(10.5);
|
|
872
|
+
expect(normalizePrice(0)).toBe(0);
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
test('should convert string to number', () => {
|
|
876
|
+
expect(normalizePrice('100')).toBe(100);
|
|
877
|
+
expect(normalizePrice('10.5')).toBe(10.5);
|
|
878
|
+
expect(normalizePrice('0')).toBe(0);
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
test('should handle decimal strings correctly', () => {
|
|
882
|
+
expect(normalizePrice('10.99')).toBe(10.99);
|
|
883
|
+
expect(normalizePrice('0.50')).toBe(0.5);
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
test('should handle undefined by converting to NaN', () => {
|
|
887
|
+
expect(normalizePrice(undefined)).toBeNaN();
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
test('should handle empty string by converting to NaN', () => {
|
|
891
|
+
expect(normalizePrice('')).toBeNaN();
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
test('should handle invalid string by converting to NaN', () => {
|
|
895
|
+
expect(normalizePrice('invalid')).toBeNaN();
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
});
|