-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Test) Add Tests for the Require Payment Modal Component (#63)
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { useBills } from '../billing.resource'; | ||
import RequirePaymentModal from './require-payment-modal.component'; | ||
|
||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ t: (key: string) => key }), | ||
})); | ||
|
||
jest.mock('@openmrs/esm-framework', () => ({ | ||
useConfig: () => ({ defaultCurrency: 'USD' }), | ||
})); | ||
|
||
jest.mock('../billing.resource', () => ({ | ||
useBills: jest.fn(), | ||
})); | ||
|
||
jest.mock('../helpers', () => ({ | ||
convertToCurrency: (value, currency) => `${currency} ${value.toFixed(2)}`, | ||
})); | ||
|
||
describe('RequirePaymentModal', () => { | ||
const closeModal = jest.fn(); | ||
const patientUuid = '12345'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders correctly', () => { | ||
(useBills as jest.Mock).mockReturnValue({ bills: [], isLoading: false, error: null }); | ||
render(<RequirePaymentModal closeModal={closeModal} patientUuid={patientUuid} />); | ||
expect(screen.getByText('patientBillingAlert')).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays loading state', () => { | ||
(useBills as jest.Mock).mockReturnValue({ bills: [], isLoading: true, error: null }); | ||
render(<RequirePaymentModal closeModal={closeModal} patientUuid={patientUuid} />); | ||
expect(screen.getByText('inlineLoading')).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays line items', () => { | ||
const bills = [ | ||
{ | ||
status: 'UNPAID', | ||
lineItems: [ | ||
{ billableService: 'Service 1', quantity: 1, price: 100 }, | ||
{ item: 'Item 1', quantity: 2, price: 50 }, | ||
], | ||
}, | ||
]; | ||
(useBills as jest.Mock).mockReturnValue({ bills, isLoading: false, error: null }); | ||
render(<RequirePaymentModal closeModal={closeModal} patientUuid={patientUuid} />); | ||
expect(screen.getByText('Service 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Item 1')).toBeInTheDocument(); | ||
}); | ||
|
||
it('handles closeModal', () => { | ||
(useBills as jest.Mock).mockReturnValue({ bills: [], isLoading: false, error: null }); | ||
render(<RequirePaymentModal closeModal={closeModal} patientUuid={patientUuid} />); | ||
fireEvent.click(screen.getByText('cancel')); | ||
fireEvent.click(screen.getByText('ok')); | ||
expect(closeModal).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |