From 2030b29ddcedfe119b994173579480425af37044 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Thu, 16 Mar 2023 00:26:11 +0100 Subject: [PATCH] Fix scope name not being displayed after a page refresh & code cleanup --- .../search-form/search-form.component.html | 9 ++++-- .../search-form/search-form.component.spec.ts | 29 ++----------------- .../search-form/search-form.component.ts | 22 +++----------- 3 files changed, 14 insertions(+), 46 deletions(-) diff --git a/src/app/shared/search-form/search-form.component.html b/src/app/shared/search-form/search-form.component.html index b6b4395c2ff..f9167858047 100644 --- a/src/app/shared/search-form/search-form.component.html +++ b/src/app/shared/search-form/search-form.component.html @@ -2,9 +2,14 @@
- +
- 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 4b5844f6609..584b7c5584c 100644 --- a/src/app/shared/search-form/search-form.component.spec.ts +++ b/src/app/shared/search-form/search-form.component.spec.ts @@ -33,7 +33,7 @@ describe('SearchFormComponent', () => { }; beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ + return TestBed.configureTestingModule({ imports: [FormsModule, RouterTestingModule, TranslateModule.forRoot()], providers: [ { provide: Router, useValue: router }, @@ -96,7 +96,7 @@ describe('SearchFormComponent', () => { tick(); const scopeSelect = de.query(By.css('.scope-button')).nativeElement; - expect(scopeSelect.textContent).toBe(testCommunity.name); + expect(scopeSelect.textContent).toContain('Sample Community'); })); describe('updateSearch', () => { @@ -172,32 +172,9 @@ describe('SearchFormComponent', () => { expect(comp.updateSearch).toHaveBeenCalledWith(searchQuery); }); }); - - // it('should call updateSearch when clicking the submit button with correct parameters', fakeAsync(() => { - // comp.query = 'Test String' - // fixture.detectChanges(); - // spyOn(comp, 'updateSearch').and.callThrough(); - // fixture.detectChanges(); - // - // const submit = de.query(By.css('button.search-button')).nativeElement; - // const scope = '123456'; - // const query = 'test'; - // const select = de.query(By.css('select')).nativeElement; - // const input = de.query(By.css('input')).nativeElement; - // - // tick(); - // select.value = scope; - // input.value = query; - // - // fixture.detectChanges(); - // - // submit.click(); - // - // expect(comp.updateSearch).toHaveBeenCalledWith({ scope: scope, query: query }); - // })); }); -export const objects: DSpaceObject[] = [ +const objects: DSpaceObject[] = [ Object.assign(new Community(), { logo: { self: { diff --git a/src/app/shared/search-form/search-form.component.ts b/src/app/shared/search-form/search-form.component.ts index 8a1b69887a1..fbab550a942 100644 --- a/src/app/shared/search-form/search-form.component.ts +++ b/src/app/shared/search-form/search-form.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { Component, EventEmitter, Input, Output, OnChanges } from '@angular/core'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { Router } from '@angular/router'; import { isNotEmpty } from '../empty.util'; @@ -14,22 +14,15 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv import { getFirstSucceededRemoteDataPayload } from '../../core/shared/operators'; import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; -/** - * This component renders a simple item page. - * The route parameter 'id' is used to request the item it represents. - * All fields of the item that should be displayed, are defined in its template. - */ - @Component({ selector: 'ds-search-form', styleUrls: ['./search-form.component.scss'], templateUrl: './search-form.component.html' }) - /** * Component that represents the search form */ -export class SearchFormComponent implements OnInit { +export class SearchFormComponent implements OnChanges { /** * The search query */ @@ -88,7 +81,7 @@ export class SearchFormComponent implements OnInit { /** * Retrieve the scope object from the URL so we can show its name */ - ngOnInit(): void { + ngOnChanges(): void { if (isNotEmpty(this.scope)) { this.dsoService.findById(this.scope).pipe(getFirstSucceededRemoteDataPayload()) .subscribe((scope: DSpaceObject) => this.selectedScope.next(scope)); @@ -122,19 +115,12 @@ export class SearchFormComponent implements OnInit { updateSearch(data: any) { const queryParams = Object.assign({}, data); - this.router.navigate(this.getSearchLinkParts(), { + void this.router.navigate(this.getSearchLinkParts(), { queryParams: queryParams, queryParamsHandling: 'merge' }); } - /** - * For usage of the isNotEmpty function in the template - */ - isNotEmpty(object: any) { - return isNotEmpty(object); - } - /** * @returns {string} The base path to the search page, or the current page when inPlaceSearch is true */