// import { Spectator, createComponentFactory } from '@ngneat/spectator';
// import { ShellProcessBarItemComponent } from './process-bar-item.component';
// import { Breadcrumb, BreadcrumbService } from '@core/breadcrumb';
// import { ApplicationProcess, ApplicationService } from '@core/application';
// import { RouterTestingModule } from '@angular/router/testing';
// import { TestScheduler } from 'rxjs/testing';
// import { NEVER, of } from 'rxjs';
// import { Router } from '@angular/router';
// import { MockComponent } from 'ng-mocks';
// import { UISvgIconComponent } from '@ui/icon';
// import { DomainCheckoutService } from '@domain/checkout';
// import { UiModalService } from '@ui/modal';

// describe('ShellProcessBarItemComponent', () => {
//   let testScheduler: TestScheduler;
//   let spectator: Spectator<ShellProcessBarItemComponent>;
//   const createComponent = createComponentFactory({
//     component: ShellProcessBarItemComponent,
//     mocks: [DomainCheckoutService, UiModalService],
//     imports: [RouterTestingModule],
//     declarations: [MockComponent(UISvgIconComponent)],
//   });

//   let breadcrumbService: jasmine.SpyObj<BreadcrumbService>;
//   let applicationService: jasmine.SpyObj<ApplicationService>;
//   let router: Router;

//   beforeEach(() => {
//     breadcrumbService = jasmine.createSpyObj<BreadcrumbService>(['getLastActivatedBreadcrumbByKey$', 'getLatestBreadcrumbForSection']);
//     breadcrumbService.getLastActivatedBreadcrumbByKey$.and.returnValue(NEVER);

//     applicationService = jasmine.createSpyObj<ApplicationService>(['getSection$', 'removeProcess']);

//     spectator = createComponent({
//       providers: [
//         { provide: BreadcrumbService, useValue: breadcrumbService },
//         { provide: ApplicationService, useValue: applicationService },
//       ],
//     });

//     router = spectator.inject(Router);

//     testScheduler = new TestScheduler((actual, expected) => {
//       expect(actual).toEqual(expected);
//     });
//   });

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

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

//     it('should call initRouterLink$', () => {
//       spyOn(spectator.component, 'initRouterLink$');
//       spectator.component.ngOnInit();
//       expect(spectator.component.initRouterLink$).toHaveBeenCalled();
//     });

//     it('sould call initQueryParams$', () => {
//       spyOn(spectator.component, 'initQueryParams$');
//       spectator.component.ngOnInit();
//       expect(spectator.component.initQueryParams$).toHaveBeenCalled();
//     });

//     it('should call initIsActive$', () => {
//       spyOn(spectator.component, 'initIsActive$');
//       spectator.component.ngOnInit();
//       expect(spectator.component.initIsActive$).toHaveBeenCalled();
//     });

//     it('should call initShowCloseButton$', () => {
//       spyOn(spectator.component, 'initShowCloseButton$');
//       spectator.component.ngOnInit();
//       expect(spectator.component.initShowCloseButton$).toHaveBeenCalled();
//     });
//   });

//   describe('initLatestBreadcrumb$', () => {
//     it('should create an observable that emits the latest breadcrumb for the current process', () => {
//       testScheduler.run(({ cold, expectObservable }) => {
//         const process = { id: 123 } as ApplicationProcess;
//         spectator.component.process$ = cold('-a', { a: process });

//         const breadcrumb: Breadcrumb = { id: 0, key: '', name: '', section: '', path: 'test' };
//         breadcrumbService.getLastActivatedBreadcrumbByKey$.and.returnValue(cold('-a', { a: breadcrumb }));

//         spectator.component.initLatestBreadcrumb$();

//         expectObservable(spectator.component.latestBreadcrumb$).toBe('--a', { a: breadcrumb });
//       });
//     });
//   });

//   describe('initRouterLink$', () => {
//     it('should create an observable that emits the path of the latest breadcrumb', () => {
//       testScheduler.run(({ cold, expectObservable }) => {
//         const breadcrumb: Breadcrumb = { id: 0, key: '', name: '', section: '', path: 'test' };
//         spectator.component.latestBreadcrumb$ = cold('-a', { a: breadcrumb });
//         spectator.component.initRouterLink$();
//         expectObservable(spectator.component.routerLink$).toBe('-a', { a: [breadcrumb.path] });
//       });
//     });
//   });

//   describe('initQueryParams$', () => {
//     it('should create an observable that emits the queryParams of the latest breadcrumb', () => {
//       testScheduler.run(({ cold, expectObservable }) => {
//         const breadcrumb: Breadcrumb = { id: 0, key: '', name: '', section: '', path: '', params: { unit: 'test' } };
//         spectator.component.latestBreadcrumb$ = cold('-a', { a: breadcrumb });
//         spectator.component.initQueryParams$();
//         expectObservable(spectator.component.queryParams$).toBe('-a', { a: breadcrumb.params });
//       });
//     });
//   });

//   describe('initIsActive$', () => {
//     it('should create an observable that emits true if the process id is the active process id', () => {
//       testScheduler.run(({ cold, expectObservable }) => {
//         spectator.component.activatedProcessId$ = cold('-a', { a: 123 });
//         spectator.component.process$ = cold('-a', { a: { id: 123 } as ApplicationProcess });

//         spectator.component.initIsActive$();
//         expectObservable(spectator.component.isActive$).toBe('-a', { a: true });
//       });
//     });

//     it('should create an observable that emits false if not the process id is the active process id', () => {
//       testScheduler.run(({ cold, expectObservable }) => {
//         spectator.component.activatedProcessId$ = cold('-a', { a: 123 });
//         spectator.component.process$ = cold('-a', { a: { id: 456 } as ApplicationProcess });

//         spectator.component.initIsActive$();
//         expectObservable(spectator.component.isActive$).toBe('-a', { a: false });
//       });
//     });
//   });

//   describe('initShowCloseButton$', () => {
//     it('should create an observable that emits true if isActive$ is true and the process is closable', () => {
//       testScheduler.run(({ cold, expectObservable }) => {
//         spectator.component.isActive$ = cold('-a', { a: true });

//         const process: ApplicationProcess = { id: 0, name: '', section: 'branch', closeable: true };
//         spectator.component.process$ = cold('-a', { a: process });

//         spectator.component.initShowCloseButton$();
//         expectObservable(spectator.component.showCloseButton$).toBe('-a', { a: true });
//       });
//     });
//   });

//   describe('ngOnDestroy', () => {
//     it('should complete _process$', () => {
//       spectator.component.ngOnDestroy();
//       expect(spectator.component['_process$'].isStopped).toBeTrue();
//     });
//   });

//   describe('close()', () => {
//     it('should call ApplicationService.removeProcess, gets the latest breadcrumb for the current section and calls navigate with the latest breadcrumb', async () => {
//       spectator.component.process = { id: 123, section: 'customer' } as ApplicationProcess;

//       const breadcrumb: Breadcrumb = { id: 0, key: '', name: '', section: '', path: '' };
//       spyOn(spectator.component, 'getLatestBreadcrumbForSection').and.callFake(() => new Promise((resolve) => resolve(breadcrumb)));

//       spyOn(spectator.component, 'navigate');

//       await spectator.component.close();

//       expect(applicationService.removeProcess).toHaveBeenCalledWith(123);
//       expect(spectator.component.getLatestBreadcrumbForSection).toHaveBeenCalled();
//       expect(spectator.component.navigate).toHaveBeenCalledWith(breadcrumb);
//     });

//     it('should call navigate with undefined if getLatestBreadcrumbForSection returns undefined', async () => {
//       spectator.component.process = { id: 123, section: 'customer' } as ApplicationProcess;

//       const breadcrumb: Breadcrumb = undefined;
//       spyOn(spectator.component, 'getLatestBreadcrumbForSection').and.callFake(() => new Promise((resolve) => resolve(breadcrumb)));

//       spyOn(spectator.component, 'navigate');

//       await spectator.component.close();

//       expect(applicationService.removeProcess).toHaveBeenCalledWith(123);
//       expect(spectator.component.getLatestBreadcrumbForSection).toHaveBeenCalled();
//       expect(spectator.component.navigate).toHaveBeenCalledWith(undefined);
//     });
//   });

//   describe('getLatestBreadcrumbForSection', () => {
//     it('should call breadcrumbService.getLastActivatedBreadcrumbByKey$ with the correct key', async () => {
//       spectator.component.process = { id: 123, section: 'customer' } as ApplicationProcess;
//       const breadcrumb: Breadcrumb = { id: 0, key: '', name: '', section: '', path: '' };
//       breadcrumbService.getLatestBreadcrumbForSection.and.returnValue(of(breadcrumb));
//       const result = await spectator.component.getLatestBreadcrumbForSection();
//       expect(breadcrumbService.getLatestBreadcrumbForSection).toHaveBeenCalled();
//       expect(result).toEqual(breadcrumb);
//     });
//   });

//   describe('navigate', () => {
//     it('should call router.navigate with the correct path and queryParams', () => {
//       const breadcrumb: Breadcrumb = { id: 0, key: '', name: '', section: '', path: 'test', params: { unit: 'test' } };
//       spyOn(router, 'navigate');
//       spectator.component.navigate(breadcrumb);
//       expect(router.navigate).toHaveBeenCalledWith([breadcrumb.path], { queryParams: breadcrumb.params });
//     });

//     it('should call router.navigate with ["/kunde/dashboard"]', () => {
//       spyOn(router, 'navigate');
//       spectator.component.navigate();
//       expect(router.navigate).toHaveBeenCalledWith(['/kunde/dashboard']);
//     });
//   });

//   describe('template', () => {
//     describe('.tab-wrapper', () => {
//       it('should not have the class border-surface if isActive$ is true', () => {
//         spectator.component.isActive$ = of(true);
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-wrapper')).not.toHaveClass('border-surface');
//       });

//       it('should have the class border-surface if isActive$ is false', () => {
//         spectator.component.isActive$ = of(false);
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-wrapper')).toHaveClass('border-surface');
//       });

//       it('should have the class border-brand if isActive$ is true', () => {
//         spectator.component.isActive$ = of(true);
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-wrapper')).toHaveClass('border-brand');
//       });

//       it('should not have the class border-brand if isActive$ is false', () => {
//         spectator.component.isActive$ = of(false);
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-wrapper')).not.toHaveClass('border-brand');
//       });
//     });

//     describe('.tab-link', () => {
//       it('should have an href with the path from routerLink$', () => {
//         spectator.component.routerLink$ = of(['test']);
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-link')).toHaveAttribute('href', '/test');
//       });

//       it('should have an href with the path from routerLink$ and the queryParams from queryParams$', () => {
//         spectator.component.routerLink$ = of(['test']);
//         spectator.component.queryParams$ = of({ unit: 'test' });
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-link')).toHaveAttribute('href', '/test?unit=test');
//       });

//       it('should have the process.name as text content', () => {
//         spectator.component.process = { name: 'test' } as ApplicationProcess;
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-link')).toHaveText('test');
//       });
//     });

//     describe('.tab-close-btn', () => {
//       it('should be rendered if showCloseButton$ is true', () => {
//         spectator.component.showCloseButton$ = of(true);
//         spectator.detectComponentChanges();
//         expect(spectator.query('.tab-close-btn')).toExist();
//       });

//       it('should call close() on click', () => {
//         spectator.component.showCloseButton$ = of(true);
//         spectator.detectComponentChanges();
//         spyOn(spectator.component, 'close');
//         spectator.click('.tab-close-btn');
//         expect(spectator.component.close).toHaveBeenCalled();
//       });
//     });
//   });
// });
