import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { RemissionListComponent } from './remission-list.component';
import { of } from 'rxjs';
import { RemissionClientModule } from '../../remission-client.module';
import { RemissionService } from '@isa/remission';
import { remissionProcess } from '../../mocks';

class MockRemissionService {
  updateRemissionFilter() {
    return of();
  }
}

describe('RemissionListComponent', () => {
  let component: RemissionListComponent;
  let fixture: ComponentFixture<RemissionListComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [RemissionClientModule],
      providers: [{ provide: RemissionService, useClass: MockRemissionService }],
    }).overrideTemplate(RemissionListComponent, `<div></div>`);
  }));

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

    component.pageSize = 10;
    component.totalHits = 9;
    component.products = [];
    component.remissionProcess = remissionProcess;
  });

  describe('subscribeToFetchLastProducts', () => {
    it('should call fetchProductsBySkipAndTake', () => {
      spyOn(component, 'fetchProductsBySkipAndTake').and.callFake(() => of());
      component.ngOnInit();

      component.fetchLastProducts$.next();

      expect(component.fetchProductsBySkipAndTake).toHaveBeenCalledWith(0, 10);
    });
  });
});
