mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1639 from atmire/issue-1635_search-bar-with-input-scope
Fix search bar with input scope
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<div class="container">
|
||||
<div class="collection-page"
|
||||
*ngVar="(collectionRD$ | async) as collectionRD">
|
||||
<div *ngIf="collectionRD?.hasSucceeded" @fadeInOut>
|
||||
<div *ngIf="collectionRD?.payload as collection">
|
||||
<div *ngIf="collectionRD?.hasSucceeded" @fadeInOut>
|
||||
<div *ngIf="collectionRD?.payload as collection">
|
||||
<ds-view-tracker [object]="collection"></ds-view-tracker>
|
||||
<div class="d-flex flex-row border-bottom mb-4 pb-4">
|
||||
<header class="comcol-header mr-auto">
|
||||
@@ -13,8 +13,7 @@
|
||||
<!-- Collection logo -->
|
||||
<ds-comcol-page-logo *ngIf="logoRD$"
|
||||
[logo]="(logoRD$ | async)?.payload"
|
||||
[alternateText]="'Collection Logo'"
|
||||
[alternateText]="'Collection Logo'">
|
||||
[alternateText]="'Collection Logo'">
|
||||
</ds-comcol-page-logo>
|
||||
|
||||
<!-- Handle -->
|
||||
|
@@ -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',
|
||||
})
|
||||
|
@@ -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(), {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user