// import { AuthService } from '@core/auth';
// import { DomainAvailabilityService } from '@domain/availability';
// import { OpenStreetMap } from '@external/openstreetmap';
// import { createServiceFactory, createSpyObject, SpectatorService, SpyObject } from '@ngneat/spectator';
// import { BranchType } from '@generated/swagger/checkout-api';
// import { UiErrorModalComponent, UiModalService } from '@ui/modal';
// import { of, throwError } from 'rxjs';
// import { BranchSelectorStore } from './branch-selector.store';

// describe('BranchSelectorStore', () => {
//   let spectator: SpectatorService<BranchSelectorStore>;
//   let availabilityServiceMock: SpyObject<DomainAvailabilityService>;
//   let uiModalServiceMock: SpyObject<UiModalService>;

//   const createService = createServiceFactory({
//     service: BranchSelectorStore,
//     mocks: [OpenStreetMap, AuthService],
//   });

//   beforeEach(() => {
//     availabilityServiceMock = createSpyObject(DomainAvailabilityService);
//     availabilityServiceMock.getBranches.and.returnValue(of([]));
//     availabilityServiceMock.getDefaultBranch.and.returnValue(of({}));

//     uiModalServiceMock = createSpyObject(UiModalService);

//     uiModalServiceMock = createSpyObject(UiModalService);

//     spectator = createService({
//       providers: [
//         { provide: DomainAvailabilityService, useValue: availabilityServiceMock },
//         { provide: UiModalService, useValue: uiModalServiceMock },
//       ],
//     });
//   });

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

//   describe('get query', () => {
//     it('should return the query', () => {
//       const query = 'test';
//       spectator.service.setQuery(query);
//       expect(spectator.service.query).toBe(query);
//     });
//   });

//   describe('get query$', () => {
//     it('should return the query$', () => {
//       const query = 'test';
//       spectator.service.setQuery(query);

//       spectator.service.query$
//         .subscribe((q) => {
//           expect(q).toBe(query);
//         })
//         .unsubscribe();
//     });
//   });

//   describe('get fetching', () => {
//     it('should return the fetching', () => {
//       const fetching = true;
//       spectator.service.setFetching(fetching);
//       expect(spectator.service.fetching).toBe(fetching);
//     });
//   });

//   describe('get fetching$', () => {
//     it('should return the fetching$', () => {
//       const fetching = true;
//       spectator.service.setFetching(fetching);

//       spectator.service.fetching$
//         .subscribe((f) => {
//           expect(f).toBe(fetching);
//         })
//         .unsubscribe();
//     });
//   });

//   // describe('get branches', () => {
//   //   it('should return the branches', () => {
//   //     const branches = [{}, {}];
//   //     spectator.service.setBranches(branches);
//   //     expect(spectator.service.branches).toBe(branches);
//   //   });
//   // });

//   // describe('get branches$', () => {
//   //   it('should return the branches$', () => {
//   //     const branches = [{}, {}];
//   //     spectator.service.setBranches(branches);

//   //     spectator.service.branches$
//   //       .subscribe((b) => {
//   //         expect(b).toBe(branches);
//   //       })
//   //       .unsubscribe();
//   //   });
//   // });

//   describe('get selectedBranch', () => {
//     it('should return the selectedBranch', () => {
//       const selectedBranch = { id: 123 };
//       spectator.service.setSelectedBranch(selectedBranch);
//       expect(spectator.service.selectedBranch).toEqual(selectedBranch);
//     });
//   });

//   describe('get selectedBranch$', () => {
//     it('should return the selectedBranch$', () => {
//       const selectedBranch = { id: 123 };
//       spectator.service.setSelectedBranch(selectedBranch);

//       spectator.service.selectedBranch$
//         .subscribe((sb) => {
//           expect(sb).toEqual(selectedBranch);
//         })
//         .unsubscribe();
//     });
//   });

//   // describe('get branchType', () => {
//   //   it('should return the branchType', () => {
//   //     const branchType = 1;
//   //     spectator.service.setBranchType(branchType);
//   //     expect(spectator.service.branchType).toEqual(branchType);
//   //   });
//   // });

//   // describe('get branchType$', () => {
//   //   it('should return the branchType$', () => {
//   //     const branchType = 1;
//   //     spectator.service.setBranchType(branchType);

//   //     spectator.service.branchType$
//   //       .subscribe((bt) => {
//   //         expect(bt).toEqual(branchType);
//   //       })
//   //       .unsubscribe();
//   //   });
//   // });

//   describe('loadBranches', () => {
//     const branches = [{ id: 1 }, { id: 2 }];

//     beforeEach(() => {
//       availabilityServiceMock.getBranches.and.returnValue(of(branches));
//     });

//     it('should call setFetching(true)', () => {
//       spyOn(spectator.service, 'setFetching');
//       spectator.service.loadBranches();
//       expect(spectator.service.setFetching).toHaveBeenCalledWith(true);
//     });

//     it('should call _availabilityService.getBranches()', () => {
//       spectator.service.loadBranches();
//       expect(availabilityServiceMock.getBranches).toHaveBeenCalled();
//     });

//     it('should call loadBranchesResponseFn({ response, selectedBranch, branchType, currentBranch })', () => {
//       const selectedBranch = { id: 123 };
//       const branchType = 1;
//       const currentBranch = { id: 9 };
//       availabilityServiceMock.getDefaultBranch.and.returnValue(of(currentBranch));
//       spectator.service.setSelectedBranch(selectedBranch);
//       spectator.service.setBranchType(branchType);
//       const loadBranchesResponseFnSpy = spyOn(spectator.service, 'loadBranchesResponseFn');
//       spectator.service.loadBranches();
//       expect(loadBranchesResponseFnSpy).toHaveBeenCalledWith({ response: branches, selectedBranch });
//     });

//     it('should call loadBranchesErrorFn(error) if error got thrown', () => {
//       const error = new Error('Error message');
//       const loadBranchesErrorFnSpy = spyOn(spectator.service, 'loadBranchesErrorFn');
//       availabilityServiceMock.getBranches.and.returnValue(throwError(error));
//       spectator.service.loadBranches();
//       expect(loadBranchesErrorFnSpy).toHaveBeenCalledWith(error);
//     });
//   });

//   describe('loadBranchesResponseFn()', () => {
//     let branches = [];
//     let branchType: BranchType = 1;

//     beforeEach(() => {
//       branches = [
//         { id: 1, branchType: 1 },
//         { id: 2, branchType: 1 },
//       ];
//       branchType = 1;
//     });

//     // it('should call _filter({ branches: response })', () => {
//     //   const filterBranchesSpy = spyOn<any>(spectator.service, '_filter');
//     //   spectator.service.loadBranchesResponseFn({ response: branches });
//     //   expect(filterBranchesSpy).toHaveBeenCalledWith({ branches });
//     // });

//     // it('should call setBranches() with branches after filtering', () => {
//     //   spyOn<any>(spectator.service, '_filter').and.returnValue([{ id: 1 }]);
//     //   const setBranchesSpy = spyOn(spectator.service, 'setBranches');
//     //   spectator.service.loadBranchesResponseFn({ response: branches });
//     //   expect(setBranchesSpy).toHaveBeenCalledWith([{ id: 1 }]);
//     // });

//     // it('should call setBranches() with default [] if getBranches() return undefined', () => {
//     //   spyOn<any>(spectator.service, '_filter').and.returnValue([]);
//     //   const setBranchesSpy = spyOn(spectator.service, 'setBranches');
//     //   spectator.service.loadBranchesResponseFn({ response: branches });
//     //   expect(setBranchesSpy).toHaveBeenCalledWith([]);
//     // });

//     it('should call setSelectedBranchId(selectedBranchId) if selectedBranch is set', () => {
//       const selectedBranch = { id: 123 };
//       const setSelectedBranchSpy = spyOn(spectator.service, 'setSelectedBranch');
//       spectator.service.loadBranchesResponseFn({ response: branches, selectedBranch });
//       expect(setSelectedBranchSpy).toHaveBeenCalledWith(selectedBranch);
//     });

//     it('should not call setSelectedBranch(selectedBranch) if selectedBranch is not set', () => {
//       const setSelectedBranchSpy = spyOn(spectator.service, 'setSelectedBranch');
//       spectator.service.loadBranchesResponseFn({ response: branches });
//       expect(setSelectedBranchSpy).not.toHaveBeenCalled();
//     });

//     it('should call setFetching(false)', () => {
//       const setFetchingSpy = spyOn(spectator.service, 'setFetching');
//       spectator.service.loadBranchesResponseFn({ response: branches });
//       expect(setFetchingSpy).toHaveBeenCalledWith(false);
//     });
//   });

//   describe('loadBranchesErrorFn()', () => {
//     it('should call uiModalServiceMock.open with appropriate UiErrorModal data', () => {
//       const error = new Error('test');
//       spectator.service.loadBranchesErrorFn(error);
//       expect(uiModalServiceMock.open).toHaveBeenCalledWith({
//         title: 'Fehler beim Laden der Filialen',
//         content: UiErrorModalComponent,
//         data: error,
//         config: { showScrollbarY: false },
//       });
//     });
//   });

//   describe('setSelectedBranch()', () => {
//     it('should call patchState with empty query and undefined selectedBranch if function call without arguments', () => {
//       const patchStateSpy = spyOn(spectator.service, 'patchState');
//       spectator.service.setSelectedBranch();
//       expect(patchStateSpy).toHaveBeenCalledWith({ selectedBranch: undefined, query: '' });
//     });

//     it('should call formatBranch(selectedBranch) if function call with selectedBranch', () => {
//       const selectedBranch = { id: 123 };
//       const formatBranchBySpy = spyOn(spectator.service, 'formatBranch');
//       spectator.service.setSelectedBranch(selectedBranch);
//       expect(formatBranchBySpy).toHaveBeenCalledWith(selectedBranch);
//     });

//     it('should call patchState({ selectedBranch, query: this.formatBranch(selectedBranch) }) if function call with selectedBranch', () => {
//       const selectedBranch = { id: 123 };
//       const query = 'test-branch';
//       spyOn(spectator.service, 'formatBranch').and.returnValue(query);
//       const patchStateSpy = spyOn(spectator.service, 'patchState');
//       spectator.service.setSelectedBranch(selectedBranch);
//       expect(patchStateSpy).toHaveBeenCalledWith({ selectedBranch, query });
//     });
//   });

//   describe('setQuery()', () => {
//     it('should call patchState with query', () => {
//       const query = 'test';
//       spyOn(spectator.service, 'patchState');
//       spectator.service.setQuery(query);
//       expect(spectator.service.patchState).toHaveBeenCalledWith({ query });
//     });
//   });

//   describe('setBranches()', () => {
//     it('should call patchState with branches', () => {
//       const branches = [{ id: 1 }, { id: 2 }];
//       spyOn(spectator.service, 'patchState');
//       spectator.service.setBranches(branches);
//       expect(spectator.service.patchState).toHaveBeenCalledWith({ branches });
//     });
//   });

//   describe('setFetching()', () => {
//     it('should call patchState with fetching', () => {
//       const fetching = true;
//       spyOn(spectator.service, 'patchState');
//       spectator.service.setFetching(fetching);
//       expect(spectator.service.patchState).toHaveBeenCalledWith({ fetching });
//     });
//   });

//   describe('formatBranch()', () => {
//     it('should return a formatted branch with key', () => {
//       const branch = {
//         id: 1,
//         name: 'Test',
//         key: 'T',
//       };
//       const formattedString = spectator.service.formatBranch(branch);
//       expect(formattedString).toBe('T - Test');
//     });

//     it('should return a formatted branch without key', () => {
//       const branch = {
//         id: 1,
//         name: 'Test',
//       };
//       const formattedString = spectator.service.formatBranch(branch);
//       expect(formattedString).toBe('Test');
//     });

//     it('should return an empty string if called without branch', () => {
//       const formattedString = spectator.service.formatBranch();
//       expect(formattedString).toBe('');
//     });
//   });

//   // describe('_filter()', () => {
//   //   it('should return branches based on filter criterias', () => {
//   //     const branches = [
//   //       {
//   //         id: 1,
//   //         branchType: 2 as BranchType,
//   //       },
//   //       {
//   //         id: 2,
//   //         isOnline: true,
//   //         isShippingEnabled: true,
//   //         isOrderingEnabled: true,
//   //         branchType: 1 as BranchType,
//   //       },
//   //     ];
//   //     const branchType: BranchType = 1;

//   //     expect(spectator.service['_filter']({ branches, branchType })).toEqual([branches[1]]);
//   //   });
//   // });
// });
