import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator';
import { GoodsInSearchResultsComponent } from './goods-in-search-results.component';
import { BehaviorSubject, of } from 'rxjs';
import { UiCommonModule } from '@ui/common';
// import { GoodsInSearchService } from '../goods-in-search.service';
import { RouterTestingModule } from '@angular/router/testing';
import { GoodsInSearchStore } from '../goods-in-search.store';
import { BreadcrumbService } from '@core/breadcrumb';

describe('GoodsInSearchResultsComponent', () => {
  let spectator: Spectator<GoodsInSearchResultsComponent>;
  let goodsInSearchStore: GoodsInSearchStore;
  const createComponent = createComponentFactory({
    component: GoodsInSearchResultsComponent,
    imports: [UiCommonModule, RouterTestingModule],
    providers: [
      mockProvider(BreadcrumbService, {
        getBreadcrumbsByKeyAndTags$: async () => {},
      }),
      mockProvider(GoodsInSearchStore, {
        results$: new BehaviorSubject({ error: false }),
        fetching$: new BehaviorSubject<boolean>(false),
        search: async () => {},
        loadSettings: async () => {},
      }),
    ],
  });

  beforeEach(() => {
    spectator = createComponent();
    goodsInSearchStore = spectator.inject(GoodsInSearchStore);
  });

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

  // describe('loading$', () => {
  //   it('should render the UiLoaderComponent if loading$ is true', () => {
  //     spectator.component.loading$.next(true);
  //     spectator.detectComponentChanges();
  //     expect(spectator.query('.loading-text')).toBeVisible();
  //   });
  // });

  // describe('checkIfReload()', () => {
  //   it('should call GoodsInFilterService.search() if HTML Element contains the class last and itemLength < hits', async () => {
  //     const ele = document.createElement('div');
  //     ele.classList.add('last');
  //     spectator.component.hits$ = of(6);
  //     spectator.component.items$ = of(new Array(5));
  //     spectator.detectComponentChanges();
  //     await spectator.component.checkIfReload(ele);
  //     expect(goodsInSearchService.search).toHaveBeenCalled();
  //   });

  //   it('should not call GoodsInFilterService.search() if itemLength >= hits', async () => {
  //     const ele = document.createElement('div');
  //     ele.classList.add('last');
  //     spectator.component.hits$ = of(5);
  //     spectator.component.items$ = of(new Array(6));
  //     spectator.detectComponentChanges();
  //     await spectator.component.checkIfReload(ele);
  //     expect(goodsInSearchService.search).not.toHaveBeenCalled();
  //   });

  //   it('should not call GoodsInFilterService.search() if HTML Element does not contain the class last', async () => {
  //     const ele = document.createElement('div');
  //     spectator.component.hits$ = of(6);
  //     spectator.component.items$ = of(new Array(5));
  //     spectator.detectComponentChanges();
  //     await spectator.component.checkIfReload(ele);
  //     expect(goodsInSearchService.search).not.toHaveBeenCalled();
  //   });
  // });
});
