|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { describe, it, expect, vi } from 'vitest'; |
| 4 | +import { InvoiceCard } from './InvoiceCard'; |
| 5 | +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; |
| 6 | + |
| 7 | +// Mock the hooks |
| 8 | +vi.mock('@/store/wallet', () => ({ |
| 9 | + useWalletStore: vi.fn(() => ({ address: 'GACR43ILX6H4PGAOO5QKSZLU4ZJMGT3E66EAUDPLM5J6YTP4Y3PSHWGB' })) |
| 10 | +})); |
| 11 | + |
| 12 | +vi.mock('@/hooks/useProfile', () => ({ |
| 13 | + useProfile: vi.fn(() => ({ isVerified: true })) |
| 14 | +})); |
| 15 | + |
| 16 | +const mockInvoice = { |
| 17 | + id: 'abcd', |
| 18 | + status: 'Created', |
| 19 | + issuer: 'GACR43ILX6H4PGAOO5QKSZLU4ZJMGT3E66EAUDPLM5J6YTP4Y3PSHWGB', |
| 20 | + buyer: 'GACR43ILX6H4PGAOO5QKSZLU4ZJMGT3E66EAUDPLM5J6YTP4Y3PSHWGB', |
| 21 | + faceValue: 10000000000n, // 1000.00 USDC |
| 22 | + dueDate: 1234567890 |
| 23 | +}; |
| 24 | + |
| 25 | +const queryClient = new QueryClient(); |
| 26 | + |
| 27 | +const renderWithQueryClient = (ui: React.ReactElement) => { |
| 28 | + return render( |
| 29 | + <QueryClientProvider client={queryClient}> |
| 30 | + {ui} |
| 31 | + </QueryClientProvider> |
| 32 | + ); |
| 33 | +}; |
| 34 | + |
| 35 | +describe('InvoiceCard', () => { |
| 36 | + it('renders invoice details correctly', () => { |
| 37 | + renderWithQueryClient(<InvoiceCard invoice={mockInvoice as any} />); |
| 38 | + expect(screen.getByText(/1,000.00 USDC/)).toBeInTheDocument(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('renders correct action buttons for created status (issuer)', () => { |
| 42 | + renderWithQueryClient(<InvoiceCard invoice={{...mockInvoice, status: 'Created'} as any} role="issuer" />); |
| 43 | + // Issuer can list for financing when created |
| 44 | + expect(screen.getByText(/Configure financing terms/i)).toBeInTheDocument(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('renders correct action buttons for listed status (lp)', () => { |
| 48 | + renderWithQueryClient(<InvoiceCard invoice={{...mockInvoice, status: 'Listed'} as any} role="lp" />); |
| 49 | + // LP can fund when listed |
| 50 | + expect(screen.getByText(/FUND INVOICE/i)).toBeInTheDocument(); |
| 51 | + }); |
| 52 | + |
| 53 | + it('renders correct action buttons for funded status (issuer)', () => { |
| 54 | + renderWithQueryClient(<InvoiceCard invoice={{...mockInvoice, status: 'Funded'} as any} role="issuer" />); |
| 55 | + // Issuer can mark shipped when funded |
| 56 | + expect(screen.getByText(/MARK GOODS SHIPPED/i)).toBeInTheDocument(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('renders correct action buttons for shipped status (buyer)', () => { |
| 60 | + renderWithQueryClient(<InvoiceCard invoice={{...mockInvoice, status: 'Active'} as any} role="buyer" />); |
| 61 | + // Buyer can confirm delivery when shipped (in contract it's Active) |
| 62 | + expect(screen.getByText(/CONFIRM DELIVERY/i)).toBeInTheDocument(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('renders correct action buttons for delivered status (buyer)', () => { |
| 66 | + renderWithQueryClient(<InvoiceCard invoice={{...mockInvoice, status: 'Confirmed'} as any} role="buyer" />); |
| 67 | + // Buyer can repay when delivered (in contract it's Confirmed) |
| 68 | + expect(screen.getByText(/REPAY INVOICE/i)).toBeInTheDocument(); |
| 69 | + }); |
| 70 | +}); |
0 commit comments