import { createComponentFactory, Spectator } from '@ngneat/spectator';
import { FilterInputChipModule } from '../../shared/filter-input-chip';
import { InputGroup } from '../../tree';
import { FilterFilterGroupMainComponent } from './filter-filter-group-main.component';

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

  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 InputGroup).toBe(true);
    });

    it('should set the UiInputGroup if it is already an instance of UiInputGroup', () => {
      const instance = InputGroup.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 = InputGroup.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('shared-filter-input-chip').length).toBe(3);
    });
  });
});
