mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
#830 Fix Filter Overlay Close Results Cleared Error
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
import {
|
||||
ComponentFixture,
|
||||
TestBed,
|
||||
fakeAsync,
|
||||
tick,
|
||||
} from '@angular/core/testing';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { SearchStateFacade } from '@shelf-store';
|
||||
import { of } from 'rxjs';
|
||||
import {
|
||||
ShelfNavigationService,
|
||||
ShelfSearchFacadeService,
|
||||
} from '../../../shared/services';
|
||||
import { ShelfSearchInputComponent } from './search-input.component';
|
||||
import { ShelfFilterService } from '../../../services';
|
||||
|
||||
class MockSearchStateFacade {
|
||||
constructor() {}
|
||||
|
||||
get hasResults$() {
|
||||
return of(true);
|
||||
}
|
||||
|
||||
get hits$() {
|
||||
return of(3);
|
||||
}
|
||||
|
||||
get input$() {
|
||||
return of('Testsuche');
|
||||
}
|
||||
|
||||
get result$() {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
get fetching$() {
|
||||
return of(false);
|
||||
}
|
||||
|
||||
get showNoResultError$() {
|
||||
return of(true);
|
||||
}
|
||||
|
||||
get selectedFilters$() {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
clearResult() {}
|
||||
|
||||
clearError() {}
|
||||
}
|
||||
|
||||
fdescribe('#SearchInputComponent', () => {
|
||||
let fixture: ComponentFixture<ShelfSearchInputComponent>;
|
||||
let component: ShelfSearchInputComponent;
|
||||
let facade: SearchStateFacade;
|
||||
let navigationService: jasmine.SpyObj<ShelfNavigationService>;
|
||||
let shelfSearchService: jasmine.SpyObj<ShelfSearchFacadeService>;
|
||||
|
||||
beforeEach(async () => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ShelfSearchInputComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: SearchStateFacade,
|
||||
useClass: MockSearchStateFacade,
|
||||
},
|
||||
{
|
||||
provide: ShelfNavigationService,
|
||||
useValue: jasmine.createSpyObj('shelfNavigationService', [
|
||||
'navigateToResultList',
|
||||
]),
|
||||
},
|
||||
{
|
||||
provide: ShelfFilterService,
|
||||
useValue: jasmine.createSpy('shelfFilterService'),
|
||||
},
|
||||
{
|
||||
provide: ShelfSearchFacadeService,
|
||||
useValue: jasmine.createSpyObj('shelfSearchService', ['search']),
|
||||
},
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA],
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ShelfSearchInputComponent);
|
||||
component = fixture.componentInstance;
|
||||
facade = TestBed.get(SearchStateFacade);
|
||||
navigationService = TestBed.get(ShelfNavigationService);
|
||||
shelfSearchService = TestBed.get(ShelfSearchFacadeService);
|
||||
|
||||
component.hasAutocomplete = false;
|
||||
component.autocompleteResult$ = of([]);
|
||||
|
||||
spyOn(component, 'ngAfterViewInit').and.callFake(() => {});
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not clear the previous results onInit', () => {
|
||||
spyOn(facade, 'clearResult').and.callThrough();
|
||||
component.ngOnInit();
|
||||
|
||||
expect(facade.clearResult).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not setup navigation onInit', fakeAsync(() => {
|
||||
component.ngOnInit();
|
||||
|
||||
tick();
|
||||
|
||||
expect(navigationService.navigateToResultList).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should set up navigation after triggering a search', fakeAsync(() => {
|
||||
component.triggerSearch({ type: 'search', value: 'Testsuche' });
|
||||
|
||||
tick();
|
||||
|
||||
expect(navigationService.navigateToResultList).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
@@ -7,14 +7,7 @@ import {
|
||||
ViewChild,
|
||||
AfterViewInit,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
Subject,
|
||||
BehaviorSubject,
|
||||
Observable,
|
||||
of,
|
||||
NEVER,
|
||||
Subscription,
|
||||
} from 'rxjs';
|
||||
import { Subject, BehaviorSubject, Observable, of, NEVER } from 'rxjs';
|
||||
import {
|
||||
ShelfSearchFacadeService,
|
||||
ShelfNavigationService,
|
||||
@@ -85,7 +78,6 @@ export class ShelfSearchInputComponent
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.clearPreviousResults();
|
||||
if (this.hasAutocomplete) {
|
||||
this.setupAutocompletion();
|
||||
}
|
||||
@@ -139,6 +131,8 @@ export class ShelfSearchInputComponent
|
||||
} else if (type === 'scan') {
|
||||
this.shelfSearchService.searchWithBarcode(value);
|
||||
}
|
||||
|
||||
this.setUpNavigation();
|
||||
}
|
||||
|
||||
openScanner() {
|
||||
@@ -173,10 +167,6 @@ export class ShelfSearchInputComponent
|
||||
}
|
||||
}
|
||||
|
||||
private clearPreviousResults() {
|
||||
this.searchStateFacade.clearResult();
|
||||
}
|
||||
|
||||
private resetSessionStorage(key: string = SHELF_SCROLL_INDEX) {
|
||||
sessionStorage.removeItem(key);
|
||||
}
|
||||
@@ -225,7 +215,6 @@ export class ShelfSearchInputComponent
|
||||
startWith('')
|
||||
);
|
||||
|
||||
this.setUpNavigation();
|
||||
this.setUpErrorCleaner();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user