import { DomainGoodsService } from '@domain/oms';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator';
import { UiInput, UiInputType } from '@ui/filter';
import { cold, hot } from 'jasmine-marbles';
import { of } from 'rxjs';
import { GoodsInSearchMainAutocompleteProvider } from './goods-in-search-main-autocomplete.provider';

describe('GoodsInSearchMainAutocompleteProvider', () => {
  let spectator: SpectatorService<GoodsInSearchMainAutocompleteProvider>;
  let domainGoodsInServiceMock: jasmine.SpyObj<DomainGoodsService>;
  const createProvider = createServiceFactory({
    service: GoodsInSearchMainAutocompleteProvider,
    mocks: [DomainGoodsService],
  });

  beforeEach(() => {
    spectator = createProvider();
    domainGoodsInServiceMock = spectator.inject(DomainGoodsService);
  });

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

  it('should have the value "main" for the property for', () => {
    expect(spectator.service.for).toBe('main');
  });

  // describe('complete(input: UiInput)', () => {
  //   it('should call DomainGoodsInService.complete with the UiInput.value as input', () => {
  //     domainGoodsInServiceMock.complete.and.returnValue(of({ result: [] }));
  //     spectator.service.complete(UiInput.create({ value: 'my value', type: UiInputType.Text }));
  //     expect(domainGoodsInServiceMock.complete).toHaveBeenCalledWith({ input: 'my value', take: 5 });
  //   });

  //   it('should map the response to the response.result', () => {
  //     const result = [{ display: 'display 1' }, { display: 'display 1' }];
  //     domainGoodsInServiceMock.complete.and.returnValue(hot('-(a|)', { a: { result } }));
  //     expect(spectator.service.complete(UiInput.create({ value: 'my value', type: UiInputType.Text }))).toBeObservable(
  //       cold('-(a|)', { a: result })
  //     );
  //   });

  //   it('should catch the error', () => {
  //     domainGoodsInServiceMock.complete.and.returnValue(hot('-#', {}, new Error()));
  //     expect(spectator.service.complete(UiInput.create({ value: 'my value', type: UiInputType.Text }))).toBeObservable(
  //       cold('-(a|)', { a: [] })
  //     );
  //   });
  // });
});
