mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
angular 6 upgrade
This commit is contained in:
@@ -12,7 +12,7 @@ export class PaginatedSearchOptions extends SearchOptions {
|
|||||||
pagination?: PaginationComponentOptions;
|
pagination?: PaginationComponentOptions;
|
||||||
sort?: SortOptions;
|
sort?: SortOptions;
|
||||||
|
|
||||||
constructor(options: {scope?: string, query?: string, dsoType?: DSpaceObjectType, filters?: SearchFilter[], pagination?: PaginationComponentOptions, sort?: SortOptions}) {
|
constructor(options: {scope?: string, query?: string, dsoType?: DSpaceObjectType, filters?: SearchFilter[], fixedFilter?: any, pagination?: PaginationComponentOptions, sort?: SortOptions}) {
|
||||||
super(options);
|
super(options);
|
||||||
this.pagination = options.pagination;
|
this.pagination = options.pagination;
|
||||||
this.sort = options.sort;
|
this.sort = options.sort;
|
||||||
|
@@ -58,7 +58,6 @@ export class SearchFixedFilterService {
|
|||||||
map((response: FilteredDiscoveryQueryResponse) =>
|
map((response: FilteredDiscoveryQueryResponse) =>
|
||||||
response.filterQuery
|
response.filterQuery
|
||||||
));
|
));
|
||||||
|
|
||||||
return filterQuery;
|
return filterQuery;
|
||||||
}
|
}
|
||||||
return observableOf(undefined);
|
return observableOf(undefined);
|
||||||
|
@@ -22,183 +22,182 @@ import { SearchConfigurationService } from './search-service/search-configuratio
|
|||||||
import { RemoteData } from '../core/data/remote-data';
|
import { RemoteData } from '../core/data/remote-data';
|
||||||
import { RouteService } from '../shared/services/route.service';
|
import { RouteService } from '../shared/services/route.service';
|
||||||
|
|
||||||
describe('SearchPageComponent', () => {
|
let comp: SearchPageComponent;
|
||||||
let comp: SearchPageComponent;
|
let fixture: ComponentFixture<SearchPageComponent>;
|
||||||
let fixture: ComponentFixture<SearchPageComponent>;
|
let searchServiceObject: SearchService;
|
||||||
let searchServiceObject: SearchService;
|
const store: Store<SearchPageComponent> = jasmine.createSpyObj('store', {
|
||||||
const store: Store<SearchPageComponent> = jasmine.createSpyObj('store', {
|
/* tslint:disable:no-empty */
|
||||||
/* tslint:disable:no-empty */
|
dispatch: {},
|
||||||
dispatch: {},
|
/* tslint:enable:no-empty */
|
||||||
/* tslint:enable:no-empty */
|
select: observableOf(true)
|
||||||
select: observableOf(true)
|
});
|
||||||
});
|
const pagination: PaginationComponentOptions = new PaginationComponentOptions();
|
||||||
const pagination: PaginationComponentOptions = new PaginationComponentOptions();
|
pagination.id = 'search-results-pagination';
|
||||||
pagination.id = 'search-results-pagination';
|
pagination.currentPage = 1;
|
||||||
pagination.currentPage = 1;
|
pagination.pageSize = 10;
|
||||||
pagination.pageSize = 10;
|
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
|
||||||
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
|
const mockResults = observableOf(new RemoteData(false, false, true, null, ['test', 'data']));
|
||||||
const mockResults = observableOf(new RemoteData(false, false, true, null, ['test', 'data']));
|
const searchServiceStub = jasmine.createSpyObj('SearchService', {
|
||||||
const searchServiceStub = jasmine.createSpyObj('SearchService', {
|
search: mockResults,
|
||||||
search: mockResults,
|
getSearchLink: '/search',
|
||||||
getSearchLink: '/search',
|
getScopes: observableOf(['test-scope'])
|
||||||
getScopes: observableOf(['test-scope'])
|
});
|
||||||
});
|
const queryParam = 'test query';
|
||||||
const queryParam = 'test query';
|
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
|
||||||
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
|
const fixedFilter = 'fixed filter';
|
||||||
const fixedFilter = 'fixed filter';
|
const paginatedSearchOptions = {
|
||||||
const paginatedSearchOptions = {
|
query: queryParam,
|
||||||
|
scope: scopeParam,
|
||||||
|
fixedFilter: fixedFilter,
|
||||||
|
pagination,
|
||||||
|
sort
|
||||||
|
};
|
||||||
|
const activatedRouteStub = {
|
||||||
|
queryParams: observableOf({
|
||||||
query: queryParam,
|
query: queryParam,
|
||||||
scope: scopeParam,
|
scope: scopeParam
|
||||||
fixedFilter: fixedFilter,
|
})
|
||||||
pagination,
|
};
|
||||||
sort
|
const sidebarService = {
|
||||||
};
|
isCollapsed: observableOf(true),
|
||||||
const activatedRouteStub = {
|
collapse: () => this.isCollapsed = observableOf(true),
|
||||||
queryParams: observableOf({
|
expand: () => this.isCollapsed = observableOf(false)
|
||||||
query: queryParam,
|
};
|
||||||
scope: scopeParam
|
|
||||||
})
|
|
||||||
};
|
|
||||||
const sidebarService = {
|
|
||||||
isCollapsed: observableOf(true),
|
|
||||||
collapse: () => this.isCollapsed = observableOf(true),
|
|
||||||
expand: () => this.isCollapsed = observableOf(false)
|
|
||||||
};
|
|
||||||
|
|
||||||
const routeServiceStub = {
|
const routeServiceStub = {
|
||||||
getRouteParameterValue: () => {
|
getRouteParameterValue: () => {
|
||||||
return observableOf('');
|
return observableOf('');
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export function configureSearchComponentTestingModule(compType) {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, NgbCollapseModule.forRoot()],
|
|
||||||
declarations: [compType],
|
|
||||||
providers: [
|
|
||||||
{ provide: SearchService, useValue: searchServiceStub },
|
|
||||||
{
|
|
||||||
provide: CommunityDataService,
|
|
||||||
useValue: jasmine.createSpyObj('communityService', ['findById', 'findAll'])
|
|
||||||
},
|
|
||||||
{ provide: ActivatedRoute, useValue: activatedRouteStub },
|
|
||||||
{
|
|
||||||
provide: Store, useValue: store
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: HostWindowService, useValue: jasmine.createSpyObj('hostWindowService',
|
|
||||||
{
|
|
||||||
isXs: observableOf(true),
|
|
||||||
isSm: observableOf(false),
|
|
||||||
isXsOrSm: observableOf(true)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: SearchSidebarService,
|
|
||||||
useValue: sidebarService
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: SearchFilterService,
|
|
||||||
useValue: {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: SearchConfigurationService,
|
|
||||||
useValue: {
|
|
||||||
paginatedSearchOptions: hot('a', {
|
|
||||||
a: paginatedSearchOptions
|
|
||||||
}),
|
|
||||||
getCurrentScope: (a) => observableOf('test-id'),
|
|
||||||
/* tslint:disable:no-empty */
|
|
||||||
updateFixedFilter: (newFilter) => {
|
|
||||||
}
|
|
||||||
/* tslint:enable:no-empty */
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: RouteService,
|
|
||||||
useValue: routeServiceStub
|
|
||||||
}
|
|
||||||
],
|
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
|
||||||
}).overrideComponent(compType, {
|
|
||||||
set: { changeDetection: ChangeDetectionStrategy.Default }
|
|
||||||
}).compileComponents();
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
describe('SearchPageComponent', () => {
|
export function configureSearchComponentTestingModule(compType) {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, NgbCollapseModule.forRoot()],
|
||||||
|
declarations: [compType],
|
||||||
|
providers: [
|
||||||
|
{ provide: SearchService, useValue: searchServiceStub },
|
||||||
|
{
|
||||||
|
provide: CommunityDataService,
|
||||||
|
useValue: jasmine.createSpyObj('communityService', ['findById', 'findAll'])
|
||||||
|
},
|
||||||
|
{ provide: ActivatedRoute, useValue: activatedRouteStub },
|
||||||
|
{
|
||||||
|
provide: Store, useValue: store
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: HostWindowService, useValue: jasmine.createSpyObj('hostWindowService',
|
||||||
|
{
|
||||||
|
isXs: observableOf(true),
|
||||||
|
isSm: observableOf(false),
|
||||||
|
isXsOrSm: observableOf(true)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: SearchSidebarService,
|
||||||
|
useValue: sidebarService
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: SearchFilterService,
|
||||||
|
useValue: {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: SearchConfigurationService,
|
||||||
|
useValue: {
|
||||||
|
paginatedSearchOptions: hot('a', {
|
||||||
|
a: paginatedSearchOptions
|
||||||
|
}),
|
||||||
|
getCurrentScope: (a) => observableOf('test-id'),
|
||||||
|
/* tslint:disable:no-empty */
|
||||||
|
updateFixedFilter: (newFilter) => {
|
||||||
|
}
|
||||||
|
/* tslint:enable:no-empty */
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: RouteService,
|
||||||
|
useValue: routeServiceStub
|
||||||
|
}
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(compType, {
|
||||||
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
|
}).compileComponents();
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(async(() => {
|
describe('SearchPageComponent', () => {
|
||||||
configureSearchComponentTestingModule(SearchPageComponent);
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
configureSearchComponentTestingModule(SearchPageComponent);
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SearchPageComponent);
|
||||||
|
comp = fixture.componentInstance; // SearchPageComponent test instance
|
||||||
|
fixture.detectChanges();
|
||||||
|
searchServiceObject = (comp as any).service;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get the scope and query from the route parameters', () => {
|
||||||
|
expect(comp.searchOptions$).toBeObservable(cold('b', {
|
||||||
|
b: paginatedSearchOptions
|
||||||
}));
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the closeSidebar event is emitted clicked in mobile view', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(SearchPageComponent);
|
spyOn(comp, 'closeSidebar');
|
||||||
comp = fixture.componentInstance; // SearchPageComponent test instance
|
const closeSidebarButton = fixture.debugElement.query(By.css('#search-sidebar-sm'));
|
||||||
|
closeSidebarButton.triggerEventHandler('toggleSidebar', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should trigger the closeSidebar function', () => {
|
||||||
|
expect(comp.closeSidebar).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the open sidebar button is clicked in mobile view', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'openSidebar');
|
||||||
|
const openSidebarButton = fixture.debugElement.query(By.css('.open-sidebar'));
|
||||||
|
openSidebarButton.triggerEventHandler('click', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should trigger the openSidebar function', () => {
|
||||||
|
expect(comp.openSidebar).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when sidebarCollapsed is true in mobile view', () => {
|
||||||
|
let menu: HTMLElement;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
menu = fixture.debugElement.query(By.css('#search-sidebar-sm')).nativeElement;
|
||||||
|
comp.isSidebarCollapsed = () => observableOf(true);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
searchServiceObject = (comp as any).service;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get the scope and query from the route parameters', () => {
|
it('should close the sidebar', () => {
|
||||||
expect(comp.searchOptions$).toBeObservable(cold('b', {
|
expect(menu.classList).not.toContain('active');
|
||||||
b: paginatedSearchOptions
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the closeSidebar event is emitted clicked in mobile view', () => {
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
describe('when sidebarCollapsed is false in mobile view', () => {
|
||||||
spyOn(comp, 'closeSidebar');
|
let menu: HTMLElement;
|
||||||
const closeSidebarButton = fixture.debugElement.query(By.css('#search-sidebar-sm'));
|
|
||||||
closeSidebarButton.triggerEventHandler('toggleSidebar', null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should trigger the closeSidebar function', () => {
|
|
||||||
expect(comp.closeSidebar).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
menu = fixture.debugElement.query(By.css('#search-sidebar-sm')).nativeElement;
|
||||||
|
comp.isSidebarCollapsed = () => observableOf(false);
|
||||||
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the open sidebar button is clicked in mobile view', () => {
|
it('should open the menu', () => {
|
||||||
|
expect(menu.classList).toContain('active');
|
||||||
beforeEach(() => {
|
|
||||||
spyOn(comp, 'openSidebar');
|
|
||||||
const openSidebarButton = fixture.debugElement.query(By.css('.open-sidebar'));
|
|
||||||
openSidebarButton.triggerEventHandler('click', null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should trigger the openSidebar function', () => {
|
|
||||||
expect(comp.openSidebar).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when sidebarCollapsed is true in mobile view', () => {
|
});
|
||||||
let menu: HTMLElement;
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
menu = fixture.debugElement.query(By.css('#search-sidebar-sm')).nativeElement;
|
|
||||||
comp.isSidebarCollapsed = () => observableOf(true);
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should close the sidebar', () => {
|
|
||||||
expect(menu.classList).not.toContain('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when sidebarCollapsed is false in mobile view', () => {
|
|
||||||
let menu: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
menu = fixture.debugElement.query(By.css('#search-sidebar-sm')).nativeElement;
|
|
||||||
comp.isSidebarCollapsed = () => observableOf(false);
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should open the menu', () => {
|
|
||||||
expect(menu.classList).toContain('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
@@ -204,7 +204,7 @@ describe('MetadataService', () => {
|
|||||||
undefined,
|
undefined,
|
||||||
MockItem
|
MockItem
|
||||||
));
|
));
|
||||||
}
|
};
|
||||||
|
|
||||||
const mockType = (mockItem: Item, type: string): Item => {
|
const mockType = (mockItem: Item, type: string): Item => {
|
||||||
const typedMockItem = Object.assign(new Item(), mockItem) as Item;
|
const typedMockItem = Object.assign(new Item(), mockItem) as Item;
|
||||||
@@ -215,7 +215,7 @@ describe('MetadataService', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return typedMockItem;
|
return typedMockItem;
|
||||||
}
|
};
|
||||||
|
|
||||||
const mockPublisher = (mockItem: Item): Item => {
|
const mockPublisher = (mockItem: Item): Item => {
|
||||||
const publishedMockItem = Object.assign(new Item(), mockItem) as Item;
|
const publishedMockItem = Object.assign(new Item(), mockItem) as Item;
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
import { EntityTypeSwitcherComponent } from './entity-type-switcher.component';
|
import { EntityTypeSwitcherComponent } from './entity-type-switcher.component';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import * as decorator from '../entity-type-decorator';
|
import * as decorator from '../entity-type-decorator';
|
||||||
import { ElementViewMode } from '../../view-mode';
|
|
||||||
import { getComponentByEntityType } from '../entity-type-decorator';
|
import { getComponentByEntityType } from '../entity-type-decorator';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { ElementViewMode } from '../../view-mode';
|
||||||
|
import createSpy = jasmine.createSpy;
|
||||||
|
|
||||||
const relationType = 'type';
|
const relationType = 'type';
|
||||||
const mockItem: Item = Object.assign(new Item(), {
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
@@ -44,7 +44,7 @@ describe('EntityTypeSwitcherComponent', () => {
|
|||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
comp.object = mockItem;
|
comp.object = mockItem;
|
||||||
comp.viewMode = viewMode;
|
comp.viewMode = viewMode;
|
||||||
spyOn(decorator, 'getComponentByEntityType').and.returnValue('component');
|
spyOnProperty(decorator, 'getComponentByEntityType').and.returnValue(createSpy('getComponentByEntityType'))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('when calling getComponent', () => {
|
describe('when calling getComponent', () => {
|
||||||
|
@@ -1,18 +1,16 @@
|
|||||||
import { Item } from '../../../../core/shared/item.model';
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
import { Observable } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { RemoteData } from '../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { ItemSearchResultListElementComponent } from './item-search-result-list-element.component';
|
import { ItemSearchResultListElementComponent } from './item-search-result-list-element.component';
|
||||||
import { of as observableOf } from 'rxjs';
|
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { TruncatableService } from '../../../truncatable/truncatable.service';
|
import { TruncatableService } from '../../../truncatable/truncatable.service';
|
||||||
import { TruncatePipe } from '../../../utils/truncate.pipe';
|
import { TruncatePipe } from '../../../utils/truncate.pipe';
|
||||||
import { createRelationshipsObservable } from '../../../../+item-page/simple/entity-types/shared/entity.component.spec';
|
import { createRelationshipsObservable } from '../../../../+item-page/simple/entity-types/shared/entity.component.spec';
|
||||||
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
|
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
|
||||||
import { of as observableOf } from 'rxjs';
|
|
||||||
|
|
||||||
const mockItem: Item = Object.assign(new Item(), {
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
bitstreams: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []))),
|
||||||
|
Reference in New Issue
Block a user