import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it, vi } from 'vitest';
import { AppShell } from './AppShell';

function renderShell(canAccessAdmin: boolean) {
  const handler = vi.fn();
  return renderToStaticMarkup(
    <AppShell
      activePage="home"
      authenticationStatus="authenticated"
      canAccessAdmin={canAccessAdmin}
      health={null}
      state="ready"
      onLogin={handler}
      onNavigate={handler}
      onRefresh={handler}
      onSignOut={handler}
    >
      <div>content</div>
    </AppShell>,
  );
}

describe('AppShell', () => {
  it('hides the admin workspace navigation without admin access', () => {
    expect(renderShell(false)).not.toContain('管理工作台');
  });

  it('shows the admin workspace navigation with admin access', () => {
    expect(renderShell(true)).toContain('管理工作台');
  });

  it('does not show signed-in or signed-out actions while checking the session', () => {
    const handler = vi.fn();
    const html = renderToStaticMarkup(
      <AppShell
        activePage="workspace"
        authenticationStatus="checking"
        canAccessAdmin={false}
        health={null}
        state="idle"
        onLogin={handler}
        onNavigate={handler}
        onRefresh={handler}
        onSignOut={handler}
      >
        <div>正在确认登录状态</div>
      </AppShell>,
    );

    expect(html).not.toContain('>登录<');
    expect(html).not.toContain('>退出<');
    expect(html).not.toContain('>刷新<');
  });
});
