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

import {
  buildInteractionConfigPayload,
  resolveInteractionDisplay,
  validateInteractionConfig,
} from './interaction-config';

describe('agent 对话体验配置', () => {
  it('为空配置补充展示默认值', () => {
    expect(resolveInteractionDisplay({ name: '数据助手' })).toEqual({
      inputPlaceholder: '输入消息',
      suggestedQuestions: [],
      welcomeMessage: '你好，我是 数据助手，有什么可以帮你？',
    });
  });

  it('保存前清理首尾空白并过滤空问题', () => {
    expect(
      buildInteractionConfigPayload({
        inputPlaceholder: '  输入需求  ',
        suggestedQuestions: ['  问题一  ', '', ' 问题二'],
        welcomeMessage: '  欢迎使用  ',
      }),
    ).toEqual({
      inputPlaceholder: '输入需求',
      suggestedQuestions: ['问题一', '问题二'],
      welcomeMessage: '欢迎使用',
    });
  });

  it('识别去除空白后的重复问题', () => {
    const issues = validateInteractionConfig({
      suggestedQuestions: ['如何开始？', '  如何开始？ '],
    });

    expect(issues).toEqual(
      expect.arrayContaining([
        expect.objectContaining({
          field: 'interaction.suggestedQuestions.1',
        }),
      ]),
    );
  });
});
