Skip to content

Commit 2030b29

Browse files
Fix scope name not being displayed after a page refresh & code cleanup
1 parent 2513f91 commit 2030b29

3 files changed

Lines changed: 14 additions & 46 deletions

File tree

src/app/shared/search-form/search-form.component.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
<div>
33
<div class="form-group input-group">
44
<div *ngIf="showScopeSelector" class="input-group-prepend">
5-
<button class="scope-button btn btn-outline-secondary text-truncate" [ngbTooltip]="dsoNameService.getName(selectedScope | async)" type="button" (click)="openScopeModal()">{{dsoNameService.getName(selectedScope | async) || ('search.form.scope.all' | translate)}}</button>
5+
<button class="scope-button btn btn-outline-secondary text-truncate"
6+
[ngbTooltip]="dsoNameService.getName(selectedScope | async)" type="button"
7+
(click)="openScopeModal()">
8+
{{dsoNameService.getName(selectedScope | async) || ('search.form.scope.all' | translate)}}
9+
</button>
610
</div>
7-
<input type="text" [(ngModel)]="query" name="query" class="form-control" attr.aria-label="{{ searchPlaceholder }}" [attr.data-test]="'search-box' | dsBrowserOnly"
11+
<input type="text" [(ngModel)]="query" name="query" class="form-control"
12+
attr.aria-label="{{ searchPlaceholder }}" [attr.data-test]="'search-box' | dsBrowserOnly"
813
[placeholder]="searchPlaceholder">
914
<span class="input-group-append">
1015
<button type="submit" class="search-button btn btn-{{brandColor}}" [attr.data-test]="'search-button' | dsBrowserOnly"><i class="fas fa-search"></i> {{ ('search.form.search' | translate) }}</button>

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('SearchFormComponent', () => {
3333
};
3434

3535
beforeEach(waitForAsync(() => {
36-
TestBed.configureTestingModule({
36+
return TestBed.configureTestingModule({
3737
imports: [FormsModule, RouterTestingModule, TranslateModule.forRoot()],
3838
providers: [
3939
{ provide: Router, useValue: router },
@@ -96,7 +96,7 @@ describe('SearchFormComponent', () => {
9696
tick();
9797
const scopeSelect = de.query(By.css('.scope-button')).nativeElement;
9898

99-
expect(scopeSelect.textContent).toBe(testCommunity.name);
99+
expect(scopeSelect.textContent).toContain('Sample Community');
100100
}));
101101

102102
describe('updateSearch', () => {
@@ -172,32 +172,9 @@ describe('SearchFormComponent', () => {
172172
expect(comp.updateSearch).toHaveBeenCalledWith(searchQuery);
173173
});
174174
});
175-
176-
// it('should call updateSearch when clicking the submit button with correct parameters', fakeAsync(() => {
177-
// comp.query = 'Test String'
178-
// fixture.detectChanges();
179-
// spyOn(comp, 'updateSearch').and.callThrough();
180-
// fixture.detectChanges();
181-
//
182-
// const submit = de.query(By.css('button.search-button')).nativeElement;
183-
// const scope = '123456';
184-
// const query = 'test';
185-
// const select = de.query(By.css('select')).nativeElement;
186-
// const input = de.query(By.css('input')).nativeElement;
187-
//
188-
// tick();
189-
// select.value = scope;
190-
// input.value = query;
191-
//
192-
// fixture.detectChanges();
193-
//
194-
// submit.click();
195-
//
196-
// expect(comp.updateSearch).toHaveBeenCalledWith({ scope: scope, query: query });
197-
// }));
198175
});
199176

200-
export const objects: DSpaceObject[] = [
177+
const objects: DSpaceObject[] = [
201178
Object.assign(new Community(), {
202179
logo: {
203180
self: {

src/app/shared/search-form/search-form.component.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
1+
import { Component, EventEmitter, Input, Output, OnChanges } from '@angular/core';
22
import { DSpaceObject } from '../../core/shared/dspace-object.model';
33
import { Router } from '@angular/router';
44
import { isNotEmpty } from '../empty.util';
@@ -14,22 +14,15 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv
1414
import { getFirstSucceededRemoteDataPayload } from '../../core/shared/operators';
1515
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
1616

17-
/**
18-
* This component renders a simple item page.
19-
* The route parameter 'id' is used to request the item it represents.
20-
* All fields of the item that should be displayed, are defined in its template.
21-
*/
22-
2317
@Component({
2418
selector: 'ds-search-form',
2519
styleUrls: ['./search-form.component.scss'],
2620
templateUrl: './search-form.component.html'
2721
})
28-
2922
/**
3023
* Component that represents the search form
3124
*/
32-
export class SearchFormComponent implements OnInit {
25+
export class SearchFormComponent implements OnChanges {
3326
/**
3427
* The search query
3528
*/
@@ -88,7 +81,7 @@ export class SearchFormComponent implements OnInit {
8881
/**
8982
* Retrieve the scope object from the URL so we can show its name
9083
*/
91-
ngOnInit(): void {
84+
ngOnChanges(): void {
9285
if (isNotEmpty(this.scope)) {
9386
this.dsoService.findById(this.scope).pipe(getFirstSucceededRemoteDataPayload())
9487
.subscribe((scope: DSpaceObject) => this.selectedScope.next(scope));
@@ -122,19 +115,12 @@ export class SearchFormComponent implements OnInit {
122115
updateSearch(data: any) {
123116
const queryParams = Object.assign({}, data);
124117

125-
this.router.navigate(this.getSearchLinkParts(), {
118+
void this.router.navigate(this.getSearchLinkParts(), {
126119
queryParams: queryParams,
127120
queryParamsHandling: 'merge'
128121
});
129122
}
130123

131-
/**
132-
* For usage of the isNotEmpty function in the template
133-
*/
134-
isNotEmpty(object: any) {
135-
return isNotEmpty(object);
136-
}
137-
138124
/**
139125
* @returns {string} The base path to the search page, or the current page when inPlaceSearch is true
140126
*/

0 commit comments

Comments
 (0)