import { ShelfFilterComponent } from './shelf-filter.component';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA, Renderer2, ChangeDetectorRef } from '@angular/core';
import { ShelfFilterService } from '../../services';
import { IsaOverlayRef } from 'apps/sales/src/app/core/overlay';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

fdescribe('ShelfFilterComponent', () => {
  let fixture: ComponentFixture<ShelfFilterComponent>;
  let component: ShelfFilterComponent;
  let filterService: jasmine.SpyObj<ShelfFilterService>;

  beforeEach(async () => {
    TestBed.configureTestingModule({
      imports: [NoopAnimationsModule],
      providers: [
        { provide: IsaOverlayRef, useValue: jasmine.createSpy('overlayRef') },
        Renderer2,
        ChangeDetectorRef,
        {
          provide: ShelfFilterService,
          useValue: jasmine.createSpyObj('filterService', ['resetPrimaryFilters', 'resetSelectedFilters']),
        },
      ],
      declarations: [ShelfFilterComponent],
      schemas: [NO_ERRORS_SCHEMA],
    }).compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(ShelfFilterComponent);
    component = fixture.componentInstance;
    filterService = TestBed.inject(ShelfFilterService);
  });

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

  describe('onResetFilters', () => {
    beforeEach(() => {
      spyOn(component, 'onResetFilters').and.callThrough();
      filterService.resetPrimaryFilters.and.callFake(() => {});
      filterService.resetSelectedFilters.and.callFake(() => {});

      component.resetStrategy = 'default';
      fixture.detectChanges();
    });

    it('should call the filter service to reset the selected filters', () => {
      component.onResetFilters();

      expect(filterService.resetSelectedFilters).toHaveBeenCalled();
    });

    it('should not reset the primary filters', () => {
      component.onResetFilters();

      expect(filterService.resetPrimaryFilters).not.toHaveBeenCalled();
    });
  });
});
