OfficialSiteMethodologyRoute.test.tsx 1.76 KB
import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it } from 'vitest';

import { App } from '../../App';

function renderApp(path = '/official-site/methodology') {
  window.localStorage.setItem('agent-admin-local-login', 'true');
  return render(
    <MemoryRouter initialEntries={[path]}>
      <App />
    </MemoryRouter>,
  );
}

describe('official site methodology route and navigation', () => {
  beforeEach(() => {
    window.localStorage.clear();
  });

  it('renders the methodology page inside admin shell with correct menu ownership', () => {
    renderApp();

    expect(screen.getByRole('heading', { name: '方法论展示配置' })).toBeInTheDocument();
    expect(screen.getByText('官网配置 / 方法论展示配置')).toBeInTheDocument();
    expect(screen.getByRole('button', { name: '方法论展示配置' })).toHaveAttribute('aria-current', 'page');
    expect(screen.getByRole('button', { name: 'Agent列表' })).not.toHaveAttribute('aria-current');
  });

  it('shows the official site navigation entry and can navigate to the methodology page from agents', () => {
    renderApp('/agents');

    fireEvent.click(screen.getByRole('button', { name: '方法论展示配置' }));

    expect(screen.getByRole('heading', { name: '方法论展示配置' })).toBeInTheDocument();
    expect(screen.getByText('官网配置 / 方法论展示配置')).toBeInTheDocument();
  });

  it('keeps the protected index redirect pointing to agents by default', () => {
    renderApp('/');

    expect(screen.getByRole('heading', { name: 'Agent管理' })).toBeInTheDocument();
    expect(screen.getByRole('button', { name: 'Agent列表' })).toHaveAttribute('aria-current', 'page');
  });
});