Task 08's pricing chain was reachable only through the API, so a clinic could not define a price list or see what a booked appointment was actually charged. Price lists - Draft / active / expired are shown as three states because they mean three different things operationally: a draft has no effect on today's price at all - Activation is a separate action rather than a checkbox in the form, matching the backend rule that creating a list must not change anything - "Copy" seeds a new list from an existing one starting the day the old one ends, since most lists are last quarter's with a few numbers moved - "All branches" is an explicit option, not an empty field Invoice card - Renders the recorded chain down to the final amount, hiding zero rows so the card stays readable - A missing invoice renders as a normal state, not an error: an appointment that was never confirmed has no invoice - Says outright that the numbers are from the appointment's own date and later tariff changes do not move them — otherwise someone who edited a price yesterday reads today's older number as a bug Also corrects task 08's checklist: its test section carried a copy-pasted "no UI was built" note against rows whose tests have existed since the task shipped. Replaced with the real test names and the two that genuinely are not covered. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
71 lines
2.9 KiB
TypeScript
71 lines
2.9 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { screen, waitFor } 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 {},
|
|
}));
|
|
|
|
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
|
|
|
import { api } from '../lib/api';
|
|
import AppointmentInvoiceCard from './AppointmentInvoiceCard';
|
|
|
|
const get = api.get as ReturnType<typeof vi.fn>;
|
|
|
|
const invoice = {
|
|
base_rials: 10_000_000,
|
|
items_rials: 2_000_000,
|
|
discount_rials: 1_200_000,
|
|
insurance_base_rials: 2_160_000,
|
|
insurance_supplementary_rials: 0,
|
|
tax_rials: 432_000,
|
|
final_rials: 9_072_000,
|
|
deposit_rials: 1_425_600,
|
|
created_at: 1_700_000_000,
|
|
breakdown: { discounts: [{ label: 'تخفیف درصدی', rials: 1_200_000 }], sources: {} },
|
|
};
|
|
|
|
describe('AppointmentInvoiceCard', () => {
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
it('lays out the chain down to the final amount', async () => {
|
|
get.mockResolvedValue({ success: true, data: invoice });
|
|
renderWithProviders(<AppointmentInvoiceCard appointmentUuid="a1" />, { route: '/admin/appointments/a1' });
|
|
|
|
await waitFor(() => expect(screen.getByText('فاکتور')).toBeInTheDocument());
|
|
expect(screen.getByText('قیمت پایه')).toBeInTheDocument();
|
|
expect(screen.getByText('مبلغ نهایی')).toBeInTheDocument();
|
|
expect(screen.getByText('بیعانه')).toBeInTheDocument();
|
|
});
|
|
|
|
/** ردیف صفر نباید جا بگیرد — فاکتور شلوغ خوانده نمیشود. */
|
|
it('hides zero rows', async () => {
|
|
get.mockResolvedValue({ success: true, data: invoice });
|
|
renderWithProviders(<AppointmentInvoiceCard appointmentUuid="a1" />, { route: '/admin/appointments/a1' });
|
|
|
|
await waitFor(() => expect(screen.getByText('فاکتور')).toBeInTheDocument());
|
|
expect(screen.queryByText('سهم بیمهٔ تکمیلی')).not.toBeInTheDocument();
|
|
});
|
|
|
|
/** ⭐ نبودِ فاکتور خطا نیست: نوبتِ ثبتنهایینشده فاکتوری ندارد. */
|
|
it('treats a missing invoice as a normal state', async () => {
|
|
get.mockRejectedValue(new Error('not found'));
|
|
renderWithProviders(<AppointmentInvoiceCard appointmentUuid="a1" />, { route: '/admin/appointments/a1' });
|
|
|
|
await waitFor(() =>
|
|
expect(screen.getByText('برای این نوبت فاکتوری ثبت نشده است.')).toBeInTheDocument(),
|
|
);
|
|
});
|
|
|
|
it('says the snapshot does not follow later price changes', async () => {
|
|
get.mockResolvedValue({ success: true, data: invoice });
|
|
renderWithProviders(<AppointmentInvoiceCard appointmentUuid="a1" />, { route: '/admin/appointments/a1' });
|
|
|
|
await waitFor(() =>
|
|
expect(screen.getByText(/تغییر بعدی تعرفه این فاکتور را عوض نمیکند/)).toBeInTheDocument(),
|
|
);
|
|
});
|
|
});
|