import { IUiOption, UiOption } from './ui-option';

describe('UiOption', () => {
  describe('static create(inputOptions: IUiOptionDTO)', () => {
    const testData: IUiOption = {
      description: 'description',
      enabled: false,
      key: 'key',
      label: 'label',
      maxValue: '2',
      minValue: '1',
      placeholder: 'placeholder',
      selected: true,
      value: 'value',
      values: [
        {
          description: 'sub description',
          enabled: true,
          key: 'sub key',
          label: 'sub label',
          maxValue: 'sub 2',
          minValue: 'sub 1',
          placeholder: 'sub placeholder',
          selected: false,
          value: 'sub value',
        },
      ],
    };

    let uiOption: UiOption;

    beforeEach(() => {
      spyOn(UiOption, 'create').and.callThrough();
      uiOption = UiOption.create(testData);
    });

    it('should return an instance of UiInputDTO', () => {
      expect(uiOption instanceof UiOption).toBe(true);
      expect(uiOption.description).toBe(testData.description);
      expect(uiOption.enabled).toBe(testData.enabled);
      expect(uiOption.key).toBe(testData.key);
      expect(uiOption.label).toBe(testData.label);
      expect(uiOption.maxValue).toBe(testData.maxValue);
      expect(uiOption.minValue).toBe(testData.minValue);
      expect(uiOption.placeholder).toBe(testData.placeholder);
      expect(uiOption.value).toBe(testData.value);

      testData.values.forEach((value) => expect(UiOption.create).toHaveBeenCalledWith(value, uiOption));
    });
  });
});
