import { createComponentFactory, Spectator } from '@ngneat/spectator';
import { UiFilterInputChipModule } from '../../shared/filter-input-chip';
import { UiInputGroup } from '../../tree';
import { UiFilterFilterGroupMainComponent } from './filter-filter-group-main.component';

describe('UiFilterFilterGroupMainComponent', () => {
  let spectator: Spectator<UiFilterFilterGroupMainComponent>;
  const createComponent = createComponentFactory({
    component: UiFilterFilterGroupMainComponent,
    imports: [UiFilterInputChipModule],
  });

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

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

  describe('inputGroup', () => {
    it('should create an instance of UiInputGroup when value is a plain object', () => {
      spectator.setInput({ inputGroup: {} });
      expect(spectator.component.uiInputGroup instanceof UiInputGroup).toBe(true);
    });

    it('should set the UiInputGroup if it is already an instance of UiInputGroup', () => {
      const instance = UiInputGroup.create({});
      spectator.setInput({ inputGroup: instance });
      expect(spectator.component.uiInputGroup).toBe(instance);
    });
  });

  describe('ui-filter-input-chip Element', () => {
    it('should render an Element for each uiInputGroup.input', () => {
      const instance = UiInputGroup.create({
        input: [
          { label: 'Label 1', type: 0 },
          { label: 'label 2', type: 0 },
          { label: 'label 3', type: 0 },
        ],
      });
      spectator.setInput({ inputGroup: instance });
      spectator.detectComponentChanges();

      expect(spectator.queryAll('ui-filter-input-chip').length).toBe(3);
    });
  });
});
