import { DomainGoodsService } from '@domain/oms';
import { createServiceFactory, mockProvider, SpectatorService } from '@ngneat/spectator';
import { QuerySettingsDTO } from '@swagger/oms';
import { UiFilter } from '@ui/filter';
import { isObservable } from 'rxjs';
import { GoodsInSearchStore } from './goods-in-search.store';

describe('GoodsInSearchStore', () => {
  let spectator: SpectatorService<GoodsInSearchStore>;
  const createService = createServiceFactory({
    service: GoodsInSearchStore,
    providers: [mockProvider(DomainGoodsService, {})],
  });

  let goodsInSearchMock: jasmine.SpyObj<DomainGoodsService>;

  beforeEach(() => {
    spectator = createService();
    goodsInSearchMock = spectator.inject(DomainGoodsService);
  });

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

  // describe('get defaultSettings()', () => {
  //   it('should return the defaultSettings from the component store', () => {
  //     const settings: QuerySettingsDTO = {
  //       filter: [],
  //       input: [],
  //     };

  //     spectator.service.patchState({ defaultSettings: settings });

  //     expect(spectator.service.defaultSettings).toBe(settings);
  //   });
  // });

  describe('get filter()', () => {
    it('shoudl return the filter from the component store', () => {
      const filter = UiFilter.create({});
      spectator.service.patchState({ filter });
      expect(spectator.service.filter).toBe(filter);
    });
  });

  // describe('get results()', () => {
  //   it('shoudl return the filter from the component store', () => {
  //     const results = [];
  //     spectator.service.patchState({ results });
  //     expect(spectator.service.results).toBe(results);
  //   });
  // });

  describe('searchResult$', () => {
    it('should be an observable', () => {
      expect(isObservable(spectator.service.searchResult$)).toBe(true);
    });

    it('should return a value when _searchResultSubject emits a value', () => {
      const next = { error: false };
      let result;
      spectator.service.searchResult$.subscribe((res) => (result = res));

      spectator.service['_searchResultSubject'].next(next);

      expect(result).toBe(next);
    });
  });

  // describe('effect loadSettings', () => {
  //   it('should call DomainGoodsInService.querySettings()', () => {
  //     spectator.service.loadSettings();

  //     expect(goodsInSearchMock.querySettings).toHaveBeenCalled();
  //   });
  // });
});
