mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1022 from atmire/w2p-76922_Search-filter-from-entity-page-carries-over-to-discovery
Fix: Search filter from entity page carries over to discovery
This commit is contained in:
@@ -2,20 +2,63 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { configureSearchComponentTestingModule } from './search.component.spec';
|
||||
import { ConfigurationSearchPageComponent } from './configuration-search-page.component';
|
||||
import { SearchConfigurationService } from '../core/shared/search/search-configuration.service';
|
||||
import { Component, ViewChild } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { RouteService } from '../core/services/route.service';
|
||||
import createSpy = jasmine.createSpy;
|
||||
|
||||
const CONFIGURATION = 'test-configuration';
|
||||
const QUERY = 'test query';
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<ds-configuration-search-page [configuration]="'${CONFIGURATION}'"
|
||||
[fixedFilterQuery]="'${QUERY}'"
|
||||
#configurationSearchPage>
|
||||
</ds-configuration-search-page>
|
||||
`,
|
||||
})
|
||||
class HostComponent {
|
||||
@ViewChild('configurationSearchPage') configurationSearchPage: ConfigurationSearchPageComponent;
|
||||
}
|
||||
|
||||
describe('ConfigurationSearchPageComponent', () => {
|
||||
let comp: ConfigurationSearchPageComponent;
|
||||
let fixture: ComponentFixture<ConfigurationSearchPageComponent>;
|
||||
let fixture: ComponentFixture<HostComponent>;
|
||||
let searchConfigService: SearchConfigurationService;
|
||||
let routeService: RouteService;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
configureSearchComponentTestingModule(ConfigurationSearchPageComponent);
|
||||
configureSearchComponentTestingModule(ConfigurationSearchPageComponent, [HostComponent]);
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ConfigurationSearchPageComponent);
|
||||
comp = fixture.componentInstance;
|
||||
searchConfigService = (comp as any).searchConfigService;
|
||||
fixture = TestBed.createComponent(HostComponent);
|
||||
|
||||
// Set router url to a dummy value for SearchComponent#ngOnInit
|
||||
spyOnProperty(TestBed.inject(Router), 'url', 'get').and.returnValue('some/url/here');
|
||||
|
||||
routeService = TestBed.inject(RouteService);
|
||||
routeService.setParameter = createSpy('setParameter');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
comp = fixture.componentInstance.configurationSearchPage;
|
||||
searchConfigService = (comp as any).searchConfigService;
|
||||
});
|
||||
|
||||
it('should set route parameters on init', () => {
|
||||
expect(comp.configuration).toBe(CONFIGURATION);
|
||||
expect(comp.fixedFilterQuery).toBe(QUERY);
|
||||
|
||||
expect(routeService.setParameter).toHaveBeenCalledWith('configuration', CONFIGURATION);
|
||||
expect(routeService.setParameter).toHaveBeenCalledWith('fixedFilterQuery', QUERY);
|
||||
});
|
||||
|
||||
it('should reset route parameters on destroy', () => {
|
||||
fixture.destroy();
|
||||
|
||||
expect(routeService.setParameter).toHaveBeenCalledWith('configuration', undefined);
|
||||
expect(routeService.setParameter).toHaveBeenCalledWith('fixedFilterQuery', undefined);
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { HostWindowService } from '../shared/host-window.service';
|
||||
import { SidebarService } from '../shared/sidebar/sidebar.service';
|
||||
import { SearchComponent } from './search.component';
|
||||
import { ChangeDetectionStrategy, Component, Inject, Input, OnInit } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, Inject, Input, OnDestroy, OnInit } from '@angular/core';
|
||||
import { pushInOut } from '../shared/animations/push';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../+my-dspace-page/my-dspace-page.component';
|
||||
import { SearchConfigurationService } from '../core/shared/search/search-configuration.service';
|
||||
@@ -27,7 +27,7 @@ import { Router } from '@angular/router';
|
||||
]
|
||||
})
|
||||
|
||||
export class ConfigurationSearchPageComponent extends SearchComponent implements OnInit {
|
||||
export class ConfigurationSearchPageComponent extends SearchComponent implements OnInit, OnDestroy {
|
||||
/**
|
||||
* The configuration to use for the search options
|
||||
* If empty, the configuration will be determined by the route parameter called 'configuration'
|
||||
@@ -65,4 +65,17 @@ export class ConfigurationSearchPageComponent extends SearchComponent implements
|
||||
this.routeService.setParameter('fixedFilterQuery', this.fixedFilterQuery);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the updated query/configuration set in ngOnInit()
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
super.ngOnDestroy();
|
||||
if (hasValue(this.configuration)) {
|
||||
this.routeService.setParameter('configuration', undefined);
|
||||
}
|
||||
if (hasValue(this.fixedFilterQuery)) {
|
||||
this.routeService.setParameter('fixedFilterQuery', undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -84,10 +84,10 @@ const routeServiceStub = {
|
||||
}
|
||||
};
|
||||
|
||||
export function configureSearchComponentTestingModule(compType) {
|
||||
export function configureSearchComponentTestingModule(compType, additionalDeclarations: any[] = []) {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, NgbCollapseModule],
|
||||
declarations: [compType],
|
||||
declarations: [compType, ...additionalDeclarations],
|
||||
providers: [
|
||||
{ provide: SearchService, useValue: searchServiceStub },
|
||||
{
|
||||
|
Reference in New Issue
Block a user