import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator';
import { IUiFilter, UiFilter, UiFilterComponent } from '@ui/filter';
import { UiIconModule } from '@ui/icon';
import { cold, hot } from 'jasmine-marbles';
import { MockComponent } from 'ng-mocks';
import { BehaviorSubject } from 'rxjs';
// import { GoodsInSearchService } from '../goods-in-search.service';
import { GoodsInSearchFilterComponent } from './goods-in-search-filter.component';

describe('GoodsInSearchFilterComponent', () => {
  let spectator: Spectator<GoodsInSearchFilterComponent>;
  const createComponent = createComponentFactory({
    component: GoodsInSearchFilterComponent,
    imports: [UiIconModule],
    declarations: [MockComponent(UiFilterComponent)],
    // providers: [mockProvider(GoodsInSearchService)],
  });

  // let goodsInServiceMock: jasmine.SpyObj<GoodsInSearchService>;

  beforeEach(() => {
    spectator = createComponent();
    // goodsInServiceMock = spectator.inject(GoodsInSearchService);
  });

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

  // describe('.btn-close', () => {
  //   it('should emit close on click', () => {
  //     let emitted = false;
  //     spectator.output('close').subscribe(() => (emitted = true));
  //     spectator.click('.btn-close');
  //     expect(emitted).toBe(true);
  //   });
  // });

  // describe('settings', () => {
  //   it('should be an instance of UiFilter', () => {
  //     expect(spectator.component.filter instanceof UiFilter).toBe(true);
  //   });

  //   it('should UiFilter.create with GoodsInSearchService.settings to create a new instance of UiFilter', () => {
  //     const settings = UiFilter.create({ input: [], filter: [] });

  //     spyOn(UiFilter, 'create').and.callThrough();
  //     goodsInServiceMock.settings = settings;

  //     spectator.component['_initSettings']();

  //     expect(UiFilter.create).toHaveBeenCalledWith(settings);
  //     expect(settings).not.toBe(spectator.component.filter);
  //   });
  // });

  // describe('loading$', () => {
  //   it('should set loading$ with GoodsInSearchService.loading$', () => {
  //     goodsInServiceMock.loading$ = new BehaviorSubject(true);

  //     spyOn(goodsInServiceMock.loading$, 'asObservable').and.returnValue(hot('a--b--a--', { a: true, b: false }));

  //     spectator.component['_initLoading$']();

  //     expect(goodsInServiceMock.loading$.asObservable).toHaveBeenCalled();

  //     expect(spectator.component.loading$).toBeObservable(cold('a--b--a--', { a: true, b: false }));
  //   });
  // });

  // describe('resetFilter()', () => {
  //   it('should call GoodsInSearchService.loadSettings()', async () => {
  //     goodsInServiceMock.loadSettings.and.returnValue(Promise.resolve());
  //     await spectator.component.resetFilter();

  //     expect(goodsInServiceMock.loadSettings).toHaveBeenCalled();
  //   });

  //   it('should UiFilter.create with GoodsInSearchService.settings to create a new instance of UiFilter', async () => {
  //     const settings = UiFilter.create({ input: [], filter: [] });

  //     spyOn(UiFilter, 'create').and.callThrough();
  //     goodsInServiceMock.loadSettings.and.returnValue(Promise.resolve());
  //     goodsInServiceMock.settings = settings;

  //     await spectator.component.resetFilter();

  //     expect(UiFilter.create).toHaveBeenCalledWith(settings);
  //     expect(settings).not.toBe(spectator.component.filter);
  //   });
  // });

  // describe('applyFilter', () => {
  //   it('should call GoodsInSearchService.setSettings with settings', () => {
  //     spectator.component.filter = UiFilter.create({});

  //     spectator.component.applyFilter();
  //     expect(goodsInServiceMock.setSettings).toHaveBeenCalledWith(spectator.component.filter);
  //   });

  //   it('should call GoodsInSearchService.search', () => {
  //     spectator.component.applyFilter();
  //     expect(goodsInServiceMock.search).toHaveBeenCalledWith();
  //   });

  //   it('should call close.emit', () => {
  //     spyOn(spectator.component.close, 'emit');
  //     spectator.component.applyFilter();
  //     expect(spectator.component.close.emit).toHaveBeenCalledWith();
  //   });
  // });

  // describe('Element .cta-reset-filter', () => {
  //   it('should call resetFilter() on click', () => {
  //     spyOn(spectator.component, 'resetFilter');
  //     spectator.click('.cta-reset-filter');
  //     expect(spectator.component.resetFilter).toHaveBeenCalled();
  //   });
  // });

  // describe('Element .cta-apply-filter', () => {
  //   it('should call resetFilter() on click', () => {
  //     spyOn(spectator.component, 'applyFilter');
  //     spectator.click('.cta-apply-filter');
  //     expect(spectator.component.applyFilter).toHaveBeenCalled();
  //   });
  // });

  // describe('Element ui-filter', () => {
  //   it('should call applyFilter() when on search', () => {
  //     spyOn(spectator.component, 'applyFilter');
  //     spectator.triggerEventHandler('ui-filter', 'search', undefined);
  //     expect(spectator.component.applyFilter).toHaveBeenCalled();
  //   });
  // });
});
