diff --git a/src/app/collection-page/collection-page.component.html b/src/app/collection-page/collection-page.component.html index 6e4437e0e0..72033649b0 100644 --- a/src/app/collection-page/collection-page.component.html +++ b/src/app/collection-page/collection-page.component.html @@ -1,8 +1,8 @@
-
-
+
+
@@ -13,8 +13,7 @@ + [alternateText]="'Collection Logo'"> diff --git a/src/app/collection-page/themed-collection-page.component.ts b/src/app/collection-page/themed-collection-page.component.ts index 82074e43e6..2faf418423 100644 --- a/src/app/collection-page/themed-collection-page.component.ts +++ b/src/app/collection-page/themed-collection-page.component.ts @@ -6,7 +6,7 @@ import { CollectionPageComponent } from './collection-page.component'; * Themed wrapper for CollectionPageComponent */ @Component({ - selector: 'ds-themed-community-page', + selector: 'ds-themed-collection-page', styleUrls: [], templateUrl: '../shared/theme-support/themed.component.html', }) diff --git a/src/app/shared/search-form/search-form.component.spec.ts b/src/app/shared/search-form/search-form.component.spec.ts index 934f00b10c..6f485ec77e 100644 --- a/src/app/shared/search-form/search-form.component.spec.ts +++ b/src/app/shared/search-form/search-form.component.spec.ts @@ -13,7 +13,9 @@ import { SearchConfigurationService } from '../../core/shared/search/search-conf import { PaginationServiceStub } from '../testing/pagination-service.stub'; import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service'; import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils'; -import { FindListOptions } from '../../core/data/find-list-options.model'; +import { SearchServiceStub } from '../testing/search-service.stub'; +import { Router } from '@angular/router'; +import { RouterStub } from '../testing/router.stub'; describe('SearchFormComponent', () => { let comp: SearchFormComponent; @@ -21,21 +23,23 @@ describe('SearchFormComponent', () => { let de: DebugElement; let el: HTMLElement; + const router = new RouterStub(); + const searchService = new SearchServiceStub(); const paginationService = new PaginationServiceStub(); - - const searchConfigService = {paginationID: 'test-id'}; + const searchConfigService = { paginationID: 'test-id' }; + const dspaceObjectService = { + findById: () => createSuccessfulRemoteDataObject$(undefined), + }; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [FormsModule, RouterTestingModule, TranslateModule.forRoot()], providers: [ - { - provide: SearchService, - useValue: {} - }, + { provide: Router, useValue: router }, + { provide: SearchService, useValue: searchService }, { provide: PaginationService, useValue: paginationService }, { provide: SearchConfigurationService, useValue: searchConfigService }, - { provide: DSpaceObjectDataService, useValue: { findById: () => createSuccessfulRemoteDataObject$(undefined)} } + { provide: DSpaceObjectDataService, useValue: dspaceObjectService }, ], declarations: [SearchFormComponent] }).compileComponents(); @@ -90,6 +94,81 @@ describe('SearchFormComponent', () => { expect(scopeSelect.textContent).toBe(testCommunity.name); })); + + describe('updateSearch', () => { + const query = 'THOR'; + const scope = 'MCU'; + let searchQuery = {}; + + it('should navigate to the search page even when no parameters are provided', () => { + comp.updateSearch(searchQuery); + + expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), { + queryParams: searchQuery, + queryParamsHandling: 'merge' + }); + }); + + it('should navigate to the search page with parameters only query if only query is provided', () => { + searchQuery = { + query: query + }; + + comp.updateSearch(searchQuery); + + expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), { + queryParams: searchQuery, + queryParamsHandling: 'merge' + }); + }); + + it('should navigate to the search page with parameters only query if only scope is provided', () => { + searchQuery = { + scope: scope + }; + + comp.updateSearch(searchQuery); + + expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), { + queryParams: searchQuery, + queryParamsHandling: 'merge' + }); + }); + }); + + describe('when the scope variable is used', () => { + const query = 'THOR'; + const scope = 'MCU'; + let searchQuery = {}; + + beforeEach(() => { + spyOn(comp, 'updateSearch'); + }); + + it('should only search in the provided scope', () => { + searchQuery = { + query: query, + scope: scope + }; + + comp.scope = scope; + comp.onSubmit(searchQuery); + + expect(comp.updateSearch).toHaveBeenCalledWith(searchQuery); + }); + + it('should not create searchQuery with the scope if an empty scope is provided', () => { + searchQuery = { + query: query + }; + + comp.scope = ''; + comp.onSubmit(searchQuery); + + expect(comp.updateSearch).toHaveBeenCalledWith(searchQuery); + }); + }); + // it('should call updateSearch when clicking the submit button with correct parameters', fakeAsync(() => { // comp.query = 'Test String' // fixture.detectChanges(); @@ -112,7 +191,7 @@ describe('SearchFormComponent', () => { // // expect(comp.updateSearch).toHaveBeenCalledWith({ scope: scope, query: query }); // })); - }); +}); export const objects: DSpaceObject[] = [ Object.assign(new Community(), { diff --git a/src/app/shared/search-form/search-form.component.ts b/src/app/shared/search-form/search-form.component.ts index caf6a91046..7ea51e4c1e 100644 --- a/src/app/shared/search-form/search-form.component.ts +++ b/src/app/shared/search-form/search-form.component.ts @@ -98,6 +98,9 @@ export class SearchFormComponent implements OnInit { * @param data Values submitted using the form */ onSubmit(data: any) { + if (isNotEmpty(this.scope)) { + data = Object.assign(data, { scope: this.scope }); + } this.updateSearch(data); this.submitSearch.emit(data); }