import { createComponentFactory, Spectator } from '@ngneat/spectator';
import { UiInput, UiInputType, UiOption } from '../../../tree';
import { UiFilterInputOptionDateRangeComponent } from './filter-input-option-date-range.component';

describe('UiFilterInputOptionDateRangeComponent', () => {
  let spectator: Spectator<UiFilterInputOptionDateRangeComponent>;
  const createComponent = createComponentFactory({
    component: UiFilterInputOptionDateRangeComponent,
  });

  beforeEach(() => {
    spectator = createComponent();
  });

  it('should create', () => {
    expect(spectator.component).toBeTruthy();
  });

  describe('set options(value: IUiOption[])', () => {
    it('should create an instance of UiOption when values are not an instance of UiOption', () => {
      spectator.setInput({
        options: [{ key: 'start' }, { key: 'stop' }],
      });

      spectator.component['_options'].forEach((uiOption) => {
        expect(uiOption instanceof UiOption).toBe(true);
      });
    });

    it('should set the values when vales are an isntance of UiOption', () => {
      const option1 = UiOption.create({ key: 'start' });
      const option2 = UiOption.create({ key: 'stop' });
      spectator.setInput({
        options: [option1, option2],
      });

      expect(spectator.component['_options'][0]).toBe(option1);
      expect(spectator.component['_options'][1]).toBe(option2);
    });
  });

  describe('get uiOptions()', () => {
    it('should return the value of _options', () => {
      const option1 = UiOption.create({ key: 'start' });
      const option2 = UiOption.create({ key: 'stop' });
      const options = [option1, option2];
      spectator.component['_options'] = options;

      expect(spectator.component.uiOptions).toBe(options);
    });
  });

  describe('get uiStartOption()', () => {
    it('should retun the option with the key start', () => {
      const option1 = UiOption.create({ key: 'start' });
      const option2 = UiOption.create({ key: 'stop' });
      const options = [option1, option2];
      spectator.component['_options'] = options;

      expect(spectator.component.uiStartOption).toBe(option1);
    });
  });

  describe('get uiStopOption()', () => {
    it('should return the option with the key stop', () => {
      const option1 = UiOption.create({ key: 'start' });
      const option2 = UiOption.create({ key: 'stop' });
      const options = [option1, option2];
      spectator.component['_options'] = options;

      expect(spectator.component.uiStopOption).toBe(option2);
    });
  });
});
