Skip to content

Commit

Permalink
108588: Fixed scope not being set when browsing by taxonomy on commun…
Browse files Browse the repository at this point in the history
…ity/collection pages
  • Loading branch information
alexandrevryghem committed Dec 20, 2023
1 parent 989db14 commit 49010db
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('BrowseByTaxonomyComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(BrowseByTaxonomyComponent);
component = fixture.componentInstance;
spyOn(component, 'updateQueryParams').and.callThrough();
fixture.detectChanges();
detail1 = new VocabularyEntryDetail();
detail2 = new VocabularyEntryDetail();
Expand All @@ -62,6 +63,7 @@ describe('BrowseByTaxonomyComponent', () => {
expect(component.selectedItems).toContain(detail1);
expect(component.selectedItems.length).toBe(1);
expect(component.filterValues).toEqual(['HUMANITIES and RELIGION,equals'] );
expect(component.updateQueryParams).toHaveBeenCalled();
});

it('should handle select event with multiple selected items', () => {
Expand All @@ -71,6 +73,7 @@ describe('BrowseByTaxonomyComponent', () => {
expect(component.selectedItems).toContain(detail1, detail2);
expect(component.selectedItems.length).toBe(2);
expect(component.filterValues).toEqual(['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'] );
expect(component.updateQueryParams).toHaveBeenCalled();
});

it('should handle deselect event', () => {
Expand All @@ -83,6 +86,33 @@ describe('BrowseByTaxonomyComponent', () => {
expect(component.selectedItems).toContain(detail2);
expect(component.selectedItems.length).toBe(1);
expect(component.filterValues).toEqual(['TECHNOLOGY,equals'] );
expect(component.updateQueryParams).toHaveBeenCalled();
});

describe('updateQueryParams', () => {
beforeEach(() => {
component.facetType = 'subject';
component.filterValues = ['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'];
});

it('should update the queryParams with the selected filterValues', () => {
component.updateQueryParams();

expect(component.queryParams).toEqual({
'f.subject': ['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'],
});
});

it('should include the scope if present', () => {
component.scope = '67f849f1-2499-4872-8c61-9e2b47d71068';

component.updateQueryParams();

expect(component.queryParams).toEqual({
'f.subject': ['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'],
'scope': '67f849f1-2499-4872-8c61-9e2b47d71068',
});
});
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { VocabularyOptions } from '../../core/submission/vocabularies/models/vocabulary-options.model';
import { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Params } from '@angular/router';
import { Observable } from 'rxjs';
import { BrowseDefinition } from '../../core/shared/browse-definition.model';
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
import { map } from 'rxjs/operators';
import { HierarchicalBrowseDefinition } from '../../core/shared/hierarchical-browse-definition.model';
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
import { hasValue } from '../../shared/empty.util';

@Component({
selector: 'ds-browse-by-taxonomy',
Expand Down Expand Up @@ -49,7 +50,7 @@ export class BrowseByTaxonomyComponent extends AbstractBrowseByTypeComponent imp
/**
* The parameters used in the URL
*/
queryParams: any;
queryParams: Params;

/**
* Resolved browse-by definition
Expand All @@ -73,6 +74,9 @@ export class BrowseByTaxonomyComponent extends AbstractBrowseByTypeComponent imp
this.vocabularyName = browseDefinition.vocabulary;
this.vocabularyOptions = { name: this.vocabularyName, closed: true };
}));
this.subs.push(this.scope$.subscribe(() => {
this.updateQueryParams();
}));
}

/**
Expand All @@ -82,9 +86,9 @@ export class BrowseByTaxonomyComponent extends AbstractBrowseByTypeComponent imp
* @param detail VocabularyEntryDetail to be added
*/
onSelect(detail: VocabularyEntryDetail): void {
this.selectedItems.push(detail);
this.filterValues = this.selectedItems
.map((item: VocabularyEntryDetail) => `${item.value},equals`);
this.selectedItems.push(detail);
this.filterValues = this.selectedItems
.map((item: VocabularyEntryDetail) => `${item.value},equals`);
this.updateQueryParams();
}

Expand All @@ -94,18 +98,25 @@ export class BrowseByTaxonomyComponent extends AbstractBrowseByTypeComponent imp
* @param detail VocabularyEntryDetail to be removed
*/
onDeselect(detail: VocabularyEntryDetail): void {
this.selectedItems = this.selectedItems.filter((entry: VocabularyEntryDetail) => { return entry.id !== detail.id; });
this.filterValues = this.filterValues.filter((value: string) => { return value !== `${detail.value},equals`; });
this.selectedItems = this.selectedItems.filter((entry: VocabularyEntryDetail) => {
return entry.id !== detail.id;
});
this.filterValues = this.filterValues.filter((value: string) => {
return value !== `${detail.value},equals`;
});
this.updateQueryParams();
}

/**
* Updates queryParams based on the current facetType and filterValues.
*/
private updateQueryParams(): void {
updateQueryParams(): void {
this.queryParams = {
['f.' + this.facetType]: this.filterValues
};
if (hasValue(this.scope)) {
this.queryParams.scope = this.scope;
}
}

}

0 comments on commit 49010db

Please sign in to comment.