import { describe, expect, it } from 'vitest';

import { formatStageSkipReason, getPlaceholderMessage, getShortageMessage } from '@/pages/searchResultsMessages';

describe('searchResultsMessages', () => {
  it('renders captcha interception placeholders as user-friendly text', () => {
    expect(getPlaceholderMessage('captcha_intercept')).toBe('历史记录：1688 滑块验证未通过，当时已跳过当前阶段');
  });

  it('keeps historical round_failed values readable', () => {
    expect(getPlaceholderMessage('round_failed')).toBe('当前阶段执行失败，已跳过');
    expect(formatStageSkipReason('round_failed')).toBe('当前阶段执行失败，已跳过');
  });

  it('renders search-stage login and captcha interception shortages clearly', () => {
    expect(getShortageMessage('login_intercept')).toBe('1688 登录态失效或被登录页拦截');
    expect(getShortageMessage('captcha_intercept')).toBe('1688 验证码未解除');
  });

  it('renders browser target crashes as the primary failure reason', () => {
    expect(getPlaceholderMessage('browser_target_crashed')).toBe('搜索浏览器崩溃，未进入结果页');
    expect(formatStageSkipReason('browser_target_crashed')).toBe('搜索浏览器崩溃，未进入结果页');
    expect(getShortageMessage('browser_target_crashed')).toBe('搜索浏览器崩溃，未进入结果页');
  });

  it('does not expose unknown English reason codes in shortage or stage labels', () => {
    expect(getShortageMessage('future_internal_reason_code')).toBe('系统已记录失败原因，请稍后重试或查看任务日志');
    expect(formatStageSkipReason('future_internal_reason_code')).toBe('系统已记录失败原因，请稍后重试或查看任务日志');
  });

  it('keeps Chinese AI and business reasons unchanged', () => {
    expect(getShortageMessage('有效电话不足，需要人工补充')).toBe('有效电话不足，需要人工补充');
  });
});
