// @vitest-environment jsdom
import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { describe, expect, it, vi } from 'vitest';
import { AppShell } from './AppShell';

vi.mock('./Sidebar', () => ({
  Sidebar: () => <aside>Sidebar</aside>,
}));

vi.mock('./Header', () => ({
  Header: () => <header>Header</header>,
}));

vi.mock('./RightPanel', () => ({
  RightPanel: () => <aside>Right panel</aside>,
}));

vi.mock('../../views/HomeView', () => ({
  HomeView: () => <div>Home view</div>,
}));

vi.mock('../../views/PortfolioView', () => ({
  PortfolioView: () => <div>Portfolio view</div>,
}));

vi.mock('../../views/ResearchView', () => ({
  ResearchView: () => <div>Research view</div>,
}));

vi.mock('../../views/SimpleView', () => ({
  SimpleView: () => <div>Simple view</div>,
}));

vi.mock('../../views/MarketsView', () => ({
  MarketsView: () => <div>Markets view</div>,
}));

vi.mock('../../views/ScreenerView', () => ({
  ScreenerView: () => <div>Screener view</div>,
}));

vi.mock('../../views/WatchlistView', () => ({
  WatchlistView: () => <div>Watchlist view</div>,
}));

vi.mock('../../views/AlertsView', () => ({
  AlertsView: () => <div>Alerts view</div>,
}));

vi.mock('../../views/SettingsView', () => ({
  SettingsView: () => <div>Settings view</div>,
}));

describe('AppShell routing fallback', () => {
  it('shows a useful 404 state for unknown routes', () => {
    render(
      <MemoryRouter initialEntries={['/missing/workspace']}>
        <AppShell />
      </MemoryRouter>,
    );

    expect(screen.getByRole('heading', { name: 'Route not found' })).toBeInTheDocument();
    expect(screen.getByText('/missing/workspace')).toBeInTheDocument();
    expect(screen.getByRole('link', { name: 'Return home' })).toHaveAttribute('href', '/');
    expect(screen.queryByText('Home view')).not.toBeInTheDocument();
  });
});
