@openmrs/esm-billing-app 1.0.2-pre.76 → 1.0.2-pre.761

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 (198) hide show
  1. package/README.md +55 -9
  2. package/__mocks__/bills.mock.ts +12 -0
  3. package/__mocks__/react-i18next.js +6 -5
  4. package/dist/1119.js +1 -1
  5. package/dist/1146.js +1 -2
  6. package/dist/1146.js.map +1 -1
  7. package/dist/1197.js +1 -1
  8. package/dist/1856.js +1 -0
  9. package/dist/1856.js.map +1 -0
  10. package/dist/2146.js +1 -1
  11. package/dist/2177.js +2 -0
  12. package/dist/2177.js.LICENSE.txt +9 -0
  13. package/dist/2177.js.map +1 -0
  14. package/dist/2524.js +1 -0
  15. package/dist/2524.js.map +1 -0
  16. package/dist/2690.js +1 -1
  17. package/dist/3041.js +1 -0
  18. package/dist/3041.js.map +1 -0
  19. package/dist/3099.js +1 -1
  20. package/dist/3584.js +1 -1
  21. package/dist/4055.js +1 -1
  22. package/dist/4132.js +1 -1
  23. package/dist/4225.js +1 -0
  24. package/dist/4225.js.map +1 -0
  25. package/dist/4300.js +1 -1
  26. package/dist/4335.js +1 -1
  27. package/dist/4618.js +1 -1
  28. package/dist/4652.js +1 -1
  29. package/dist/4724.js +1 -0
  30. package/dist/4724.js.map +1 -0
  31. package/dist/4739.js +1 -1
  32. package/dist/4739.js.map +1 -1
  33. package/dist/4944.js +1 -1
  34. package/dist/5173.js +1 -1
  35. package/dist/5241.js +1 -1
  36. package/dist/5422.js +1 -0
  37. package/dist/5422.js.map +1 -0
  38. package/dist/5442.js +1 -1
  39. package/dist/5661.js +1 -1
  40. package/dist/6022.js +1 -1
  41. package/dist/6468.js +1 -1
  42. package/dist/6540.js +1 -1
  43. package/dist/6540.js.map +1 -1
  44. package/dist/6606.js +1 -0
  45. package/dist/6606.js.map +1 -0
  46. package/dist/6679.js +1 -1
  47. package/dist/6840.js +1 -1
  48. package/dist/6859.js +1 -1
  49. package/dist/7097.js +1 -1
  50. package/dist/7159.js +1 -1
  51. package/dist/723.js +1 -1
  52. package/dist/7452.js +2 -0
  53. package/dist/7452.js.map +1 -0
  54. package/dist/7617.js +1 -1
  55. package/dist/795.js +1 -1
  56. package/dist/8163.js +1 -1
  57. package/dist/8349.js +1 -1
  58. package/dist/8618.js +1 -1
  59. package/dist/890.js +1 -1
  60. package/dist/8930.js +2 -0
  61. package/dist/{6525.js.LICENSE.txt → 8930.js.LICENSE.txt} +16 -4
  62. package/dist/8930.js.map +1 -0
  63. package/dist/9214.js +1 -1
  64. package/dist/942.js +1 -0
  65. package/dist/942.js.map +1 -0
  66. package/dist/9538.js +1 -1
  67. package/dist/9569.js +1 -1
  68. package/dist/961.js +1 -1
  69. package/dist/961.js.map +1 -1
  70. package/dist/986.js +1 -1
  71. package/dist/9879.js +1 -1
  72. package/dist/9895.js +1 -1
  73. package/dist/9900.js +1 -1
  74. package/dist/9913.js +1 -1
  75. package/dist/main.js +1 -1
  76. package/dist/main.js.map +1 -1
  77. package/dist/openmrs-esm-billing-app.js +1 -1
  78. package/dist/openmrs-esm-billing-app.js.buildmanifest.json +368 -262
  79. package/dist/openmrs-esm-billing-app.js.map +1 -1
  80. package/dist/routes.json +1 -1
  81. package/e2e/README.md +19 -18
  82. package/e2e/specs/sample-test.spec.ts +0 -1
  83. package/package.json +10 -10
  84. package/src/bill-history/bill-history.component.tsx +17 -25
  85. package/src/bill-history/bill-history.scss +4 -94
  86. package/src/bill-history/bill-history.test.tsx +37 -78
  87. package/src/bill-item-actions/bill-item-actions.scss +0 -4
  88. package/src/bill-item-actions/{edit-bill-item.component.tsx → edit-bill-item.modal.tsx} +57 -56
  89. package/src/bill-item-actions/edit-bill-item.test.tsx +22 -25
  90. package/src/billable-services/bill-waiver/bill-selection.component.tsx +2 -2
  91. package/src/billable-services/bill-waiver/patient-bills.component.tsx +3 -3
  92. package/src/billable-services/billable-service.resource.ts +17 -9
  93. package/src/billable-services/billable-services-home.component.tsx +1 -1
  94. package/src/billable-services/billable-services.component.tsx +142 -145
  95. package/src/billable-services/billable-services.scss +3 -0
  96. package/src/billable-services/billable-services.test.tsx +2 -45
  97. package/src/billable-services/cash-point/add-cash-point.modal.tsx +168 -0
  98. package/src/billable-services/cash-point/cash-point-configuration.component.tsx +18 -192
  99. package/src/billable-services/cash-point/cash-point-configuration.scss +1 -5
  100. package/src/billable-services/create-edit/add-billable-service.component.tsx +345 -298
  101. package/src/billable-services/create-edit/add-billable-service.scss +5 -6
  102. package/src/billable-services/create-edit/add-billable-service.test.tsx +37 -36
  103. package/src/billable-services/create-edit/edit-billable-service.modal.tsx +51 -0
  104. package/src/billable-services/payment-modes/add-payment-mode.modal.tsx +121 -0
  105. package/src/billable-services/payment-modes/delete-payment-mode.modal.tsx +72 -0
  106. package/src/billable-services/payment-modes/payment-modes-config.component.tsx +125 -0
  107. package/src/billable-services/{payyment-modes → payment-modes}/payment-modes-config.scss +5 -4
  108. package/src/billing-form/billing-checkin-form.component.tsx +2 -3
  109. package/src/billing-form/billing-checkin-form.test.tsx +97 -24
  110. package/src/billing-form/billing-form.component.tsx +214 -269
  111. package/src/billing-form/billing-form.scss +143 -0
  112. package/src/billing.resource.ts +16 -19
  113. package/src/bills-table/bills-table.test.tsx +97 -53
  114. package/src/config-schema.ts +52 -18
  115. package/src/dashboard.meta.ts +4 -2
  116. package/src/helpers/functions.ts +5 -4
  117. package/src/index.ts +17 -6
  118. package/src/invoice/invoice-table.component.tsx +24 -54
  119. package/src/invoice/invoice-table.scss +1 -5
  120. package/src/invoice/invoice-table.test.tsx +21 -47
  121. package/src/invoice/invoice.component.tsx +36 -29
  122. package/src/invoice/invoice.scss +7 -4
  123. package/src/invoice/invoice.test.tsx +22 -48
  124. package/src/invoice/payments/payment-form/payment-form.component.tsx +29 -29
  125. package/src/invoice/payments/payment-form/payment-form.scss +5 -6
  126. package/src/invoice/payments/payment-form/payment-form.test.tsx +215 -67
  127. package/src/invoice/payments/payment-history/payment-history.component.tsx +6 -4
  128. package/src/invoice/payments/payment-history/payment-history.test.tsx +9 -14
  129. package/src/invoice/payments/payments.component.tsx +53 -65
  130. package/src/invoice/payments/payments.test.tsx +282 -0
  131. package/src/invoice/payments/utils.ts +5 -23
  132. package/src/invoice/printable-invoice/print-receipt.component.tsx +3 -2
  133. package/src/invoice/printable-invoice/print-receipt.test.tsx +14 -25
  134. package/src/invoice/printable-invoice/printable-footer.component.tsx +2 -2
  135. package/src/invoice/printable-invoice/printable-footer.test.tsx +4 -13
  136. package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +12 -11
  137. package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +16 -14
  138. package/src/invoice/printable-invoice/printable-invoice.component.tsx +19 -33
  139. package/src/metrics-cards/metrics-cards.test.tsx +18 -5
  140. package/src/modal/require-payment-modal.test.tsx +27 -22
  141. package/src/modal/{require-payment-modal.component.tsx → require-payment.modal.tsx} +17 -18
  142. package/src/routes.json +22 -2
  143. package/src/types/index.ts +26 -17
  144. package/translations/am.json +60 -18
  145. package/translations/ar.json +60 -18
  146. package/translations/ar_SY.json +60 -18
  147. package/translations/bn.json +65 -23
  148. package/translations/de.json +60 -18
  149. package/translations/en.json +60 -18
  150. package/translations/en_US.json +60 -18
  151. package/translations/es.json +60 -18
  152. package/translations/es_MX.json +60 -18
  153. package/translations/fr.json +73 -31
  154. package/translations/he.json +60 -18
  155. package/translations/hi.json +60 -18
  156. package/translations/hi_IN.json +60 -18
  157. package/translations/id.json +61 -19
  158. package/translations/it.json +96 -54
  159. package/translations/ka.json +61 -19
  160. package/translations/km.json +60 -18
  161. package/translations/ku.json +60 -18
  162. package/translations/ky.json +60 -18
  163. package/translations/lg.json +60 -18
  164. package/translations/ne.json +60 -18
  165. package/translations/pl.json +60 -18
  166. package/translations/pt.json +60 -18
  167. package/translations/pt_BR.json +60 -18
  168. package/translations/qu.json +60 -18
  169. package/translations/ro_RO.json +206 -164
  170. package/translations/ru_RU.json +60 -18
  171. package/translations/si.json +60 -18
  172. package/translations/sw.json +60 -18
  173. package/translations/sw_KE.json +60 -18
  174. package/translations/tr.json +60 -18
  175. package/translations/tr_TR.json +60 -18
  176. package/translations/uk.json +60 -18
  177. package/translations/uz.json +60 -18
  178. package/translations/uz@Latn.json +60 -18
  179. package/translations/uz_UZ.json +60 -18
  180. package/translations/vi.json +60 -18
  181. package/translations/zh.json +60 -18
  182. package/translations/zh_CN.json +117 -75
  183. package/dist/1146.js.LICENSE.txt +0 -21
  184. package/dist/2352.js +0 -1
  185. package/dist/2352.js.map +0 -1
  186. package/dist/246.js +0 -1
  187. package/dist/246.js.map +0 -1
  188. package/dist/6525.js +0 -2
  189. package/dist/6525.js.map +0 -1
  190. package/dist/8556.js +0 -2
  191. package/dist/8556.js.map +0 -1
  192. package/dist/8638.js +0 -1
  193. package/dist/8638.js.map +0 -1
  194. package/dist/9968.js +0 -1
  195. package/dist/9968.js.map +0 -1
  196. package/src/billable-services/payyment-modes/payment-modes-config.component.tsx +0 -280
  197. package/src/invoice/payments/payments.component.test.tsx +0 -121
  198. /package/dist/{8556.js.LICENSE.txt → 7452.js.LICENSE.txt} +0 -0
@@ -2,7 +2,7 @@ import React, { useCallback, useState, useEffect } from 'react';
2
2
  import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { TrashCan, Add } from '@carbon/react/icons';
5
- import { Button, Dropdown, NumberInputSkeleton, TextInput, NumberInput } from '@carbon/react';
5
+ import { Button, IconButton, Dropdown, NumberInputSkeleton, TextInput, NumberInput } from '@carbon/react';
6
6
  import { ErrorState } from '@openmrs/esm-patient-common-lib';
7
7
  import { type PaymentFormValue } from '../payments.component';
8
8
  import { usePaymentModes } from '../payment.resource';
@@ -10,26 +10,19 @@ import styles from './payment-form.scss';
10
10
 
11
11
  type PaymentFormProps = {
12
12
  disablePayment: boolean;
13
- clientBalance: number;
14
- isSingleLineItemSelected: boolean;
15
13
  isSingleLineItem: boolean;
16
14
  };
17
15
 
18
- const DEFAULT_PAYMENT = { method: '', amount: 0, referenceCode: '' };
16
+ const DEFAULT_PAYMENT = { method: '', amount: undefined, referenceCode: '' };
19
17
 
20
- const PaymentForm: React.FC<PaymentFormProps> = ({
21
- disablePayment,
22
- clientBalance,
23
- isSingleLineItemSelected,
24
- isSingleLineItem,
25
- }) => {
18
+ const PaymentForm: React.FC<PaymentFormProps> = ({ disablePayment, isSingleLineItem }) => {
26
19
  const { t } = useTranslation();
27
20
  const {
28
21
  control,
29
22
  formState: { errors },
30
23
  } = useFormContext<PaymentFormValue>();
31
24
  const { paymentModes, isLoading, error } = usePaymentModes();
32
- const { fields, remove, append } = useFieldArray({ name: 'payment', control: control });
25
+ const { fields, remove, append } = useFieldArray({ name: 'payment', control });
33
26
  const [isFormVisible, setIsFormVisible] = useState(isSingleLineItem);
34
27
 
35
28
  useEffect(() => {
@@ -45,10 +38,11 @@ const PaymentForm: React.FC<PaymentFormProps> = ({
45
38
  setIsFormVisible(true);
46
39
  append(DEFAULT_PAYMENT);
47
40
  }, [append]);
48
- const handleRemovePaymentMode = useCallback((index) => remove(index), [remove]);
41
+
42
+ const handleRemovePaymentMode = useCallback((index: number) => remove(index), [remove]);
49
43
 
50
44
  if (isLoading) {
51
- return <NumberInputSkeleton data-testid="number-input-skeleton" />;
45
+ return <NumberInputSkeleton />;
52
46
  }
53
47
 
54
48
  if (error) {
@@ -62,8 +56,8 @@ const PaymentForm: React.FC<PaymentFormProps> = ({
62
56
  return (
63
57
  <div className={styles.container}>
64
58
  {isFormVisible &&
65
- fields.map((field, index) => (
66
- <div key={field.id} className={styles.paymentMethodContainer}>
59
+ fields.map((fieldItem, index) => (
60
+ <div key={fieldItem.id} className={styles.paymentMethodContainer}>
67
61
  <Controller
68
62
  control={control}
69
63
  name={`payment.${index}.method`}
@@ -85,13 +79,17 @@ const PaymentForm: React.FC<PaymentFormProps> = ({
85
79
  name={`payment.${index}.amount`}
86
80
  render={({ field }) => (
87
81
  <NumberInput
82
+ allowEmpty
88
83
  id="paymentAmount"
89
- {...field}
90
- onChange={(e) => field.onChange(Number(e.target.value))}
91
84
  invalid={!!errors?.payment?.[index]?.amount}
92
85
  invalidText={errors?.payment?.[index]?.amount?.message}
93
86
  label={t('amount', 'Amount')}
87
+ onChange={(_, { value }) => {
88
+ const numValue = value === '' || value === undefined ? undefined : Number(value);
89
+ field.onChange(numValue);
90
+ }}
94
91
  placeholder={t('enterAmount', 'Enter amount')}
92
+ value={field.value ?? ''}
95
93
  />
96
94
  )}
97
95
  />
@@ -101,31 +99,33 @@ const PaymentForm: React.FC<PaymentFormProps> = ({
101
99
  render={({ field }) => (
102
100
  <TextInput
103
101
  id="paymentReferenceCode"
104
- {...field}
105
102
  labelText={t('referenceNumber', 'Reference number')}
106
- placeholder={t('enterReferenceNumber', 'Enter ref. number')}
103
+ name={field.name}
104
+ onBlur={field.onBlur}
105
+ onChange={field.onChange}
106
+ placeholder={t('enterReferenceNumber', 'Enter reference number')}
107
107
  type="text"
108
+ value={field.value ?? ''}
108
109
  />
109
110
  )}
110
111
  />
111
112
  <div className={styles.removeButtonContainer}>
112
- <TrashCan
113
- onClick={() => handleRemovePaymentMode(index)}
114
- className={styles.removeButton}
115
- size={20}
116
- data-testid="trash-can-icon"
117
- />
113
+ <IconButton
114
+ kind="danger--tertiary"
115
+ label={t('removePaymentMethod', 'Remove payment method')}
116
+ onClick={() => handleRemovePaymentMode(index)}>
117
+ <TrashCan />
118
+ </IconButton>
118
119
  </div>
119
120
  </div>
120
121
  ))}
121
122
  <Button
122
- disabled={disablePayment || (!isSingleLineItem && !isSingleLineItemSelected)}
123
- size="md"
123
+ disabled={disablePayment}
124
124
  onClick={handleAppendPaymentMode}
125
125
  className={styles.paymentButtons}
126
126
  renderIcon={(props) => <Add size={24} {...props} />}
127
- iconDescription="Add">
128
- {t('addPaymentOptions', 'Add payment option')}
127
+ iconDescription={t('add', 'Add')}>
128
+ {t('addPaymentMethod', 'Add payment method')}
129
129
  </Button>
130
130
  </div>
131
131
  );
@@ -3,7 +3,8 @@
3
3
  @use '@carbon/type';
4
4
 
5
5
  .container {
6
- margin: 1rem;
6
+ margin: layout.$spacing-05;
7
+ gap: layout.$spacing-06;
7
8
  }
8
9
 
9
10
  .paymentContainer {
@@ -19,10 +20,10 @@
19
20
 
20
21
  .paymentMethodContainer {
21
22
  display: grid;
22
- grid-template-columns: repeat(4, minmax(auto, 1fr));
23
+ grid-template-columns: 1fr 1fr 1fr auto;
23
24
  align-items: flex-start;
24
- column-gap: 1rem;
25
- margin: 0.625rem 0;
25
+ gap: layout.$spacing-05;
26
+ margin: layout.$spacing-05 0;
26
27
  width: 100%;
27
28
  }
28
29
 
@@ -45,8 +46,6 @@
45
46
  .removeButtonContainer {
46
47
  display: flex;
47
48
  align-self: center;
48
- cursor: pointer;
49
- margin-left: layout.$spacing-07;
50
49
  }
51
50
 
52
51
  .removeButton {
@@ -1,54 +1,50 @@
1
1
  import React from 'react';
2
- import { render, screen, fireEvent, waitFor } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { render, screen, waitFor } from '@testing-library/react';
3
4
  import { FormProvider, useForm } from 'react-hook-form';
4
5
  import type { PaymentFormValue } from '../payments.component';
6
+ import { usePaymentModes } from '../payment.resource';
5
7
  import PaymentForm from './payment-form.component';
6
8
 
7
- // Mock the payment resource
8
9
  jest.mock('../payment.resource', () => ({
9
10
  usePaymentModes: jest.fn(),
10
11
  }));
11
12
 
12
- const { usePaymentModes } = jest.requireMock('../payment.resource');
13
+ const mockUsePaymentModes = jest.mocked(usePaymentModes);
13
14
 
14
15
  type WrapperProps = {
15
16
  children: React.ReactNode;
17
+ defaultValues?: Partial<PaymentFormValue>;
16
18
  };
17
19
 
18
- const Wrapper: React.FC<WrapperProps> = ({ children }) => {
19
- const methods = useForm<PaymentFormValue>();
20
+ const Wrapper: React.FC<WrapperProps> = ({ children, defaultValues }) => {
21
+ const methods = useForm<PaymentFormValue>({
22
+ mode: 'all',
23
+ defaultValues: defaultValues || { payment: [] },
24
+ });
20
25
  return <FormProvider {...methods}>{children}</FormProvider>;
21
26
  };
22
27
 
23
28
  describe('PaymentForm Component', () => {
24
- beforeEach(() => {
25
- jest.clearAllMocks();
26
- });
27
-
28
29
  test('should render skeleton while loading payment modes', () => {
29
- usePaymentModes.mockReturnValue({
30
+ mockUsePaymentModes.mockReturnValue({
30
31
  paymentModes: [],
31
32
  isLoading: true,
32
33
  error: null,
33
34
  mutate: jest.fn(),
34
35
  });
35
36
 
36
- render(
37
+ const { container } = render(
37
38
  <Wrapper>
38
- <PaymentForm
39
- disablePayment={false}
40
- clientBalance={100}
41
- isSingleLineItemSelected={false}
42
- isSingleLineItem={false}
43
- />
39
+ <PaymentForm disablePayment={false} isSingleLineItem={false} />
44
40
  </Wrapper>,
45
41
  );
46
42
 
47
- expect(screen.getByTestId('number-input-skeleton')).toBeInTheDocument();
43
+ expect(container.querySelector('.cds--skeleton')).toBeInTheDocument();
48
44
  });
49
45
 
50
46
  test('should render error message when payment modes fail to load', () => {
51
- usePaymentModes.mockReturnValue({
47
+ mockUsePaymentModes.mockReturnValue({
52
48
  paymentModes: [],
53
49
  isLoading: false,
54
50
  error: new Error('Failed to load payment modes'),
@@ -57,12 +53,7 @@ describe('PaymentForm Component', () => {
57
53
 
58
54
  render(
59
55
  <Wrapper>
60
- <PaymentForm
61
- disablePayment={false}
62
- clientBalance={100}
63
- isSingleLineItemSelected={false}
64
- isSingleLineItem={false}
65
- />
56
+ <PaymentForm disablePayment={false} isSingleLineItem={false} />
66
57
  </Wrapper>,
67
58
  );
68
59
 
@@ -70,8 +61,8 @@ describe('PaymentForm Component', () => {
70
61
  });
71
62
 
72
63
  test('should append default payment when isSingleLineItem is true', () => {
73
- usePaymentModes.mockReturnValue({
74
- paymentModes: [{ uuid: '1', name: 'Credit Card' }],
64
+ mockUsePaymentModes.mockReturnValue({
65
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
75
66
  isLoading: false,
76
67
  error: null,
77
68
  mutate: jest.fn(),
@@ -79,12 +70,7 @@ describe('PaymentForm Component', () => {
79
70
 
80
71
  render(
81
72
  <Wrapper>
82
- <PaymentForm
83
- disablePayment={false}
84
- clientBalance={100}
85
- isSingleLineItemSelected={false}
86
- isSingleLineItem={true}
87
- />
73
+ <PaymentForm disablePayment={false} isSingleLineItem={true} />
88
74
  </Wrapper>,
89
75
  );
90
76
 
@@ -96,9 +82,10 @@ describe('PaymentForm Component', () => {
96
82
  expect(screen.getByPlaceholderText(/enter amount/i)).toBeInTheDocument();
97
83
  });
98
84
 
99
- test('should append a payment field when add payment option button is clicked', () => {
100
- usePaymentModes.mockReturnValue({
101
- paymentModes: [{ uuid: '1', name: 'Credit Card' }],
85
+ test('should append a payment field when add payment method button is clicked', async () => {
86
+ const user = userEvent.setup();
87
+ mockUsePaymentModes.mockReturnValue({
88
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
102
89
  isLoading: false,
103
90
  error: null,
104
91
  mutate: jest.fn(),
@@ -106,24 +93,25 @@ describe('PaymentForm Component', () => {
106
93
 
107
94
  render(
108
95
  <Wrapper>
109
- <PaymentForm
110
- disablePayment={false}
111
- clientBalance={100}
112
- isSingleLineItemSelected={true}
113
- isSingleLineItem={false}
114
- />
96
+ <PaymentForm disablePayment={false} isSingleLineItem={false} />
115
97
  </Wrapper>,
116
98
  );
117
99
 
118
- const addButton = screen.getByText(/add payment option/i);
119
- fireEvent.click(addButton);
120
- const paymentMethodElements = screen.getAllByLabelText(/payment method/i);
121
- expect(paymentMethodElements).toHaveLength(2);
100
+ // Initially no payment fields are shown
101
+ expect(screen.queryByPlaceholderText(/enter amount/i)).not.toBeInTheDocument();
102
+
103
+ const addButton = screen.getByText(/add payment method/i);
104
+ await user.click(addButton);
105
+
106
+ // After clicking, payment fields should be visible
107
+ expect(screen.getByPlaceholderText(/enter amount/i)).toBeInTheDocument();
108
+ expect(screen.getByPlaceholderText(/enter reference number/i)).toBeInTheDocument();
109
+ expect(screen.getByText(/select payment method/i)).toBeInTheDocument();
122
110
  });
123
111
 
124
112
  test('should disable add payment button when disablePayment is true', () => {
125
- usePaymentModes.mockReturnValue({
126
- paymentModes: [{ uuid: '1', name: 'Credit Card' }],
113
+ mockUsePaymentModes.mockReturnValue({
114
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
127
115
  isLoading: false,
128
116
  error: null,
129
117
  mutate: jest.fn(),
@@ -131,21 +119,17 @@ describe('PaymentForm Component', () => {
131
119
 
132
120
  render(
133
121
  <Wrapper>
134
- <PaymentForm
135
- disablePayment={true}
136
- clientBalance={100}
137
- isSingleLineItemSelected={true}
138
- isSingleLineItem={false}
139
- />
122
+ <PaymentForm disablePayment={true} isSingleLineItem={false} />
140
123
  </Wrapper>,
141
124
  );
142
125
 
143
- expect(screen.getByText(/add payment option/i)).toBeDisabled();
126
+ expect(screen.getByText(/add payment method/i)).toBeDisabled();
144
127
  });
145
128
 
146
- test('should remove payment field when trash can icon is clicked', async () => {
147
- usePaymentModes.mockReturnValue({
148
- paymentModes: [{ uuid: '1', name: 'Credit Card' }],
129
+ test('should remove payment field when remove button is clicked', async () => {
130
+ const user = userEvent.setup();
131
+ mockUsePaymentModes.mockReturnValue({
132
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
149
133
  isLoading: false,
150
134
  error: null,
151
135
  mutate: jest.fn(),
@@ -153,22 +137,186 @@ describe('PaymentForm Component', () => {
153
137
 
154
138
  render(
155
139
  <Wrapper>
156
- <PaymentForm
157
- disablePayment={false}
158
- clientBalance={100}
159
- isSingleLineItemSelected={true}
160
- isSingleLineItem={false}
161
- />
140
+ <PaymentForm disablePayment={false} isSingleLineItem={false} />
162
141
  </Wrapper>,
163
142
  );
164
143
 
165
- fireEvent.click(screen.getByText(/add payment option/i));
144
+ await user.click(screen.getByText(/add payment method/i));
166
145
 
167
- const trashCanIcon = screen.getByTestId('trash-can-icon');
168
- fireEvent.click(trashCanIcon);
146
+ const removeButton = screen.getByRole('button', { name: /remove payment method/i });
147
+ await user.click(removeButton);
169
148
 
170
149
  await waitFor(() => {
171
150
  expect(screen.queryByPlaceholderText(/enter amount/i)).not.toBeInTheDocument();
172
151
  });
173
152
  });
153
+
154
+ test('should render amount input without leading zero', () => {
155
+ mockUsePaymentModes.mockReturnValue({
156
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
157
+ isLoading: false,
158
+ error: null,
159
+ mutate: jest.fn(),
160
+ });
161
+
162
+ render(
163
+ <Wrapper>
164
+ <PaymentForm disablePayment={false} isSingleLineItem={true} />
165
+ </Wrapper>,
166
+ );
167
+
168
+ const amountInput = screen.getByPlaceholderText(/enter amount/i) as HTMLInputElement;
169
+ expect(amountInput.value).toBe('');
170
+ });
171
+
172
+ test('should allow user to clear amount input without reverting to zero', async () => {
173
+ const user = userEvent.setup();
174
+ mockUsePaymentModes.mockReturnValue({
175
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
176
+ isLoading: false,
177
+ error: null,
178
+ mutate: jest.fn(),
179
+ });
180
+
181
+ render(
182
+ <Wrapper>
183
+ <PaymentForm disablePayment={false} isSingleLineItem={true} />
184
+ </Wrapper>,
185
+ );
186
+
187
+ const amountInput = screen.getByPlaceholderText(/enter amount/i) as HTMLInputElement;
188
+
189
+ await user.type(amountInput, '100');
190
+ expect(amountInput.value).toBe('100');
191
+
192
+ await user.clear(amountInput);
193
+ expect(amountInput.value).toBe('');
194
+ });
195
+
196
+ test('should handle amount input with decimal values', async () => {
197
+ const user = userEvent.setup();
198
+ mockUsePaymentModes.mockReturnValue({
199
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
200
+ isLoading: false,
201
+ error: null,
202
+ mutate: jest.fn(),
203
+ });
204
+
205
+ render(
206
+ <Wrapper>
207
+ <PaymentForm disablePayment={false} isSingleLineItem={true} />
208
+ </Wrapper>,
209
+ );
210
+
211
+ const amountInput = screen.getByPlaceholderText(/enter amount/i) as HTMLInputElement;
212
+
213
+ await user.type(amountInput, '10.50');
214
+ expect(amountInput.value).toBe('10.5');
215
+ });
216
+
217
+ test('should not auto-focus reference number input on mount', () => {
218
+ mockUsePaymentModes.mockReturnValue({
219
+ paymentModes: [{ uuid: '1', name: 'Credit Card', description: 'Credit Card', retired: false }],
220
+ isLoading: false,
221
+ error: null,
222
+ mutate: jest.fn(),
223
+ });
224
+
225
+ render(
226
+ <Wrapper>
227
+ <PaymentForm disablePayment={false} isSingleLineItem={true} />
228
+ </Wrapper>,
229
+ );
230
+
231
+ const referenceInput = screen.getByPlaceholderText(/enter reference number/i);
232
+ expect(referenceInput).not.toHaveFocus();
233
+ });
234
+
235
+ test('should allow adding multiple payment methods', async () => {
236
+ const user = userEvent.setup();
237
+ mockUsePaymentModes.mockReturnValue({
238
+ paymentModes: [
239
+ { uuid: '1', name: 'Cash', description: 'Cash', retired: false },
240
+ { uuid: '2', name: 'Credit Card', description: 'Credit Card', retired: false },
241
+ ],
242
+ isLoading: false,
243
+ error: null,
244
+ mutate: jest.fn(),
245
+ });
246
+
247
+ render(
248
+ <Wrapper>
249
+ <PaymentForm disablePayment={false} isSingleLineItem={false} />
250
+ </Wrapper>,
251
+ );
252
+
253
+ const addButton = screen.getByText(/add payment method/i);
254
+
255
+ await user.click(addButton);
256
+ await user.click(addButton);
257
+
258
+ const amountInputs = screen.getAllByPlaceholderText(/enter amount/i);
259
+ expect(amountInputs).toHaveLength(2);
260
+ });
261
+
262
+ test('should preserve entered values when adding new payment method', async () => {
263
+ const user = userEvent.setup();
264
+ mockUsePaymentModes.mockReturnValue({
265
+ paymentModes: [{ uuid: '1', name: 'Cash', description: 'Cash', retired: false }],
266
+ isLoading: false,
267
+ error: null,
268
+ mutate: jest.fn(),
269
+ });
270
+
271
+ render(
272
+ <Wrapper>
273
+ <PaymentForm disablePayment={false} isSingleLineItem={false} />
274
+ </Wrapper>,
275
+ );
276
+
277
+ const addButton = screen.getByText(/add payment method/i);
278
+ await user.click(addButton);
279
+
280
+ const firstAmountInput = screen.getByPlaceholderText(/enter amount/i) as HTMLInputElement;
281
+ await user.type(firstAmountInput, '50');
282
+
283
+ await user.click(addButton);
284
+
285
+ const amountInputs = screen.getAllByPlaceholderText(/enter amount/i) as HTMLInputElement[];
286
+ expect(amountInputs[0].value).toBe('50');
287
+ expect(amountInputs[1].value).toBe('');
288
+ });
289
+
290
+ test('should handle removing payment method without affecting other fields', async () => {
291
+ const user = userEvent.setup();
292
+ mockUsePaymentModes.mockReturnValue({
293
+ paymentModes: [{ uuid: '1', name: 'Cash', description: 'Cash', retired: false }],
294
+ isLoading: false,
295
+ error: null,
296
+ mutate: jest.fn(),
297
+ });
298
+
299
+ render(
300
+ <Wrapper>
301
+ <PaymentForm disablePayment={false} isSingleLineItem={false} />
302
+ </Wrapper>,
303
+ );
304
+
305
+ const addButton = screen.getByText(/add payment method/i);
306
+ await user.click(addButton);
307
+ await user.click(addButton);
308
+
309
+ const amountInputs = screen.getAllByPlaceholderText(/enter amount/i) as HTMLInputElement[];
310
+ await user.type(amountInputs[0], '50');
311
+ await user.type(amountInputs[1], '75');
312
+
313
+ const removeButtons = screen.getAllByRole('button', { name: /remove payment method/i });
314
+ await user.click(removeButtons[0]);
315
+
316
+ await waitFor(() => {
317
+ const remainingInputs = screen.getAllByPlaceholderText(/enter amount/i) as HTMLInputElement[];
318
+ expect(remainingInputs).toHaveLength(1);
319
+ expect(remainingInputs[0].value).toBe('75');
320
+ });
321
+ });
174
322
  });
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { DataTable, Table, TableHead, TableRow, TableHeader, TableBody, TableCell } from '@carbon/react';
3
+ import { useTranslation } from 'react-i18next';
3
4
  import { type MappedBill } from '../../../types';
4
5
  import { formatDate, useConfig } from '@openmrs/esm-framework';
5
6
  import { convertToCurrency } from '../../../helpers';
@@ -9,23 +10,24 @@ type PaymentHistoryProps = {
9
10
  };
10
11
 
11
12
  const PaymentHistory: React.FC<PaymentHistoryProps> = ({ bill }) => {
13
+ const { t } = useTranslation();
12
14
  const { defaultCurrency } = useConfig();
13
15
  const headers = [
14
16
  {
15
17
  key: 'dateCreated',
16
- header: 'Date of payment',
18
+ header: t('dateOfPayment', 'Date of payment'),
17
19
  },
18
20
  {
19
21
  key: 'amount',
20
- header: 'Bill amount',
22
+ header: t('billAmount', 'Bill amount'),
21
23
  },
22
24
  {
23
25
  key: 'amountTendered',
24
- header: 'Amount tendered',
26
+ header: t('amountTendered', 'Amount tendered'),
25
27
  },
26
28
  {
27
29
  key: 'paymentMethod',
28
- header: 'Payment method',
30
+ header: t('paymentMethod', 'Payment method'),
29
31
  },
30
32
  ];
31
33
  const rows = bill?.payments?.map((payment, index) => {
@@ -1,24 +1,19 @@
1
1
  import React from 'react';
2
2
  import { render, screen } from '@testing-library/react';
3
- import { useConfig } from '@openmrs/esm-framework';
4
- import PaymentHistory from './payment-history.component';
3
+ import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
4
+ import { type BillingConfig, configSchema } from '../../../config-schema';
5
5
  import { type MappedBill } from '../../../types';
6
-
7
- // Mocking useConfig to return a default currency
8
- jest.mock('@openmrs/esm-framework', () => ({
9
- useConfig: jest.fn(),
10
- formatDate: jest.fn((date) => date.toISOString().split('T')[0]),
11
- }));
6
+ import PaymentHistory from './payment-history.component';
12
7
 
13
8
  jest.mock('../../../helpers', () => ({
14
9
  convertToCurrency: jest.fn((amount, currency) => `${currency} ${amount.toFixed(2)}`),
15
10
  }));
16
11
 
12
+ const mockUseConfig = jest.mocked(useConfig<BillingConfig>);
13
+
17
14
  describe('PaymentHistory Component', () => {
18
15
  beforeEach(() => {
19
- (useConfig as jest.Mock).mockReturnValue({
20
- defaultCurrency: 'USD',
21
- });
16
+ mockUseConfig.mockReturnValue({ ...getDefaultsFromConfigSchema(configSchema), defaultCurrency: 'USD' });
22
17
  });
23
18
 
24
19
  const mockBill: MappedBill = {
@@ -129,12 +124,12 @@ describe('PaymentHistory Component', () => {
129
124
  test('renders correct data in the rows', () => {
130
125
  render(<PaymentHistory bill={mockBill} />);
131
126
 
132
- expect(screen.getByText('2023-09-01')).toBeInTheDocument();
127
+ expect(screen.getByText('01-Sept-2023')).toBeInTheDocument();
133
128
  expect(screen.getByText('USD 80.00')).toBeInTheDocument();
134
129
  expect(screen.getByText('USD 100.00')).toBeInTheDocument();
135
130
  expect(screen.getByText('Credit Card')).toBeInTheDocument();
136
131
 
137
- expect(screen.getByText('2023-09-05')).toBeInTheDocument();
132
+ expect(screen.getByText('05-Sept-2023')).toBeInTheDocument();
138
133
  expect(screen.getByText('USD 180.00')).toBeInTheDocument();
139
134
  expect(screen.getByText('USD 200.00')).toBeInTheDocument();
140
135
  expect(screen.getByText('Cash')).toBeInTheDocument();
@@ -153,7 +148,7 @@ describe('PaymentHistory Component', () => {
153
148
  test('formats dates and converts amounts correctly', () => {
154
149
  render(<PaymentHistory bill={mockBill} />);
155
150
 
156
- expect(screen.getByText('2023-09-01')).toBeInTheDocument();
151
+ expect(screen.getByText('01-Sept-2023')).toBeInTheDocument();
157
152
  expect(screen.getByText('USD 80.00')).toBeInTheDocument();
158
153
  expect(screen.getByText('USD 100.00')).toBeInTheDocument();
159
154
  });