import { Input, InputType } from '../../types';
import { textFilterInputMapping } from './text-filter-input.mapping';
import * as schemaModule from '../schemas/text-filter-input.schema';

describe('textFilterInputMapping', () => {
  const mockSchemaParser = jest.fn().mockImplementation((input) => input);

  beforeEach(() => {
    jest.clearAllMocks();

    // Mock the schema parse method to avoid validation errors in tests
    jest.spyOn(schemaModule.TextFilterInputSchema, 'parse').mockImplementation(mockSchemaParser);
  });

  it('should map minimal input correctly', () => {
    // Arrange
    const group = 'testGroup';
    const input: Input = {
      key: 'testKey',
      label: 'Test Label',
      type: InputType.Text,
    };

    // Act
    const result = textFilterInputMapping(group, input);

    // Assert
    expect(mockSchemaParser).toHaveBeenCalledWith({
      group: 'testGroup',
      key: 'testKey',
      label: 'Test Label',
      description: undefined,
      type: InputType.Text,
      defaultValue: undefined,
      value: undefined,
      placeholder: undefined,
      target: undefined,
    });

    expect(result).toEqual({
      group: 'testGroup',
      key: 'testKey',
      label: 'Test Label',
      description: undefined,
      type: InputType.Text,
      defaultValue: undefined,
      value: undefined,
      placeholder: undefined,
      target: undefined,
    });
  });

  it('should map complete input correctly', () => {
    // Arrange
    const group = 'testGroup';
    const input: Input = {
      key: 'testKey',
      label: 'Test Label',
      description: 'Test Description',
      type: InputType.Text,
      value: 'defaultValue',
      placeholder: 'Enter text...',
    };

    // Act
    const result = textFilterInputMapping(group, input);

    // Assert
    expect(mockSchemaParser).toHaveBeenCalledWith({
      group: 'testGroup',
      key: 'testKey',
      label: 'Test Label',
      description: 'Test Description',
      type: InputType.Text,
      defaultValue: 'defaultValue',
      value: 'defaultValue',
      placeholder: 'Enter text...',
      target: undefined,
    });

    expect(result).toEqual({
      group: 'testGroup',
      key: 'testKey',
      label: 'Test Label',
      description: 'Test Description',
      type: InputType.Text,
      defaultValue: 'defaultValue',
      value: 'defaultValue',
      placeholder: 'Enter text...',
      target: undefined,
    });
  });
});
