Commits

Alexandre Vryghem authored and github-actions[bot] committed d96c048874d
111639: Fixed search settings not using the scope

(cherry picked from commit 93b22cba1f1b541d86f12b3bce79c8db6fd83bb9)
No tags

src/app/shared/search/search-settings/search-settings.component.spec.ts

Modified
1 -import { SearchService } from '../../../core/shared/search/search.service';
2 1 import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3 2 import { SearchSettingsComponent } from './search-settings.component';
4 3 import { of as observableOf } from 'rxjs';
5 4 import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
6 5 import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
7 6 import { TranslateModule } from '@ngx-translate/core';
8 7 import { RouterTestingModule } from '@angular/router/testing';
9 -import { ActivatedRoute } from '@angular/router';
10 8 import { NO_ERRORS_SCHEMA } from '@angular/core';
11 9 import { EnumKeysPipe } from '../../utils/enum-keys-pipe';
12 10 import { By } from '@angular/platform-browser';
13 -import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
14 11 import { VarDirective } from '../../utils/var.directive';
15 12 import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
16 -import { SidebarService } from '../../sidebar/sidebar.service';
17 -import { SidebarServiceStub } from '../../testing/sidebar-service.stub';
18 13 import { PaginationService } from '../../../core/pagination/pagination.service';
19 14 import { PaginationServiceStub } from '../../testing/pagination-service.stub';
20 15
21 16 describe('SearchSettingsComponent', () => {
22 17
23 18 let comp: SearchSettingsComponent;
24 19 let fixture: ComponentFixture<SearchSettingsComponent>;
25 - let searchServiceObject: SearchService;
26 20
27 21 let pagination: PaginationComponentOptions;
28 22 let sort: SortOptions;
29 - let mockResults;
30 - let searchServiceStub;
31 23
32 24 let queryParam;
33 25 let scopeParam;
34 26 let paginatedSearchOptions;
35 27
36 - let paginationService;
28 + let paginationService: PaginationServiceStub;
37 29
38 - let activatedRouteStub;
39 30
40 - beforeEach(waitForAsync(() => {
31 + beforeEach(waitForAsync(async () => {
41 32 pagination = new PaginationComponentOptions();
42 33 pagination.id = 'search-results-pagination';
43 34 pagination.currentPage = 1;
44 35 pagination.pageSize = 10;
45 36 sort = new SortOptions('score', SortDirection.DESC);
46 - mockResults = ['test', 'data'];
47 - searchServiceStub = {
48 - searchOptions: { pagination: pagination, sort: sort },
49 - search: () => mockResults,
50 - };
51 37
52 38 queryParam = 'test query';
53 39 scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
54 40 paginatedSearchOptions = {
55 41 query: queryParam,
56 42 scope: scopeParam,
57 43 pagination,
58 44 sort,
59 45 };
60 46
61 - activatedRouteStub = {
62 - queryParams: observableOf({
63 - query: queryParam,
64 - scope: scopeParam,
65 - }),
66 - };
67 -
68 47 paginationService = new PaginationServiceStub(pagination, sort);
69 48
70 - TestBed.configureTestingModule({
49 + await TestBed.configureTestingModule({
71 50 imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
72 51 declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
73 52 providers: [
74 - { provide: SearchService, useValue: searchServiceStub },
75 -
76 - { provide: ActivatedRoute, useValue: activatedRouteStub },
77 - {
78 - provide: SidebarService,
79 - useValue: SidebarServiceStub,
80 - },
81 - {
82 - provide: SearchFilterService,
83 - useValue: {},
84 - },
85 53 {
86 54 provide: PaginationService,
87 55 useValue: paginationService,
88 56 },
89 57 {
90 58 provide: SEARCH_CONFIG_SERVICE,
91 59 useValue: {
92 60 paginatedSearchOptions: observableOf(paginatedSearchOptions),
93 61 getCurrentScope: observableOf('test-id'),
94 62 }
104 72
105 73 comp.sortOptionsList = [
106 74 new SortOptions('score', SortDirection.DESC),
107 75 new SortOptions('dc.title', SortDirection.ASC),
108 76 new SortOptions('dc.title', SortDirection.DESC)
109 77 ];
110 78 comp.currentSortOption = new SortOptions('score', SortDirection.DESC);
111 79
112 80 // SearchPageComponent test instance
113 81 fixture.detectChanges();
114 - searchServiceObject = (comp as any).service;
115 82 spyOn(comp, 'reloadOrder');
116 - spyOn(searchServiceObject, 'search').and.callThrough();
117 -
118 83 });
119 84
120 85 it('it should show the order settings with the respective selectable options', () => {
121 86 fixture.detectChanges();
122 87 const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings'));
123 88 expect(orderSetting).toBeDefined();
124 89 const childElements = orderSetting.queryAll(By.css('option'));
125 90 expect(childElements.length).toEqual(comp.sortOptionsList.length);
126 91 });
127 92

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut