@openmrs/esm-billing-app 1.1.2-pre.8 → 1.2.0
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/.turbo/cache/31f1dfc7f71601df-meta.json +1 -0
- package/.turbo/cache/31f1dfc7f71601df.tar.zst +0 -0
- package/.turbo/turbo-build.log +13 -42
- package/__mocks__/bills.mock.ts +3 -2
- package/dist/1480.js +1 -0
- package/dist/1480.js.map +1 -0
- package/dist/1564.js +1 -0
- package/dist/1564.js.map +1 -0
- package/dist/1578.js +1 -0
- package/dist/1578.js.map +1 -0
- package/dist/1646.js +1 -0
- package/dist/1646.js.map +1 -0
- package/dist/1869.js +1 -0
- package/dist/1869.js.map +1 -0
- package/dist/1877.js +1 -0
- package/dist/1877.js.map +1 -0
- package/dist/1899.js +1 -0
- package/dist/1899.js.map +1 -0
- package/dist/196.js +2 -0
- package/dist/196.js.map +1 -0
- package/dist/2250.js +43 -0
- package/dist/2250.js.map +1 -0
- package/dist/2269.js +1 -0
- package/dist/2269.js.map +1 -0
- package/dist/2317.js +1 -0
- package/dist/2317.js.map +1 -0
- package/dist/2416.js +1 -0
- package/dist/2416.js.map +1 -0
- package/dist/2489.js +1 -0
- package/dist/2489.js.map +1 -0
- package/dist/282.js +1 -0
- package/dist/282.js.map +1 -0
- package/dist/2881.js +1 -0
- package/dist/2881.js.map +1 -0
- package/dist/2997.js +1 -0
- package/dist/2997.js.map +1 -0
- package/dist/3378.js +1 -0
- package/dist/3378.js.map +1 -0
- package/dist/3379.js +1 -0
- package/dist/3379.js.map +1 -0
- package/dist/3784.js +1 -0
- package/dist/3784.js.map +1 -0
- package/dist/3963.js +1 -0
- package/dist/3963.js.map +1 -0
- package/dist/4106.js +1 -0
- package/dist/4106.js.map +1 -0
- package/dist/4111.js +1 -0
- package/dist/4111.js.map +1 -0
- package/dist/434.js +1 -0
- package/dist/434.js.map +1 -0
- package/dist/4348.js +1 -0
- package/dist/4348.js.map +1 -0
- package/dist/4383.js +1 -0
- package/dist/4383.js.map +1 -0
- package/dist/4658.js +1 -0
- package/dist/4658.js.map +1 -0
- package/dist/4870.js +1 -0
- package/dist/4870.js.map +1 -0
- package/dist/4928.js +1 -0
- package/dist/4928.js.map +1 -0
- package/dist/5098.js +1 -0
- package/dist/5098.js.map +1 -0
- package/dist/5117.js +1 -0
- package/dist/5117.js.map +1 -0
- package/dist/5132.js +1 -0
- package/dist/5132.js.map +1 -0
- package/dist/5145.js +1 -0
- package/dist/5145.js.map +1 -0
- package/dist/5390.js +1 -0
- package/dist/5390.js.map +1 -0
- package/dist/5503.js +1 -0
- package/dist/5503.js.map +1 -0
- package/dist/556.js +1 -0
- package/dist/556.js.map +1 -0
- package/dist/5644.js +1 -0
- package/dist/5644.js.map +1 -0
- package/dist/5898.js +1 -0
- package/dist/5898.js.map +1 -0
- package/dist/5940.js +1 -0
- package/dist/5940.js.map +1 -0
- package/dist/6047.js +1 -0
- package/dist/6047.js.map +1 -0
- package/dist/6237.js +1 -0
- package/dist/6237.js.map +1 -0
- package/dist/6362.js +1 -0
- package/dist/6362.js.map +1 -0
- package/dist/6371.js +1 -0
- package/dist/6371.js.map +1 -0
- package/dist/6377.js +1 -0
- package/dist/6377.js.map +1 -0
- package/dist/6444.js +1 -0
- package/dist/6444.js.map +1 -0
- package/dist/6508.js +1 -0
- package/dist/6508.js.map +1 -0
- package/dist/6594.js +1 -0
- package/dist/6594.js.map +1 -0
- package/dist/6724.js +1 -0
- package/dist/6724.js.map +1 -0
- package/dist/6904.js +1 -0
- package/dist/6904.js.map +1 -0
- package/dist/7045.js +1 -0
- package/dist/7045.js.map +1 -0
- package/dist/7175.js +1 -0
- package/dist/7175.js.map +1 -0
- package/dist/7182.js +1 -0
- package/dist/7182.js.map +1 -0
- package/dist/7247.js +1 -0
- package/dist/7247.js.map +1 -0
- package/dist/7742.js +1 -0
- package/dist/7742.js.map +1 -0
- package/dist/7912.js +1 -0
- package/dist/7912.js.map +1 -0
- package/dist/8358.js +1 -0
- package/dist/8358.js.map +1 -0
- package/dist/8359.js +1 -0
- package/dist/8359.js.map +1 -0
- package/dist/8695.js +1 -0
- package/dist/8695.js.map +1 -0
- package/dist/903.js +1 -0
- package/dist/903.js.map +1 -0
- package/dist/9072.js +1 -0
- package/dist/9072.js.map +1 -0
- package/dist/9414.js +1 -0
- package/dist/9414.js.map +1 -0
- package/dist/9655.js +11 -0
- package/dist/9655.js.map +1 -0
- package/dist/9806.js +1 -0
- package/dist/9806.js.map +1 -0
- package/dist/990.js +1 -0
- package/dist/990.js.map +1 -0
- package/dist/main.js +17 -2
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-billing-app.js +6 -1
- package/dist/openmrs-esm-billing-app.js.buildmanifest.json +643 -436
- package/dist/openmrs-esm-billing-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/e2e/commands/billing-operations.ts +21 -0
- package/e2e/commands/types.ts +9 -1
- package/e2e/pages/discounts-page.ts +75 -0
- package/e2e/pages/index.ts +1 -0
- package/e2e/pages/invoice-page.ts +7 -7
- package/e2e/specs/bill-discounts.spec.ts +255 -0
- package/e2e/specs/billing-dashboard.spec.ts +3 -3
- package/e2e/specs/billing-patient-chart.spec.ts +2 -2
- package/package.json +13 -22
- package/rspack.config.js +1 -0
- package/src/bill-history/bill-action-menu.component.tsx +20 -2
- package/src/bill-history/bill-history.test.tsx +23 -22
- package/src/bill-item-actions/edit-bill-item.modal.tsx +1 -1
- package/src/bill-item-actions/edit-bill-item.test.tsx +29 -27
- package/src/billable-services/billable-service-form/billable-service-form.test.tsx +74 -73
- package/src/billable-services/billable-services-home.component.tsx +4 -2
- package/src/billable-services/billable-services.test.tsx +8 -7
- package/src/billable-services/dashboard/dashboard.test.tsx +3 -2
- package/src/billable-services-admin-card-link.test.tsx +2 -1
- package/src/billing-dashboard/billing-dashboard.test.tsx +19 -3
- package/src/billing-form/billing-checkin-form.component.tsx +7 -3
- package/src/billing-form/billing-checkin-form.test.tsx +22 -21
- package/src/billing-form/billing-form.resource.test.ts +7 -6
- package/src/billing-form/billing-form.test.tsx +77 -40
- package/src/billing-form/billing-form.workspace.tsx +25 -6
- package/src/billing-form/visit-attributes/visit-attributes-form.component.tsx +6 -2
- package/src/billing.resource.test.ts +43 -41
- package/src/billing.resource.ts +65 -16
- package/src/bills-table/bills-table.component.tsx +15 -4
- package/src/bills-table/bills-table.test.tsx +72 -71
- package/src/config-schema.ts +0 -7
- package/src/discounts/admin/discount-requests-left-panel-link.component.tsx +43 -0
- package/src/discounts/admin/discount-requests.component.tsx +316 -0
- package/src/discounts/admin/discount-requests.scss +133 -0
- package/src/discounts/admin/discount-requests.test.tsx +104 -0
- package/src/discounts/admin/review-bill-discounts/bill-line-items-table/bill-line-items-table.component.tsx +42 -0
- package/src/discounts/admin/review-bill-discounts/bill-line-items-table/bill-line-items-table.scss +76 -0
- package/src/discounts/admin/review-bill-discounts/bill-payments-table/bill-payments-table.component.tsx +50 -0
- package/src/discounts/admin/review-bill-discounts/bill-payments-table/bill-payments-table.scss +63 -0
- package/src/discounts/admin/review-bill-discounts/bill-receipt-rail/bill-receipt-rail.component.tsx +73 -0
- package/src/discounts/admin/review-bill-discounts/bill-receipt-rail/bill-receipt-rail.scss +54 -0
- package/src/discounts/admin/review-bill-discounts/bill-totals-summary/bill-totals-summary.component.tsx +95 -0
- package/src/discounts/admin/review-bill-discounts/bill-totals-summary/bill-totals-summary.scss +128 -0
- package/src/discounts/admin/review-bill-discounts/discount-card/discount-card.component.tsx +158 -0
- package/src/discounts/admin/review-bill-discounts/discount-card/discount-card.scss +164 -0
- package/src/discounts/admin/review-bill-discounts/discount-review-stack/discount-review-stack.component.tsx +86 -0
- package/src/discounts/admin/review-bill-discounts/discount-review-stack/discount-review-stack.scss +40 -0
- package/src/discounts/admin/review-bill-discounts/review-bill-discounts.modal.scss +14 -0
- package/src/discounts/admin/review-bill-discounts/review-bill-discounts.modal.test.tsx +153 -0
- package/src/discounts/admin/review-bill-discounts/review-bill-discounts.modal.tsx +167 -0
- package/src/discounts/admin/review-bill-discounts/review-bill-discounts.utils.ts +42 -0
- package/src/discounts/discounts-table.component.tsx +109 -0
- package/src/discounts/discounts-table.scss +37 -0
- package/src/discounts/discounts-table.test.tsx +67 -0
- package/src/discounts/discounts.resource.ts +71 -0
- package/src/discounts/request-discount.modal.scss +88 -0
- package/src/discounts/request-discount.modal.test.tsx +161 -0
- package/src/discounts/request-discount.modal.tsx +253 -0
- package/src/index.ts +52 -21
- package/src/invoice/invoice-table.component.tsx +116 -18
- package/src/invoice/invoice-table.test.tsx +165 -13
- package/src/invoice/invoice.component.tsx +111 -7
- package/src/invoice/invoice.test.tsx +366 -66
- package/src/invoice/line-item-action-menu.component.tsx +31 -1
- package/src/invoice/payments/payment-form/payment-form.test.tsx +20 -19
- package/src/invoice/payments/payment-history/payment-history.test.tsx +13 -10
- package/src/invoice/payments/payments.component.tsx +20 -6
- package/src/invoice/payments/payments.test.tsx +88 -23
- package/src/invoice/printable-invoice/print-receipt.test.tsx +10 -28
- package/src/invoice/printable-invoice/printable-footer.test.tsx +5 -4
- package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +3 -3
- package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +26 -11
- package/src/invoice/printable-invoice/printable-invoice.component.tsx +38 -15
- package/src/left-panel-link.test.tsx +3 -3
- package/src/metrics-cards/metrics-cards.test.tsx +11 -10
- package/src/modal/delete-bill-confirmation.modal.test.tsx +134 -0
- package/src/modal/delete-bill-confirmation.modal.tsx +98 -0
- package/src/modal/delete-line-item-confirmation.modal.test.tsx +11 -9
- package/src/modal/finalize-bill-confirmation.modal.test.tsx +10 -8
- package/src/modal/require-payment-modal.test.tsx +12 -11
- package/src/payment-status-tag/payment-status-tag.component.tsx +50 -0
- package/src/payment-status-tag/payment-status-tag.scss +6 -0
- package/src/payment-status-tag/payment-status-tag.test.tsx +113 -0
- package/src/refunds/admin/refund-requests-left-panel-link.component.tsx +43 -0
- package/src/refunds/admin/refund-requests.component.tsx +324 -0
- package/src/refunds/admin/refund-requests.scss +133 -0
- package/src/refunds/admin/refund-requests.test.tsx +99 -0
- package/src/refunds/admin/review-bill-refunds/bill-line-items-table/bill-line-items-table.component.tsx +42 -0
- package/src/refunds/admin/review-bill-refunds/bill-line-items-table/bill-line-items-table.scss +76 -0
- package/src/refunds/admin/review-bill-refunds/bill-payments-table/bill-payments-table.component.tsx +50 -0
- package/src/refunds/admin/review-bill-refunds/bill-payments-table/bill-payments-table.scss +63 -0
- package/src/refunds/admin/review-bill-refunds/bill-receipt-rail/bill-receipt-rail.component.tsx +84 -0
- package/src/refunds/admin/review-bill-refunds/bill-receipt-rail/bill-receipt-rail.scss +54 -0
- package/src/refunds/admin/review-bill-refunds/bill-totals-summary/bill-totals-summary.component.tsx +83 -0
- package/src/refunds/admin/review-bill-refunds/bill-totals-summary/bill-totals-summary.scss +65 -0
- package/src/refunds/admin/review-bill-refunds/refund-card/refund-card.component.tsx +170 -0
- package/src/refunds/admin/review-bill-refunds/refund-card/refund-card.scss +155 -0
- package/src/refunds/admin/review-bill-refunds/refund-review-stack/refund-review-stack.component.tsx +86 -0
- package/src/refunds/admin/review-bill-refunds/refund-review-stack/refund-review-stack.scss +40 -0
- package/src/refunds/admin/review-bill-refunds/review-bill-refunds.modal.scss +14 -0
- package/src/refunds/admin/review-bill-refunds/review-bill-refunds.modal.test.tsx +313 -0
- package/src/refunds/admin/review-bill-refunds/review-bill-refunds.modal.tsx +188 -0
- package/src/refunds/admin/review-bill-refunds/review-bill-refunds.utils.ts +66 -0
- package/src/refunds/refunds-table.component.tsx +137 -0
- package/src/refunds/refunds-table.scss +37 -0
- package/src/refunds/refunds-table.test.tsx +105 -0
- package/src/refunds/refunds.resource.test.ts +44 -0
- package/src/refunds/refunds.resource.ts +42 -0
- package/src/refunds/refunds.types.test.ts +15 -0
- package/src/refunds/request-refund.modal.scss +84 -0
- package/src/refunds/request-refund.modal.test.tsx +204 -0
- package/src/refunds/request-refund.modal.tsx +218 -0
- package/src/routes.json +36 -2
- package/src/types/index.ts +116 -1
- package/src/visit-bills/visit-bills-panel.component.tsx +151 -0
- package/src/visit-bills/visit-bills-panel.scss +31 -0
- package/src/visit-bills/visit-bills-panel.test.tsx +113 -0
- package/tools/empty-module.ts +1 -0
- package/tools/setup-tests.ts +9 -9
- package/translations/am.json +154 -16
- package/translations/ar.json +154 -16
- package/translations/ar_SY.json +154 -16
- package/translations/bn.json +154 -16
- package/translations/cs.json +154 -16
- package/translations/de.json +154 -16
- package/translations/en.json +154 -16
- package/translations/en_US.json +154 -16
- package/translations/es.json +154 -16
- package/translations/es_MX.json +154 -16
- package/translations/fr.json +154 -16
- package/translations/he.json +154 -16
- package/translations/hi.json +154 -16
- package/translations/hi_IN.json +154 -16
- package/translations/id.json +154 -16
- package/translations/it.json +154 -16
- package/translations/ka.json +154 -16
- package/translations/km.json +154 -16
- package/translations/ku.json +154 -16
- package/translations/ky.json +154 -16
- package/translations/lg.json +154 -16
- package/translations/ne.json +154 -16
- package/translations/pl.json +154 -16
- package/translations/pt.json +154 -16
- package/translations/pt_BR.json +154 -16
- package/translations/qu.json +154 -16
- package/translations/ro_RO.json +154 -16
- package/translations/ru_RU.json +154 -16
- package/translations/si.json +154 -16
- package/translations/sq.json +154 -16
- package/translations/sw.json +154 -16
- package/translations/sw_KE.json +154 -16
- package/translations/tr.json +154 -16
- package/translations/tr_TR.json +154 -16
- package/translations/uk.json +154 -16
- package/translations/uz.json +154 -16
- package/translations/uz@Latn.json +154 -16
- package/translations/uz_UZ.json +154 -16
- package/translations/vi.json +154 -16
- package/translations/zh.json +154 -16
- package/translations/zh_CN.json +179 -41
- package/translations/zh_TW.json +154 -16
- package/tsconfig.json +3 -3
- package/vitest.config.js +28 -0
- package/.turbo/cache/6c998b0f30a031ab-meta.json +0 -1
- package/.turbo/cache/6c998b0f30a031ab.tar.zst +0 -0
- package/dist/1119.js +0 -1
- package/dist/1197.js +0 -1
- package/dist/1435.js +0 -1
- package/dist/1435.js.map +0 -1
- package/dist/1807.js +0 -1
- package/dist/1807.js.map +0 -1
- package/dist/2146.js +0 -1
- package/dist/2177.js +0 -2
- package/dist/2177.js.LICENSE.txt +0 -9
- package/dist/2177.js.map +0 -1
- package/dist/2690.js +0 -1
- package/dist/2704.js +0 -1
- package/dist/2704.js.map +0 -1
- package/dist/3002.js +0 -1
- package/dist/3002.js.map +0 -1
- package/dist/3041.js +0 -1
- package/dist/3041.js.map +0 -1
- package/dist/3099.js +0 -1
- package/dist/3184.js +0 -2
- package/dist/3184.js.LICENSE.txt +0 -14
- package/dist/3184.js.map +0 -1
- package/dist/3584.js +0 -1
- package/dist/4055.js +0 -1
- package/dist/4132.js +0 -1
- package/dist/4225.js +0 -1
- package/dist/4225.js.map +0 -1
- package/dist/4300.js +0 -1
- package/dist/4335.js +0 -1
- package/dist/439.js +0 -1
- package/dist/4618.js +0 -1
- package/dist/4652.js +0 -1
- package/dist/4944.js +0 -1
- package/dist/5173.js +0 -1
- package/dist/5241.js +0 -1
- package/dist/5422.js +0 -1
- package/dist/5422.js.map +0 -1
- package/dist/5442.js +0 -1
- package/dist/5661.js +0 -1
- package/dist/6022.js +0 -1
- package/dist/6404.js +0 -1
- package/dist/6404.js.map +0 -1
- package/dist/6468.js +0 -1
- package/dist/6540.js +0 -2
- package/dist/6540.js.LICENSE.txt +0 -9
- package/dist/6540.js.map +0 -1
- package/dist/6589.js +0 -1
- package/dist/6606.js +0 -1
- package/dist/6606.js.map +0 -1
- package/dist/6679.js +0 -1
- package/dist/6792.js +0 -1
- package/dist/6792.js.map +0 -1
- package/dist/6840.js +0 -1
- package/dist/6859.js +0 -1
- package/dist/7097.js +0 -1
- package/dist/7159.js +0 -1
- package/dist/723.js +0 -1
- package/dist/7255.js +0 -1
- package/dist/7255.js.map +0 -1
- package/dist/7617.js +0 -1
- package/dist/795.js +0 -1
- package/dist/8163.js +0 -1
- package/dist/8341.js +0 -2
- package/dist/8341.js.LICENSE.txt +0 -52
- package/dist/8341.js.map +0 -1
- package/dist/8349.js +0 -1
- package/dist/8371.js +0 -1
- package/dist/8421.js +0 -1
- package/dist/8421.js.map +0 -1
- package/dist/8618.js +0 -1
- package/dist/890.js +0 -1
- package/dist/9214.js +0 -1
- package/dist/9538.js +0 -1
- package/dist/9569.js +0 -1
- package/dist/961.js +0 -2
- package/dist/961.js.LICENSE.txt +0 -19
- package/dist/961.js.map +0 -1
- package/dist/986.js +0 -1
- package/dist/9879.js +0 -1
- package/dist/9895.js +0 -1
- package/dist/9900.js +0 -1
- package/dist/9913.js +0 -1
- package/dist/main.js.LICENSE.txt +0 -62
- package/src/billable-services/bill-waiver/bill-selection.component.tsx +0 -76
- package/src/billable-services/bill-waiver/bill-waiver-form.component.tsx +0 -107
- package/src/billable-services/bill-waiver/bill-waiver-form.scss +0 -34
- package/src/billable-services/bill-waiver/bill-waiver.component.tsx +0 -34
- package/src/billable-services/bill-waiver/bill-waiver.scss +0 -10
- package/src/billable-services/bill-waiver/patient-bills.component.tsx +0 -134
- package/webpack.config.js +0 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import {
|
|
5
|
+
DataTable,
|
|
6
|
+
Table,
|
|
7
|
+
TableBody,
|
|
8
|
+
TableCell,
|
|
9
|
+
TableContainer,
|
|
10
|
+
TableHead,
|
|
11
|
+
TableHeader,
|
|
12
|
+
TableRow,
|
|
13
|
+
} from '@carbon/react';
|
|
14
|
+
import { isDesktop, useConfig, useLayoutType } from '@openmrs/esm-framework';
|
|
15
|
+
import type { BillingConfig } from '../config-schema';
|
|
16
|
+
import { convertToCurrency } from '../helpers';
|
|
17
|
+
import { BillDiscountType, type BillDiscount, type MappedBill } from '../types';
|
|
18
|
+
import styles from './discounts-table.scss';
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
bill: MappedBill;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function resolveScope(d: BillDiscount, bill: MappedBill, fallback: string) {
|
|
25
|
+
if (!d.lineItemUuid) return fallback;
|
|
26
|
+
const li = bill.lineItems?.find((l) => l.uuid === d.lineItemUuid);
|
|
27
|
+
return li?.item || li?.billableService || fallback;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DiscountsTable: React.FC<Props> = ({ bill }) => {
|
|
31
|
+
const { t } = useTranslation();
|
|
32
|
+
const { defaultCurrency } = useConfig<BillingConfig>();
|
|
33
|
+
const layout = useLayoutType();
|
|
34
|
+
const responsiveSize = isDesktop(layout) ? 'sm' : 'lg';
|
|
35
|
+
const discounts = useMemo(() => (bill.discounts ?? []).filter((d) => !d.voided), [bill.discounts]);
|
|
36
|
+
|
|
37
|
+
const tableHeaders = [
|
|
38
|
+
{ header: t('discountItem', 'Item'), key: 'item', width: 25 },
|
|
39
|
+
{ header: t('discountType', 'Type'), key: 'type', width: 15 },
|
|
40
|
+
{ header: t('discountAmount', 'Amount'), key: 'amount', width: 15 },
|
|
41
|
+
{ header: t('justification', 'Justification'), key: 'justification', width: 30 },
|
|
42
|
+
{ header: t('status', 'Status'), key: 'status', width: 15 },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const tableRows = useMemo(
|
|
46
|
+
() =>
|
|
47
|
+
(discounts ?? []).map((d) => ({
|
|
48
|
+
id: d.uuid,
|
|
49
|
+
item: resolveScope(d, bill, t('wholeBill', 'Whole bill')),
|
|
50
|
+
type:
|
|
51
|
+
d.discountType === BillDiscountType.PERCENTAGE
|
|
52
|
+
? t('percentage', 'Percentage')
|
|
53
|
+
: t('fixedAmount', 'Fixed amount'),
|
|
54
|
+
amount: convertToCurrency(d.discountAmount, defaultCurrency),
|
|
55
|
+
justification: d.justification,
|
|
56
|
+
status: t(d.status.toLowerCase(), d.status),
|
|
57
|
+
})),
|
|
58
|
+
[discounts, bill, defaultCurrency, t],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (!discounts || discounts.length === 0) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className={styles.discountsWrapper}>
|
|
67
|
+
<DataTable
|
|
68
|
+
headers={tableHeaders}
|
|
69
|
+
rows={tableRows}
|
|
70
|
+
size={responsiveSize}
|
|
71
|
+
useZebraStyles
|
|
72
|
+
overflowMenuOnHover={isDesktop(layout)}>
|
|
73
|
+
{({ rows, headers, getRowProps, getTableProps }) => (
|
|
74
|
+
<TableContainer
|
|
75
|
+
description={
|
|
76
|
+
<span className={styles.tableDescription}>
|
|
77
|
+
<span>{t('discountsAppliedToBill', 'Discounts applied to this bill')}</span>
|
|
78
|
+
</span>
|
|
79
|
+
}
|
|
80
|
+
title={t('discounts', 'Discounts')}>
|
|
81
|
+
<Table
|
|
82
|
+
{...getTableProps()}
|
|
83
|
+
aria-label={t('billDiscounts', 'Bill discounts')}
|
|
84
|
+
className={classNames(styles.discountsTable, 'billingTable')}>
|
|
85
|
+
<TableHead>
|
|
86
|
+
<TableRow>
|
|
87
|
+
{headers.map((header) => (
|
|
88
|
+
<TableHeader key={header.key}>{header.header}</TableHeader>
|
|
89
|
+
))}
|
|
90
|
+
</TableRow>
|
|
91
|
+
</TableHead>
|
|
92
|
+
<TableBody>
|
|
93
|
+
{rows.map((row) => (
|
|
94
|
+
<TableRow key={row.id} {...getRowProps({ row })}>
|
|
95
|
+
{row.cells.map((cell) => (
|
|
96
|
+
<TableCell key={cell.id}>{cell.value}</TableCell>
|
|
97
|
+
))}
|
|
98
|
+
</TableRow>
|
|
99
|
+
))}
|
|
100
|
+
</TableBody>
|
|
101
|
+
</Table>
|
|
102
|
+
</TableContainer>
|
|
103
|
+
)}
|
|
104
|
+
</DataTable>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default DiscountsTable;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@use '@carbon/colors';
|
|
2
|
+
@use '@carbon/layout';
|
|
3
|
+
@use '@carbon/type';
|
|
4
|
+
@use '@openmrs/esm-styleguide/src/vars' as *;
|
|
5
|
+
|
|
6
|
+
.discountsWrapper {
|
|
7
|
+
border: 1px solid colors.$gray-20;
|
|
8
|
+
background-color: colors.$white;
|
|
9
|
+
margin-bottom: layout.$spacing-05;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.discountsTable {
|
|
13
|
+
width: 100%;
|
|
14
|
+
|
|
15
|
+
td {
|
|
16
|
+
border-bottom: none !important;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.tableDescription {
|
|
21
|
+
display: flex;
|
|
22
|
+
align-items: flex-start;
|
|
23
|
+
margin-top: layout.$spacing-02;
|
|
24
|
+
column-gap: layout.$spacing-01;
|
|
25
|
+
|
|
26
|
+
::after {
|
|
27
|
+
content: '';
|
|
28
|
+
display: block;
|
|
29
|
+
width: layout.$spacing-07;
|
|
30
|
+
padding-top: 0.188rem;
|
|
31
|
+
border-bottom: 0.375rem solid var(--brand-03);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
& > span {
|
|
35
|
+
@include type.type-style('body-01');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { useSession, useConfig } from '@openmrs/esm-framework';
|
|
5
|
+
import DiscountsTable from './discounts-table.component';
|
|
6
|
+
import { BillDiscountStatus, BillDiscountType, type BillDiscount, type MappedBill } from '../types';
|
|
7
|
+
|
|
8
|
+
vi.mock('@openmrs/esm-framework', () => ({
|
|
9
|
+
useSession: vi.fn(),
|
|
10
|
+
useConfig: vi.fn(),
|
|
11
|
+
useLayoutType: () => 'desktop',
|
|
12
|
+
isDesktop: () => true,
|
|
13
|
+
formatDate: (d: Date) => d.toISOString(),
|
|
14
|
+
parseDate: (s: string) => new Date(s),
|
|
15
|
+
showModal: vi.fn(),
|
|
16
|
+
showSnackbar: vi.fn(),
|
|
17
|
+
restBaseUrl: '/ws/rest/v1',
|
|
18
|
+
}));
|
|
19
|
+
window.i18next = { language: 'en-US' } as any;
|
|
20
|
+
|
|
21
|
+
const mockDiscount = (overrides: Partial<BillDiscount> = {}) => ({
|
|
22
|
+
uuid: 'd1',
|
|
23
|
+
billUuid: 'b1',
|
|
24
|
+
lineItemUuid: null,
|
|
25
|
+
discountType: BillDiscountType.PERCENTAGE,
|
|
26
|
+
discountValue: 10,
|
|
27
|
+
discountAmount: 500,
|
|
28
|
+
justification: 'returning patient',
|
|
29
|
+
initiator: { uuid: 'u-cashier', display: 'cashier-alex' },
|
|
30
|
+
approver: null,
|
|
31
|
+
dateCreated: '2026-05-11T00:00:00.000+0000',
|
|
32
|
+
status: BillDiscountStatus.PENDING,
|
|
33
|
+
voided: false,
|
|
34
|
+
...overrides,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
vi.clearAllMocks();
|
|
39
|
+
vi.mocked(useSession).mockReturnValue({ user: { uuid: 'u-cashier' } } as any);
|
|
40
|
+
vi.mocked(useConfig).mockReturnValue({ defaultCurrency: 'USD' } as any);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const makeBill = (discounts: BillDiscount[] = []): MappedBill =>
|
|
44
|
+
({ uuid: 'b1', lineItems: [{ uuid: 'li1', item: 'Consultation' }], discounts }) as unknown as MappedBill;
|
|
45
|
+
|
|
46
|
+
describe('DiscountsTable', () => {
|
|
47
|
+
it('returns null when no non-voided discounts exist', () => {
|
|
48
|
+
const { container } = render(<DiscountsTable bill={makeBill([])} />);
|
|
49
|
+
expect(container).toBeEmptyDOMElement();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('returns null when all discounts are voided', () => {
|
|
53
|
+
const { container } = render(<DiscountsTable bill={makeBill([mockDiscount({ voided: true })])} />);
|
|
54
|
+
expect(container).toBeEmptyDOMElement();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('renders one row per discount with status tag', () => {
|
|
58
|
+
render(
|
|
59
|
+
<DiscountsTable
|
|
60
|
+
bill={makeBill([mockDiscount({ status: BillDiscountStatus.APPROVED }), mockDiscount({ uuid: 'd2' })])}
|
|
61
|
+
/>,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(screen.getByText(/Approved/i)).toBeInTheDocument();
|
|
65
|
+
expect(screen.getByText(/Pending/i)).toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import useSWR from 'swr';
|
|
2
|
+
import { openmrsFetch, useOpenmrsFetchAll } from '@openmrs/esm-framework';
|
|
3
|
+
import { apiBasePath } from '../constants';
|
|
4
|
+
import type {
|
|
5
|
+
BillDiscount,
|
|
6
|
+
BillDiscountStatus,
|
|
7
|
+
DecideDiscountPayload,
|
|
8
|
+
PatientInvoice,
|
|
9
|
+
RequestDiscountPayload,
|
|
10
|
+
} from '../types';
|
|
11
|
+
|
|
12
|
+
interface FetchEnvelope<T> {
|
|
13
|
+
data: { results: T[]; totalCount?: number };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const discountUrl = `${apiBasePath}billDiscount`;
|
|
17
|
+
const billUrl = `${apiBasePath}bill`;
|
|
18
|
+
|
|
19
|
+
export function useBillDiscounts(billUuid: string | undefined) {
|
|
20
|
+
const url = billUuid ? `${discountUrl}?bill=${billUuid}&v=default` : null;
|
|
21
|
+
const { data, isLoading, error, mutate } = useSWR<FetchEnvelope<BillDiscount>>(url, openmrsFetch);
|
|
22
|
+
const discounts = (data?.data?.results ?? []).filter((d) => !d.voided);
|
|
23
|
+
return { discounts, isLoading, error, mutate };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface UseDiscountRequestsArgs {
|
|
27
|
+
statuses: BillDiscountStatus[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useDiscountRequests({ statuses }: UseDiscountRequestsArgs) {
|
|
31
|
+
const qs = new URLSearchParams({
|
|
32
|
+
discountStatus: statuses.join(','),
|
|
33
|
+
v: 'default',
|
|
34
|
+
});
|
|
35
|
+
const url = `${billUrl}?${qs.toString()}`;
|
|
36
|
+
const { data, isLoading, error, mutate, isValidating } = useOpenmrsFetchAll<PatientInvoice>(url);
|
|
37
|
+
return {
|
|
38
|
+
bills: data ?? [],
|
|
39
|
+
isLoading,
|
|
40
|
+
error,
|
|
41
|
+
mutate,
|
|
42
|
+
isValidating,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function requestDiscount(payload: RequestDiscountPayload): Promise<BillDiscount> {
|
|
47
|
+
const response = await openmrsFetch<BillDiscount>(discountUrl, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: { 'Content-Type': 'application/json' },
|
|
50
|
+
body: payload as any,
|
|
51
|
+
});
|
|
52
|
+
return response.data;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function decideDiscount(
|
|
56
|
+
uuid: string,
|
|
57
|
+
status: DecideDiscountPayload['status'],
|
|
58
|
+
approverUuid: string,
|
|
59
|
+
): Promise<BillDiscount> {
|
|
60
|
+
const body: DecideDiscountPayload = { status, approver: approverUuid };
|
|
61
|
+
const response = await openmrsFetch<BillDiscount>(`${discountUrl}/${uuid}`, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: { 'Content-Type': 'application/json' },
|
|
64
|
+
body: body as any,
|
|
65
|
+
});
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function voidDiscount(uuid: string, reason: string): Promise<void> {
|
|
70
|
+
await openmrsFetch(`${discountUrl}/${uuid}?reason=${encodeURIComponent(reason)}`, { method: 'DELETE' });
|
|
71
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
@use '@carbon/styles/scss/spacing' as *;
|
|
2
|
+
@use '@carbon/styles/scss/type' as *;
|
|
3
|
+
|
|
4
|
+
.modalBody {
|
|
5
|
+
padding-bottom: $spacing-05;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.scopePanel {
|
|
9
|
+
background: var(--cds-layer);
|
|
10
|
+
border-left: 3px solid var(--cds-border-interactive);
|
|
11
|
+
padding: $spacing-04 $spacing-05;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.scopePrimary {
|
|
15
|
+
@include type-style('heading-compact-01');
|
|
16
|
+
color: var(--cds-text-primary);
|
|
17
|
+
margin-bottom: $spacing-02;
|
|
18
|
+
word-break: break-word;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.scopeMeta {
|
|
22
|
+
@include type-style('label-01');
|
|
23
|
+
color: var(--cds-text-secondary);
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
list-style: none;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
|
|
30
|
+
li + li::before {
|
|
31
|
+
content: '·';
|
|
32
|
+
margin: 0 $spacing-03;
|
|
33
|
+
color: var(--cds-text-helper);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.scopeTotal {
|
|
38
|
+
color: var(--cds-text-primary);
|
|
39
|
+
font-variant-numeric: tabular-nums;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.discountGroup :global(.cds--fieldset) {
|
|
43
|
+
margin-bottom: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.summaryCard {
|
|
47
|
+
background: var(--cds-layer);
|
|
48
|
+
padding: $spacing-04 $spacing-05;
|
|
49
|
+
display: grid;
|
|
50
|
+
grid-template-columns: 1fr auto;
|
|
51
|
+
row-gap: $spacing-03;
|
|
52
|
+
column-gap: $spacing-05;
|
|
53
|
+
align-items: baseline;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.summaryLabel {
|
|
57
|
+
@include type-style('body-compact-01');
|
|
58
|
+
color: var(--cds-text-secondary);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.summaryValue {
|
|
62
|
+
@include type-style('body-compact-01');
|
|
63
|
+
color: var(--cds-text-primary);
|
|
64
|
+
font-variant-numeric: tabular-nums;
|
|
65
|
+
text-align: right;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.summaryDiscount {
|
|
69
|
+
color: var(--cds-text-error);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.summaryDivider {
|
|
73
|
+
grid-column: 1 / -1;
|
|
74
|
+
height: 1px;
|
|
75
|
+
background: var(--cds-border-subtle);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.summaryTotalLabel {
|
|
79
|
+
@include type-style('heading-compact-01');
|
|
80
|
+
color: var(--cds-text-primary);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.summaryTotalValue {
|
|
84
|
+
@include type-style('heading-compact-01');
|
|
85
|
+
color: var(--cds-text-primary);
|
|
86
|
+
font-variant-numeric: tabular-nums;
|
|
87
|
+
text-align: right;
|
|
88
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
3
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
import { showSnackbar } from '@openmrs/esm-framework';
|
|
6
|
+
import RequestDiscountModal from './request-discount.modal';
|
|
7
|
+
import { requestDiscount } from './discounts.resource';
|
|
8
|
+
import { BillDiscountType } from '../types';
|
|
9
|
+
|
|
10
|
+
vi.mock('@openmrs/esm-framework', () => ({
|
|
11
|
+
showSnackbar: vi.fn(),
|
|
12
|
+
useConfig: vi.fn().mockReturnValue({ defaultCurrency: 'USD' }),
|
|
13
|
+
getCoreTranslation: (key: string) => key,
|
|
14
|
+
restBaseUrl: '/ws/rest/v1',
|
|
15
|
+
}));
|
|
16
|
+
vi.mock('./discounts.resource');
|
|
17
|
+
|
|
18
|
+
(window as any).i18next = { language: 'en-US' };
|
|
19
|
+
|
|
20
|
+
const closeModal = vi.fn();
|
|
21
|
+
const onMutate = vi.fn();
|
|
22
|
+
|
|
23
|
+
beforeEach(() => vi.clearAllMocks());
|
|
24
|
+
|
|
25
|
+
describe('RequestDiscountModal', () => {
|
|
26
|
+
it('blocks submit when justification is empty', async () => {
|
|
27
|
+
render(
|
|
28
|
+
<RequestDiscountModal
|
|
29
|
+
closeModal={closeModal}
|
|
30
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 1000 }}
|
|
31
|
+
onMutate={onMutate}
|
|
32
|
+
/>,
|
|
33
|
+
);
|
|
34
|
+
const submit = screen.getByRole('button', { name: /submit request/i });
|
|
35
|
+
expect(submit).toBeDisabled();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('rejects percentage value greater than 100', async () => {
|
|
39
|
+
const user = userEvent.setup();
|
|
40
|
+
render(
|
|
41
|
+
<RequestDiscountModal
|
|
42
|
+
closeModal={closeModal}
|
|
43
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 1000 }}
|
|
44
|
+
onMutate={onMutate}
|
|
45
|
+
/>,
|
|
46
|
+
);
|
|
47
|
+
await user.type(screen.getByLabelText(/value/i), '150');
|
|
48
|
+
await user.type(screen.getByLabelText(/justification/i), 'reason');
|
|
49
|
+
expect(screen.getByRole('button', { name: /submit request/i })).toBeDisabled();
|
|
50
|
+
expect(screen.getByText(/cannot exceed 100/i)).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('flags a fixed-amount discount that exceeds the amount due', async () => {
|
|
54
|
+
const user = userEvent.setup();
|
|
55
|
+
render(
|
|
56
|
+
<RequestDiscountModal
|
|
57
|
+
closeModal={closeModal}
|
|
58
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 1000 }}
|
|
59
|
+
onMutate={onMutate}
|
|
60
|
+
/>,
|
|
61
|
+
);
|
|
62
|
+
await user.click(screen.getByRole('radio', { name: /fixed amount/i }));
|
|
63
|
+
await user.type(screen.getByLabelText(/value/i), '2000');
|
|
64
|
+
await user.type(screen.getByLabelText(/justification/i), 'reason');
|
|
65
|
+
expect(screen.getByText(/cannot exceed the amount due/i)).toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('flags a percentage whose computed discount exceeds amount due on a partially-paid bill', async () => {
|
|
69
|
+
const user = userEvent.setup();
|
|
70
|
+
render(
|
|
71
|
+
<RequestDiscountModal
|
|
72
|
+
closeModal={closeModal}
|
|
73
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 200 }}
|
|
74
|
+
onMutate={onMutate}
|
|
75
|
+
/>,
|
|
76
|
+
);
|
|
77
|
+
await user.type(screen.getByLabelText(/value/i), '50');
|
|
78
|
+
await user.type(screen.getByLabelText(/justification/i), 'reason');
|
|
79
|
+
expect(screen.getByRole('button', { name: /submit request/i })).toBeDisabled();
|
|
80
|
+
expect(screen.getByText(/cannot exceed the amount due/i)).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('flags a fixed-amount discount that exceeds the line item total', async () => {
|
|
84
|
+
const user = userEvent.setup();
|
|
85
|
+
render(
|
|
86
|
+
<RequestDiscountModal
|
|
87
|
+
closeModal={closeModal}
|
|
88
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 1000 }}
|
|
89
|
+
lineItem={{ uuid: 'li1', display: 'Consultation', total: 200 }}
|
|
90
|
+
onMutate={onMutate}
|
|
91
|
+
/>,
|
|
92
|
+
);
|
|
93
|
+
await user.click(screen.getByRole('radio', { name: /fixed amount/i }));
|
|
94
|
+
await user.type(screen.getByLabelText(/value/i), '300');
|
|
95
|
+
await user.type(screen.getByLabelText(/justification/i), 'reason');
|
|
96
|
+
expect(screen.getByText(/cannot exceed the line item total/i)).toBeInTheDocument();
|
|
97
|
+
expect(screen.getByRole('button', { name: /submit request/i })).toBeDisabled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('flags a fixed-amount discount that would push the bill amount due negative on a partially-paid bill', async () => {
|
|
101
|
+
const user = userEvent.setup();
|
|
102
|
+
render(
|
|
103
|
+
<RequestDiscountModal
|
|
104
|
+
closeModal={closeModal}
|
|
105
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 300 }}
|
|
106
|
+
onMutate={onMutate}
|
|
107
|
+
/>,
|
|
108
|
+
);
|
|
109
|
+
await user.click(screen.getByRole('radio', { name: /fixed amount/i }));
|
|
110
|
+
// 500 <= bill.total (1000), but > amountDue (300) → would make amountDue negative.
|
|
111
|
+
await user.type(screen.getByLabelText(/value/i), '500');
|
|
112
|
+
await user.type(screen.getByLabelText(/justification/i), 'reason');
|
|
113
|
+
expect(screen.getByText(/cannot exceed the amount due/i)).toBeInTheDocument();
|
|
114
|
+
expect(screen.getByRole('button', { name: /submit request/i })).toBeDisabled();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('submits a valid request and closes', async () => {
|
|
118
|
+
vi.mocked(requestDiscount).mockResolvedValue({ uuid: 'new-d' } as any);
|
|
119
|
+
const user = userEvent.setup();
|
|
120
|
+
render(
|
|
121
|
+
<RequestDiscountModal
|
|
122
|
+
closeModal={closeModal}
|
|
123
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 1000 }}
|
|
124
|
+
onMutate={onMutate}
|
|
125
|
+
/>,
|
|
126
|
+
);
|
|
127
|
+
await user.type(screen.getByLabelText(/value/i), '10');
|
|
128
|
+
await user.type(screen.getByLabelText(/justification/i), 'returning patient');
|
|
129
|
+
await user.click(screen.getByRole('button', { name: /submit request/i }));
|
|
130
|
+
await waitFor(() =>
|
|
131
|
+
expect(requestDiscount).toHaveBeenCalledWith({
|
|
132
|
+
bill: 'b1',
|
|
133
|
+
discountType: BillDiscountType.PERCENTAGE,
|
|
134
|
+
discountValue: 10,
|
|
135
|
+
justification: 'returning patient',
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
await waitFor(() => expect(closeModal).toHaveBeenCalled());
|
|
139
|
+
expect(onMutate).toHaveBeenCalled();
|
|
140
|
+
expect(showSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'success' }));
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('shows an error snackbar and keeps the modal open when submission fails', async () => {
|
|
144
|
+
vi.mocked(requestDiscount).mockRejectedValue({
|
|
145
|
+
responseBody: { error: { message: 'billing.error.discount.scopeConflict' } },
|
|
146
|
+
});
|
|
147
|
+
const user = userEvent.setup();
|
|
148
|
+
render(
|
|
149
|
+
<RequestDiscountModal
|
|
150
|
+
closeModal={closeModal}
|
|
151
|
+
bill={{ uuid: 'b1', total: 1000, amountDue: 1000 }}
|
|
152
|
+
onMutate={onMutate}
|
|
153
|
+
/>,
|
|
154
|
+
);
|
|
155
|
+
await user.type(screen.getByLabelText(/value/i), '10');
|
|
156
|
+
await user.type(screen.getByLabelText(/justification/i), 'x');
|
|
157
|
+
await user.click(screen.getByRole('button', { name: /submit request/i }));
|
|
158
|
+
await waitFor(() => expect(showSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'error' })));
|
|
159
|
+
expect(closeModal).not.toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
});
|