feat(ConfirmAppointmentModal): add payment handling tests and improve modal functionality
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { screen, fireEvent } from '@testing-library/react';
|
||||
import { renderWithProviders } from '../../test/utils';
|
||||
|
||||
vi.mock('../../lib/api', () => ({
|
||||
api: { get: vi.fn(), post: vi.fn(), patch: vi.fn(), put: vi.fn(), delete: vi.fn() },
|
||||
ApiError: class extends Error {},
|
||||
}));
|
||||
|
||||
import ConfirmAppointmentModal from './ConfirmAppointmentModal';
|
||||
|
||||
const appointment = {
|
||||
uuid: 'a1',
|
||||
version: 1,
|
||||
patient_name: 'محمد رضایی',
|
||||
visit_price_rials: 2_120_000,
|
||||
service_items: [{ uuid: 's1', name: 'لیزر', price_rials: 880_000 }],
|
||||
};
|
||||
|
||||
function render() {
|
||||
return renderWithProviders(
|
||||
<ConfirmAppointmentModal open appointmentUuid="a1" appointment={appointment} onClose={() => {}} />,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
describe('ConfirmAppointmentModal', () => {
|
||||
it('بیمار، اقلام هزینه و جمع کل را نشان میدهد', () => {
|
||||
render();
|
||||
expect(screen.getByText('محمد رضایی')).toBeInTheDocument();
|
||||
expect(screen.getByText('ویزیت')).toBeInTheDocument();
|
||||
expect(screen.getByText('لیزر')).toBeInTheDocument();
|
||||
expect(screen.getByText('جمع کل')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('مبلغ پرداختی پیشفرض برابر باقیمانده (کل هزینه) است', () => {
|
||||
render();
|
||||
// ۳٬۰۰۰٬۰۰۰ ریال = ۳۰۰٬۰۰۰ تومان
|
||||
expect(screen.getByPlaceholderText('0')).toHaveValue('۳۰۰٬۰۰۰');
|
||||
expect(screen.getByText('تسویه کامل')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('با تغییر دستی مبلغ، باقیمانده دوباره محاسبه میشود', () => {
|
||||
render();
|
||||
fireEvent.change(screen.getByPlaceholderText('0'), { target: { value: '100000' } });
|
||||
|
||||
expect(screen.getByText('پرداخت جزئی')).toBeInTheDocument();
|
||||
// ۳۰۰٬۰۰۰ − ۱۰۰٬۰۰۰ تومان باقیمانده ⇒ ۲٬۰۰۰٬۰۰۰ ریال
|
||||
expect(screen.getByText(/باقیمانده پس از این پرداخت/)).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'بدون پرداخت' }));
|
||||
expect(screen.getByText('بدون پرداخت', { selector: 'span' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('دکمهٔ تأیید فقط با مبلغ بیشتر از جمع کل غیرفعال میشود', () => {
|
||||
render();
|
||||
const submit = screen.getByRole('button', { name: 'تأیید و قطعی کردن' });
|
||||
expect(submit).not.toBeDisabled();
|
||||
|
||||
// مبلغ بالاتر از جمع کل (۳٬۰۰۰٬۰۰۰ ریال = ۳۰۰٬۰۰۰ تومان < کل؛ پس عدد بزرگتر میدهیم)
|
||||
fireEvent.change(screen.getByPlaceholderText('0'), { target: { value: '9000000' } });
|
||||
expect(screen.getByText('مبلغ پرداخت از جمع کل بیشتر است.')).toBeInTheDocument();
|
||||
expect(submit).toBeDisabled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user