|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | +import { describe, expect, it, vi } from 'vitest'; |
| 3 | + |
| 4 | +import { TestProviders } from '#mocks'; |
| 5 | + |
| 6 | +import { SchedulesTable } from './SchedulesTable'; |
| 7 | + |
| 8 | +const state = vi.hoisted(() => ({ isNarrowWidth: true })); |
| 9 | + |
| 10 | +vi.mock('@actual-app/components/hooks/useResponsive', () => ({ |
| 11 | + useResponsive: () => ({ |
| 12 | + isNarrowWidth: state.isNarrowWidth, |
| 13 | + isWideWidth: !state.isNarrowWidth, |
| 14 | + }), |
| 15 | +})); |
| 16 | + |
| 17 | +vi.mock('#hooks/useScheduleDateLookup', () => ({ |
| 18 | + useScheduleDateLookup: () => ({ schedules: [], isLoading: false }), |
| 19 | +})); |
| 20 | + |
| 21 | +vi.mock('#hooks/usePayees', () => ({ |
| 22 | + usePayees: () => ({ data: [{ id: 'p1', name: 'Acme Corp' }] }), |
| 23 | +})); |
| 24 | + |
| 25 | +vi.mock('#hooks/usePayee', () => ({ |
| 26 | + usePayee: () => ({ data: { id: 'p1', name: 'Acme Corp' } }), |
| 27 | +})); |
| 28 | + |
| 29 | +vi.mock('#hooks/useAccounts', () => ({ |
| 30 | + useAccounts: () => ({ data: [{ id: 'a1', name: 'Joint Checking' }] }), |
| 31 | +})); |
| 32 | + |
| 33 | +vi.mock('#hooks/useAccount', () => ({ |
| 34 | + useAccount: () => ({ id: 'a1', name: 'Joint Checking' }), |
| 35 | +})); |
| 36 | + |
| 37 | +const schedules = [ |
| 38 | + { |
| 39 | + id: 's1', |
| 40 | + name: 'Payroll deposit', |
| 41 | + _payee: 'p1', |
| 42 | + _account: 'a1', |
| 43 | + _amount: 187711, |
| 44 | + _amountOp: 'is', |
| 45 | + _date: '2026-11-13', |
| 46 | + next_date: '2026-11-13', |
| 47 | + completed: false, |
| 48 | + }, |
| 49 | +] as never; |
| 50 | + |
| 51 | +function renderTable() { |
| 52 | + render( |
| 53 | + <TestProviders> |
| 54 | + <SchedulesTable |
| 55 | + schedules={schedules} |
| 56 | + statuses={new Map([['s1', 'due']])} |
| 57 | + filter="" |
| 58 | + allowCompleted={false} |
| 59 | + minimal |
| 60 | + onSelect={vi.fn()} |
| 61 | + style={{}} |
| 62 | + /> |
| 63 | + </TestProviders>, |
| 64 | + ); |
| 65 | +} |
| 66 | + |
| 67 | +describe('SchedulesTable in the minimal (link) dialog', () => { |
| 68 | + it('stacks the name, payee and account on a phone-width screen', () => { |
| 69 | + state.isNarrowWidth = true; |
| 70 | + renderTable(); |
| 71 | + expect(screen.getByText('Payroll deposit')).toBeInTheDocument(); |
| 72 | + expect(screen.getByText(/Acme Corp/)).toBeInTheDocument(); |
| 73 | + expect(screen.getByText(/Joint Checking/)).toBeInTheDocument(); |
| 74 | + // The wide column headers are replaced by the stacked row |
| 75 | + expect(screen.queryByText('Payee')).not.toBeInTheDocument(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('keeps the column layout on desktop', () => { |
| 79 | + state.isNarrowWidth = false; |
| 80 | + renderTable(); |
| 81 | + expect(screen.getByText('Payee')).toBeInTheDocument(); |
| 82 | + expect(screen.getByText('Account')).toBeInTheDocument(); |
| 83 | + }); |
| 84 | +}); |
0 commit comments