import { UiInput } from './ui-input';
import { IUiInputGroup, UiInputGroup } from './ui-input-group';

describe('UiInputGroup', () => {
  const testData: IUiInputGroup = {
    description: 'test description',
    group: 'main',
    focused: true,
    input: [
      { key: 'all_branches', label: 'Alle Filialen', type: 2, target: 'filter' },
      { key: 'customer_name', label: 'Kundenname', type: 2, target: 'input' },
      { key: 'product_contributor', label: 'Autor', type: 2, target: 'input' },
      { key: 'product_name', label: 'Titel', type: 2, target: 'input' },
    ],
  };

  let inputGroup: UiInputGroup;

  beforeEach(() => {
    spyOn(UiInput, 'create').and.callThrough();
    inputGroup = UiInputGroup.create(testData);
  });

  describe('static create(inputGroup: IUiInputGroup)', () => {
    it('should create and return an instance of UiInputGroup', () => {
      expect(inputGroup instanceof UiInputGroup).toBe(true);
      expect(inputGroup.description).toEqual(testData.description);
      expect(inputGroup.group).toEqual(testData.group);

      testData.input.forEach((input) => expect(UiInput.create).toHaveBeenCalledWith(input, inputGroup));

      expect(inputGroup.label).toEqual(testData.label);
    });
  });
});
