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

import { resolveWorkflowFormParameters } from '../workflowFormParameters';

describe('resolveWorkflowFormParameters', () => {
  it('uses the image parameter when a legacy schema still declares text', () => {
    const parameters = resolveWorkflowFormParameters({
      parameters: [
        {
          name: 'image_input',
          contentType: 'image',
          dataType: 'Object',
          formType: 'input',
        },
      ],
      startFormSchema: [
        {
          key: 'image_input',
          label: '图片',
          type: 'text',
          contentType: 'text',
        },
      ],
    });

    expect(parameters).toEqual([
      expect.objectContaining({
        name: 'image_input',
        contentType: 'image',
        dataType: 'Object',
      }),
    ]);
  });

  it('uses a custom parameter name when the schema keeps a default label', () => {
    const parameters = resolveWorkflowFormParameters({
      parameters: [
        {
          name: '补充信息',
          formLabel: '文本字段',
        },
      ],
      startFormSchema: [
        {
          key: '补充信息',
          label: '文本字段',
          type: 'text',
          required: false,
        },
      ],
    });

    expect(parameters[0]).toMatchObject({
      name: '补充信息',
      formLabel: '补充信息',
      required: false,
    });
  });

  it('preserves an explicitly customized field label', () => {
    const parameters = resolveWorkflowFormParameters({
      startFormSchema: [
        {
          key: 'context',
          label: '背景资料',
          type: 'textarea',
        },
      ],
    });

    expect(parameters[0]).toMatchObject({
      name: 'context',
      formLabel: '背景资料',
    });
  });
});
