import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NgxsModule } from '@ngxs/store';
import { SearchStateFacade } from '@shelf-store';
import { AppService } from '@sales/core-services';
import { ShelfSearchComponent } from './shelf-search.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { WindowRef } from 'apps/native-container/src/lib';

fdescribe('ShelfSearchComponent', () => {
  let fixture: ComponentFixture<ShelfSearchComponent>;
  let component: ShelfSearchComponent;
  let searchFacade: jasmine.SpyObj<SearchStateFacade>;

  beforeEach(async () => {
    TestBed.configureTestingModule({
      imports: [NgxsModule.forRoot([])],
      providers: [
        {
          provide: SearchStateFacade,
          useValue: jasmine.createSpyObj('searchStateFacade', {
            setPendingInput: () => {},
            resetPrimaryFilters: () => {},
            resetSelectedFilters: () => {},
          }),
        },
        WindowRef,
        {
          provide: AppService,
          useValue: jasmine.createSpyObj('appService', {
            isIPadEnv: () => false,
          }),
        },
      ],
      declarations: [ShelfSearchComponent],
      schemas: [NO_ERRORS_SCHEMA],
    });
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(ShelfSearchComponent);
    component = fixture.componentInstance;
    searchFacade = TestBed.inject(SearchStateFacade);

    spyOn(component, 'restoreInitialState').and.callThrough();

    fixture.detectChanges();
  });

  it('should be created', () => {
    expect(component instanceof ShelfSearchComponent).toBeTruthy();
  });

  it('should restore the initial state on page load (onInit)', () => {
    expect(component.restoreInitialState).toHaveBeenCalledTimes(1);
  });

  it('should reset the pending input on page load (onInit)', () => {
    expect(searchFacade.setPendingInput).toHaveBeenCalledWith('');
  });

  it('should reset the filters on page load (onInit)', () => {
    expect(searchFacade.resetPrimaryFilters).toHaveBeenCalled();
    expect(searchFacade.resetSelectedFilters).toHaveBeenCalled();
  });
});
