Skip to content

Commit

Permalink
111639: Fixed search settings not using the scope
Browse files Browse the repository at this point in the history
(cherry picked from commit 93b22cb)
  • Loading branch information
alexandrevryghem authored and github-actions[bot] committed Feb 15, 2024
1 parent 865f489 commit d96c048
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
import { SearchService } from '../../../core/shared/search/search.service';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { SearchSettingsComponent } from './search-settings.component';
import { of as observableOf } from 'rxjs';
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { ActivatedRoute } from '@angular/router';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EnumKeysPipe } from '../../utils/enum-keys-pipe';
import { By } from '@angular/platform-browser';
import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
import { VarDirective } from '../../utils/var.directive';
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
import { SidebarService } from '../../sidebar/sidebar.service';
import { SidebarServiceStub } from '../../testing/sidebar-service.stub';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../testing/pagination-service.stub';

describe('SearchSettingsComponent', () => {

let comp: SearchSettingsComponent;
let fixture: ComponentFixture<SearchSettingsComponent>;
let searchServiceObject: SearchService;

let pagination: PaginationComponentOptions;
let sort: SortOptions;
let mockResults;
let searchServiceStub;

let queryParam;
let scopeParam;
let paginatedSearchOptions;

let paginationService;
let paginationService: PaginationServiceStub;

let activatedRouteStub;

beforeEach(waitForAsync(() => {
beforeEach(waitForAsync(async () => {
pagination = new PaginationComponentOptions();
pagination.id = 'search-results-pagination';
pagination.currentPage = 1;
pagination.pageSize = 10;
sort = new SortOptions('score', SortDirection.DESC);
mockResults = ['test', 'data'];
searchServiceStub = {
searchOptions: { pagination: pagination, sort: sort },
search: () => mockResults,
};

queryParam = 'test query';
scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
Expand All @@ -58,30 +44,12 @@ describe('SearchSettingsComponent', () => {
sort,
};

activatedRouteStub = {
queryParams: observableOf({
query: queryParam,
scope: scopeParam,
}),
};

paginationService = new PaginationServiceStub(pagination, sort);

TestBed.configureTestingModule({
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
providers: [
{ provide: SearchService, useValue: searchServiceStub },

{ provide: ActivatedRoute, useValue: activatedRouteStub },
{
provide: SidebarService,
useValue: SidebarServiceStub,
},
{
provide: SearchFilterService,
useValue: {},
},
{
provide: PaginationService,
useValue: paginationService,
Expand Down Expand Up @@ -111,10 +79,7 @@ describe('SearchSettingsComponent', () => {

// SearchPageComponent test instance
fixture.detectChanges();
searchServiceObject = (comp as any).service;
spyOn(comp, 'reloadOrder');
spyOn(searchServiceObject, 'search').and.callThrough();

});

it('it should show the order settings with the respective selectable options', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Component, Inject, Input } from '@angular/core';
import { SearchService } from '../../../core/shared/search/search.service';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { ActivatedRoute, Router } from '@angular/router';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
import { PaginationService } from '../../../core/pagination/pagination.service';
Expand All @@ -26,11 +24,10 @@ export class SearchSettingsComponent {
*/
@Input() sortOptionsList: SortOptions[];

constructor(private service: SearchService,
private route: ActivatedRoute,
private router: Router,
private paginationService: PaginationService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigurationService: SearchConfigurationService) {
constructor(
protected paginationService: PaginationService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigurationService: SearchConfigurationService,
) {
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,8 @@ export class SearchComponent implements OnDestroy, OnInit {
// Determinate PaginatedSearchOptions and listen to any update on it
const configuration$: Observable<string> = this.searchConfigService
.getCurrentConfiguration(this.configuration).pipe(distinctUntilChanged());
const searchSortOptions$: Observable<SortOptions[]> = configuration$.pipe(
switchMap((configuration: string) => this.searchConfigService
.getConfigurationSearchConfig(configuration)),
const searchSortOptions$: Observable<SortOptions[]> = combineLatest([configuration$, this.currentScope$]).pipe(
switchMap(([configuration, scope]: [string, string]) => this.searchConfigService.getConfigurationSearchConfig(configuration, scope)),
map((searchConfig: SearchConfig) => this.searchConfigService.getConfigurationSortOptions(searchConfig)),
distinctUntilChanged()
);
Expand Down
12 changes: 12 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3988,6 +3988,18 @@

"sorting.lastModified.DESC": "Last modified Descending",

"sorting.person.familyName.ASC": "Surname Ascending",

"sorting.person.familyName.DESC": "Surname Descending",

"sorting.person.givenName.ASC": "Name Ascending",

"sorting.person.givenName.DESC": "Name Descending",

"sorting.person.birthDate.ASC": "Birth Date Ascending",

"sorting.person.birthDate.DESC": "Birth Date Descending",

"statistics.title": "Statistics",

"statistics.header": "Statistics for {{ scope }}",
Expand Down

0 comments on commit d96c048

Please sign in to comment.