import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { CartDrawer } from '../../../src/components/cart/CartDrawer';
const sampleItem = {
code: 'POINTS_PACK',
name: 'Points: Complete Pack',
category: 'Bundle',
desc: 'All points',
priceInr: 900,
priceUsd: 15,
priceEur: 15,
};
describe('CartDrawer', () => {
it('renders empty state when cart is empty', () => {
render(
);
expect(screen.getByText('0 Items')).toBeInTheDocument();
expect(screen.getByText(/Your checkout cart is empty/i)).toBeInTheDocument();
});
it('renders populated cart, discounts, invalid/valid coupons, billing profile, and checkout errors', async () => {
const user = userEvent.setup();
const onUpdateBillingPhone = vi.fn();
const removePromoCode = vi.fn();
const handleCheckout = vi.fn();
const { rerender } = render(
);
expect(screen.getByText('Complete Pack')).toBeInTheDocument();
expect(screen.getByText('Early Renewal Discount (20%)')).toBeInTheDocument();
expect(screen.getByText('Loyalty Discount: 10%')).toBeInTheDocument();
expect(screen.getByText('Coupon Discount (SAVE20)')).toBeInTheDocument();
expect(screen.getByText('Gateway fee (2%)')).toBeInTheDocument();
expect(screen.getByText('Required for checkout')).toBeInTheDocument();
expect(screen.getByText('Signature mismatch')).toBeInTheDocument();
await user.click(screen.getByRole('button', { name: 'Add Number' }));
expect(onUpdateBillingPhone).toHaveBeenCalledTimes(1);
await user.click(screen.getByRole('button', { name: /Secure Payment with Razorpay/i }));
expect(handleCheckout).toHaveBeenCalledTimes(1);
// Rerender with EUR, invalid coupon, and incomplete phone
rerender(
);
expect(screen.getByText(/Invalid coupon/i)).toBeInTheDocument();
expect(screen.getByText(/Incomplete \(123\)/i)).toBeInTheDocument();
expect(screen.getByText('Total Discounts')).toBeInTheDocument();
});
});