import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SelectFilterComponent } from './select-filter.component';
import { SelectFilterOptionComponent } from './select-filter-option.component';
import {
  selectFilterOptionsAllSelected,
  selectFilterOptionsAllDeselected,
  selectFilterOptionsMixedSelected,
} from '../../../../shelf/shared/mockdata';
import { NO_ERRORS_SCHEMA } from '@angular/core';

fdescribe('SelectFilterComponent', () => {
  let fixture: ComponentFixture<SelectFilterComponent>;
  let component: SelectFilterComponent;

  beforeEach(async () => {
    TestBed.configureTestingModule({
      providers: [],
      declarations: [SelectFilterComponent, SelectFilterOptionComponent],
      schemas: [NO_ERRORS_SCHEMA],
    }).compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(SelectFilterComponent);
    component = fixture.componentInstance;

    spyOn(component, 'ngAfterViewInit').and.callFake(() => {});
    fixture.detectChanges();
  });

  describe('setAllSelected', () => {
    beforeEach(() => {
      spyOn(component, 'setAllSelected').and.callThrough();
      spyOn(component.allSelected$, 'next').and.callFake(() => {});
    });

    it('should set allSelected with true', () => {
      const mockFilters = selectFilterOptionsAllSelected;
      component.setAllSelected(mockFilters);

      expect(component.allSelected$.next).toHaveBeenCalledWith(true);
    });

    it('should set allSelected to false if only some options are selected', () => {
      const mockFilters = selectFilterOptionsMixedSelected;
      component.setAllSelected(mockFilters);

      expect(component.allSelected$.next).toHaveBeenCalledWith(false);
    });

    it('should set allSelected with false', () => {
      const mockFilters = selectFilterOptionsAllDeselected;
      component.setAllSelected(mockFilters);

      expect(component.allSelected$.next).toHaveBeenCalledWith(false);
    });
  });
});
