mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Fix SearchHierarchyFilterComponent no expectation tests
Reverted the way you detect when an item is selected by using observables again instead of promises. The reason why it didn't work without the old observable approach was because `VocabularyTreeviewModalComponent` didn't have a `select` `@Output` like `VocabularyTreeviewComponent`
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Component, Input } from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model';
|
import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model';
|
||||||
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
|
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
|
||||||
@@ -33,6 +33,12 @@ export class VocabularyTreeviewModalComponent {
|
|||||||
*/
|
*/
|
||||||
@Input() multiSelect = false;
|
@Input() multiSelect = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event fired when a vocabulary entry is selected.
|
||||||
|
* Event's payload equals to {@link VocabularyEntryDetail} selected.
|
||||||
|
*/
|
||||||
|
@Output() select: EventEmitter<VocabularyEntryDetail> = new EventEmitter<VocabularyEntryDetail>(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize instance variables
|
* Initialize instance variables
|
||||||
*
|
*
|
||||||
@@ -46,6 +52,7 @@ export class VocabularyTreeviewModalComponent {
|
|||||||
* Method called on entry select
|
* Method called on entry select
|
||||||
*/
|
*/
|
||||||
onSelect(item: VocabularyEntryDetail) {
|
onSelect(item: VocabularyEntryDetail) {
|
||||||
|
this.select.emit(item);
|
||||||
this.activeModal.close(item);
|
this.activeModal.close(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { SearchHierarchyFilterComponent } from './search-hierarchy-filter.component';
|
import { SearchHierarchyFilterComponent } from './search-hierarchy-filter.component';
|
||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
import { DebugElement, EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { DebugElement, EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { VocabularyService } from '../../../../../core/submission/vocabularies/vocabulary.service';
|
import { VocabularyService } from '../../../../../core/submission/vocabularies/vocabulary.service';
|
||||||
@@ -56,7 +56,7 @@ describe('SearchHierarchyFilterComponent', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
return TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
NgbModule,
|
NgbModule,
|
||||||
@@ -138,8 +138,9 @@ describe('SearchHierarchyFilterComponent', () => {
|
|||||||
|
|
||||||
describe('when selecting a value from the vocabulary tree', () => {
|
describe('when selecting a value from the vocabulary tree', () => {
|
||||||
|
|
||||||
it('should add a new search filter to the existing search filters', () => {
|
it('should add a new search filter to the existing search filters', fakeAsync(() => {
|
||||||
waitForAsync(() => expect(router.navigate).toHaveBeenCalledWith([testSearchLink], {
|
tick();
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith([testSearchLink], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
[`f.${testSearchFilter}`]: [
|
[`f.${testSearchFilter}`]: [
|
||||||
...alreadySelectedValues,
|
...alreadySelectedValues,
|
||||||
@@ -147,8 +148,8 @@ describe('SearchHierarchyFilterComponent', () => {
|
|||||||
].map((value => `${value},equals`)),
|
].map((value => `${value},equals`)),
|
||||||
},
|
},
|
||||||
queryParamsHandling: 'merge',
|
queryParamsHandling: 'merge',
|
||||||
}));
|
});
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, Inject, OnInit } from '@angular/core';
|
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { renderFacetFor } from '../search-filter-type-decorator';
|
import { renderFacetFor } from '../search-filter-type-decorator';
|
||||||
import { FilterType } from '../../../models/filter-type.model';
|
import { FilterType } from '../../../models/filter-type.model';
|
||||||
import { facetLoad, SearchFacetFilterComponent } from '../search-facet-filter/search-facet-filter.component';
|
import { facetLoad, SearchFacetFilterComponent } from '../search-facet-filter/search-facet-filter.component';
|
||||||
@@ -21,7 +21,7 @@ import { FacetValue } from '../../../models/facet-value.model';
|
|||||||
import { getFacetValueForType } from '../../../search.utils';
|
import { getFacetValueForType } from '../../../search.utils';
|
||||||
import { filter, map, take } from 'rxjs/operators';
|
import { filter, map, take } from 'rxjs/operators';
|
||||||
import { VocabularyService } from '../../../../../core/submission/vocabularies/vocabulary.service';
|
import { VocabularyService } from '../../../../../core/submission/vocabularies/vocabulary.service';
|
||||||
import { Observable, BehaviorSubject } from 'rxjs';
|
import { Observable, BehaviorSubject, Subscription } from 'rxjs';
|
||||||
import { PageInfo } from '../../../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../../../core/shared/page-info.model';
|
||||||
import { environment } from '../../../../../../environments/environment';
|
import { environment } from '../../../../../../environments/environment';
|
||||||
import { addOperatorToFilterValue } from '../../../search.utils';
|
import { addOperatorToFilterValue } from '../../../search.utils';
|
||||||
@@ -38,7 +38,9 @@ import { VocabularyTreeviewModalComponent } from '../../../../form/vocabulary-tr
|
|||||||
* Component that represents a hierarchy facet for a specific filter configuration
|
* Component that represents a hierarchy facet for a specific filter configuration
|
||||||
*/
|
*/
|
||||||
@renderFacetFor(FilterType.hierarchy)
|
@renderFacetFor(FilterType.hierarchy)
|
||||||
export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent implements OnInit {
|
export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
|
subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
constructor(protected searchService: SearchService,
|
constructor(protected searchService: SearchService,
|
||||||
protected filterService: SearchFilterService,
|
protected filterService: SearchFilterService,
|
||||||
@@ -56,6 +58,11 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
|
|||||||
|
|
||||||
vocabularyExists$: Observable<boolean>;
|
vocabularyExists$: Observable<boolean>;
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
super.ngOnDestroy();
|
||||||
|
this.subscriptions.forEach((subscription: Subscription) => subscription.unsubscribe());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submits a new active custom value to the filter from the input field
|
* Submits a new active custom value to the filter from the input field
|
||||||
* Overwritten method from parent component, adds the "query" operator to the received data before passing it on
|
* Overwritten method from parent component, adds the "query" operator to the received data before passing it on
|
||||||
@@ -91,11 +98,11 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
|
|||||||
name: this.getVocabularyEntry(),
|
name: this.getVocabularyEntry(),
|
||||||
closed: true
|
closed: true
|
||||||
};
|
};
|
||||||
modalRef.result.then((detail: VocabularyEntryDetail) => {
|
this.subscriptions.push(modalRef.componentInstance.select.subscribe((detail: VocabularyEntryDetail) => {
|
||||||
this.selectedValues$
|
this.selectedValues$
|
||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
.subscribe((selectedValues) => {
|
.subscribe((selectedValues) => {
|
||||||
this.router.navigate(
|
void this.router.navigate(
|
||||||
[this.searchService.getSearchLink()],
|
[this.searchService.getSearchLink()],
|
||||||
{
|
{
|
||||||
queryParams: {
|
queryParams: {
|
||||||
@@ -106,7 +113,7 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}).catch();
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user