// import { CommonModule } from '@angular/common';
// import { HttpClient } from '@angular/common/http';
// import { FormsModule } from '@angular/forms';
// import { AuthService } from '@core/auth';
// import { DomainAvailabilityService } from '@domain/availability';
// import { createComponentFactory, Spectator } from '@ngneat/spectator';
// import { UiAutocompleteModule } from '@ui/autocomplete';
// import { UiCommonModule } from '@ui/common';
// import { UiIconModule } from '@ui/icon';
// import { UiModalService } from '@ui/modal';
// import { BranchSelectorComponent } from './branch-selector.component';
// import { BranchSelectorStore } from './branch-selector.store';
// import { EmptyIconLoader, IconLoader, provideIcon } from '@shared/components/icon';

// describe('BranchSelectorComponent', () => {
//   let spectator: Spectator<BranchSelectorComponent>;
//   let branchSelectorStoreMock: jasmine.SpyObj<BranchSelectorStore>;

//   const createComponent = createComponentFactory({
//     component: BranchSelectorComponent,
//     imports: [UiCommonModule, CommonModule, FormsModule, UiIconModule, UiAutocompleteModule],
//     mocks: [DomainAvailabilityService, UiModalService, HttpClient, AuthService],
//     providers: [provideIcon({ provide: IconLoader, useClass: EmptyIconLoader })],
//   });

//   beforeEach(() => {
//     spectator = createComponent();
//     branchSelectorStoreMock = spectator.inject(BranchSelectorStore, true);
//   });

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

//   describe('value', () => {
//     it('should call setBranch(value)', () => {
//       const value = { id: 1 };
//       const setBranchSpy = spyOn(spectator.component, 'setBranch');
//       spectator.component.value = value;
//       expect(setBranchSpy).toHaveBeenCalledWith(value);
//     });
//   });

//   describe('disabled', () => {
//     it('should set disabled based on Input value', () => {
//       const disabled = true;
//       spectator.setInput('disabled', disabled);
//       expect(spectator.component.disabled).toBe(disabled);
//     });
//   });

//   // describe('branchType', () => {
//   //   it('should set branchType based on Input value', () => {
//   //     const branchType = 4;
//   //     spectator.setInput('branchType', branchType);
//   //     expect(spectator.component.branchType).toBe(branchType);
//   //   });
//   // });

//   describe('registerOnChange()', () => {
//     it('should assign new fn to onChange', () => {
//       const newFn = () => {};
//       spectator.component.registerOnChange(newFn);
//       expect(spectator.component.onChange).toEqual(newFn);
//     });
//   });

//   describe('registerOnTouched()', () => {
//     it('should assign new fn to onTouched', () => {
//       const newFn = () => {};
//       spectator.component.registerOnTouched(newFn);
//       expect(spectator.component.onTouched).toEqual(newFn);
//     });
//   });

//   describe('setDisabledState()', () => {
//     it('should assign new value to disabled', () => {
//       const newValue = true;
//       spectator.component.setDisabledState(newValue);
//       expect(spectator.component.disabled).toBe(newValue);
//     });
//   });

//   describe('ngOnInit()', () => {
//     it('should call store.loadBranches()', () => {
//       spyOn(branchSelectorStoreMock, 'loadBranches');
//       spectator.component.ngOnInit();
//       expect(branchSelectorStoreMock.loadBranches).toHaveBeenCalled();
//     });
//   });

//   describe('ngAfterViewInit()', () => {
//     it('should call initAutocomplete()', () => {
//       const initAutocompleteSpy = spyOn(spectator.component, 'initAutocomplete');
//       spectator.component.ngAfterViewInit();
//       expect(initAutocompleteSpy).toHaveBeenCalled();
//     });
//   });

//   describe('initAutocomplete()', () => {
//     // it('should call complete.asObservable()', () => {
//     //   const completeSpy = spyOn(spectator.component.complete, 'asObservable').and.returnValue(of('test'));
//     //   spectator.component.initAutocomplete();
//     //   expect(completeSpy).toHaveBeenCalled();
//     // });
//     // it('should call filterBranchesFn({ query, branches })', () => {
//     //   const branches = [{ id: 1 }, { id: 2 }];
//     //   const query = 'Test';
//     //   branchSelectorStoreMock.setBranches(branches);
//     //   const filterBranchesFnSpy = spyOn(spectator.component, 'filterBranchesFn');
//     //   spectator.component.initAutocomplete();
//     //   spectator.component.branches$.pipe(take(1)).subscribe(() => {
//     //     expect(filterBranchesFnSpy).toHaveBeenCalledWith({ query, branches });
//     //   });
//     //   spectator.component.complete.next(query);
//     // });
//     // it('should call sortAutocompleteFn with BranchDTO[]', () => {
//     //   const branches = [{ id: 1 }, { id: 2 }];
//     //   const query = 'Test';
//     //   spyOn(spectator.component, 'initAutocompleteFn').and.returnValue(branches);
//     //   const sortAutocompleteFnSpy = spyOn(spectator.component, 'sortAutocompleteFn');
//     //   spectator.component.initAutocomplete();
//     //   spectator.component.complete.next(query);
//     //   expect(sortAutocompleteFnSpy).toHaveBeenCalledWith(branches);
//     // });
//   });

//   // describe('initAutocompleteFn()', () => {
//   //   it('should call filterAutocompleteFn({ query, branches }) if query.length > 1', () => {
//   //     const query = 'test';
//   //     const branches = [{ id: 1 }, { id: 2 }];

//   //     spectator.component.initAutocompleteFn({ query, branches });
//   //     expect(spectator.component.complete.asObservable).toHaveBeenCalled();
//   //   });

//   //   it('should not call filterAutocompleteFn({ query, branches }) if query.length <= 1 and return branches', () => {});
//   // });

//   //   describe('filterAutocompleteFn()', () => {});

//   //   it('should not emit search with the current query when key is ArrowUp or ArrowDown', () => {
//   //     spectator.component.query = 'my query';
//   //     let searchResult;
//   //     spectator.output('search').subscribe((search) => (searchResult = search));
//   //     spectator.component.onKeyup(new KeyboardEvent('', { key: 'ArrowUp' }));
//   //     spectator.component.onKeyup(new KeyboardEvent('', { key: 'ArrowDown' }));
//   //     expect(searchResult).toBeUndefined();
//   //   });

//   //   it('should call handleArrowUpDownEvent when key is ArrowUp', () => {
//   //     spyOn(spectator.component, 'handleArrowUpDownEvent');
//   //     spectator.component.onKeyup(new KeyboardEvent('', { key: 'ArrowUp' }));
//   //     expect(spectator.component.handleArrowUpDownEvent).toHaveBeenCalled();
//   //   });

//   //   it('should call handleArrowUpDownEvent when key is ArrowDown', () => {
//   //     spyOn(spectator.component, 'handleArrowUpDownEvent');
//   //     spectator.component.onKeyup(new KeyboardEvent('', { key: 'ArrowDown' }));
//   //     expect(spectator.component.handleArrowUpDownEvent).toHaveBeenCalled();
//   //   });

//   //   it('should not call handleArrowUpDownEvent when key is Enter', () => {
//   //     spyOn(spectator.component, 'handleArrowUpDownEvent');
//   //     spectator.component.onKeyup(new KeyboardEvent('', { key: 'Enter' }));
//   //     expect(spectator.component.handleArrowUpDownEvent).not.toHaveBeenCalled();
//   //   });
//   // });

//   // describe('with autocomplete', () => {
//   //   const testItems = [
//   //     { name: 'testbranch1', key: 'testkey1' },
//   //     { name: 'testbranch2', key: 'testkey2' },
//   //   ];

//   //   beforeEach(() => {
//   //     spectator = createHostWithAutocomplete(undefined, {
//   //       hostProps: {
//   //         items: testItems,
//   //       },
//   //     });
//   //   });

//   //   describe('handleArrowUpDownEvent', () => {
//   //     it('should call handleKeyboardEvent with the event', () => {
//   //       const event = new KeyboardEvent('keyup');
//   //       spyOn(spectator.component.autocompleteComponent, 'handleKeyboardEvent');
//   //       spectator.component.handleArrowUpDownEvent(event);

//   //       expect(spectator.component.autocompleteComponent.handleKeyboardEvent).toHaveBeenCalledWith(event);
//   //     });

//   //     it('should call setQuery when autocomplete.selectedItem is set', () => {
//   //       const event = new KeyboardEvent('keyup');
//   //       spyOn(spectator.component, 'setQuery');

//   //       spectator.component.autocompleteComponent.listKeyManager.setFirstItemActive();

//   //       spectator.component.handleArrowUpDownEvent(event);
//   //       expect(spectator.component.setQuery).toHaveBeenCalledWith(testItems[0].key + ' - ' + testItems[0].name);
//   //     });
//   //   });
//   // });
// });
