agent-list-mock.test.ts 1.72 KB
import { describe, expect, it } from 'vitest';

import {
  agentListMockFixtures,
  agentPositionOptions,
  getAgentListPage,
  sortAgentsForDisplay,
} from './agent-list-mock';

describe('agent list mock contract', () => {
  it('provides the minimal page-facing fields and stable position options', () => {
    const [agent] = agentListMockFixtures.normal.items;

    expect(agent).toMatchObject({
      agent_id: expect.any(Number),
      name: expect.any(String),
      is_manager: expect.any(Boolean),
      positions: expect.any(Array),
      status: expect.stringMatching(/enable|disable/),
      bound_group_count: expect.any(Number),
      bound_skill_count: expect.any(Number),
      updated_at: expect.any(String),
      available_actions: expect.any(Array),
    });
    expect(agentPositionOptions[0]).toEqual({ id: 'sales', name: '驻店销售岗' });
  });

  it('covers required page state fixtures without a backend service', () => {
    expect(Object.keys(agentListMockFixtures).sort()).toEqual([
      'disabledActions',
      'empty',
      'error',
      'filteredEmpty',
      'loading',
      'longText',
      'managerOnly',
      'normal',
      'paginationBoundary',
    ]);
  });

  it('keeps manager agents visible and sorted before ordinary agents', () => {
    const sorted = sortAgentsForDisplay(agentListMockFixtures.normal.items);

    expect(sorted[0].is_manager).toBe(true);
    expect(sorted[0].positions).toEqual([]);
  });

  it('filters and paginates mock data from page-facing query fields', () => {
    const result = getAgentListPage({ keyword: '复盘', positionId: 'sales', status: 'enable', page: 1, pageSize: 10 });

    expect(result.total).toBe(1);
    expect(result.items[0].name).toBe('复盘Agent');
  });
});