diff --git a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.spec.ts b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.spec.ts index c104de0b17..4b9dcef00d 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.spec.ts +++ b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.spec.ts @@ -25,6 +25,9 @@ import { NotificationsServiceStub } from '../../../shared/testing/notifications- import { RouterStub } from '../../../shared/testing/router.stub'; import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; import { RequestService } from '../../../core/data/request.service'; +import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('EPeopleRegistryComponent', () => { let component: EPeopleRegistryComponent; @@ -37,6 +40,8 @@ describe('EPeopleRegistryComponent', () => { let authorizationService: AuthorizationDataService; let modalService; + let paginationService; + beforeEach(waitForAsync(() => { mockEPeople = [EPersonMock, EPersonMock2]; ePersonDataServiceStub = { @@ -115,6 +120,16 @@ describe('EPeopleRegistryComponent', () => { }); builderService = getMockFormBuilderService(); translateService = getMockTranslateService(); + + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); TestBed.configureTestingModule({ imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, TranslateModule.forRoot({ @@ -131,7 +146,8 @@ describe('EPeopleRegistryComponent', () => { { provide: AuthorizationDataService, useValue: authorizationService }, { provide: FormBuilderService, useValue: builderService }, { provide: Router, useValue: new RouterStub() }, - { provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeByHrefSubstring']) } + { provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeByHrefSubstring']) }, + { provide: PaginationService, useValue: paginationService } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts index 1163490e12..e10c1af94c 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts +++ b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts @@ -26,6 +26,9 @@ import { AuthorizationDataService } from '../../../../core/data/feature-authoriz import { GroupDataService } from '../../../../core/eperson/group-data.service'; import { createPaginatedList } from '../../../../shared/testing/utils.test'; import { RequestService } from '../../../../core/data/request.service'; +import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model'; +import { PaginationService } from '../../../../core/pagination/pagination.service'; describe('EPersonFormComponent', () => { let component: EPersonFormComponent; @@ -38,6 +41,10 @@ describe('EPersonFormComponent', () => { let authorizationService: AuthorizationDataService; let groupsDataService: GroupDataService; + let paginationService: PaginationService; + + + beforeEach(waitForAsync(() => { mockEPeople = [EPersonMock, EPersonMock2]; ePersonDataServiceStub = { @@ -104,6 +111,17 @@ describe('EPersonFormComponent', () => { findAllByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])), getGroupRegistryRouterLink: '' }); + + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {} + }); TestBed.configureTestingModule({ imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, TranslateModule.forRoot({ @@ -121,6 +139,7 @@ describe('EPersonFormComponent', () => { { provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: AuthService, useValue: authService }, { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: PaginationService, useValue: paginationService }, { provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeByHrefSubstring']) } ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts index 8fc0d74aca..48f171f966 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts +++ b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts @@ -271,14 +271,12 @@ export class EPersonFormComponent implements OnInit, OnDestroy { })]); }), switchMap(([eperson, findListOptions]) => { - return this.groupsDataService.findAllByHref(eperson._links.groups.href, findListOptions); + if (eperson != null) { + return this.groupsDataService.findAllByHref(eperson._links.groups.href, findListOptions); + } + return observableOf(undefined); }) ); - // this.subs.push(combineLatest([activeEPerson$, paginationOption$]).subscribe(([eperson, options]) => { - // if (eperson != null) { - // this.groups = this.groupsDataService.findAllByHref(eperson._links.groups.href, options); - // } - // })); this.canImpersonate$ = activeEPerson$.pipe( switchMap((eperson) => this.authorizationService.isAuthorized(FeatureID.LoginOnBehalfOf, hasValue(eperson) ? eperson.self : undefined)) diff --git a/src/app/+admin/admin-access-control/group-registry/group-form/members-list/members-list.component.spec.ts b/src/app/+admin/admin-access-control/group-registry/group-form/members-list/members-list.component.spec.ts index 10735cbde5..ad1455ae0f 100644 --- a/src/app/+admin/admin-access-control/group-registry/group-form/members-list/members-list.component.spec.ts +++ b/src/app/+admin/admin-access-control/group-registry/group-form/members-list/members-list.component.spec.ts @@ -26,6 +26,10 @@ import { getMockFormBuilderService } from '../../../../../shared/mocks/form-buil import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock'; import { NotificationsServiceStub } from '../../../../../shared/testing/notifications-service.stub'; import { RouterMock } from '../../../../../shared/mocks/router.mock'; +import { PaginationComponentOptions } from '../../../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../../core/data/request.models'; +import { PaginationService } from '../../../../../core/pagination/pagination.service'; describe('MembersListComponent', () => { let component: MembersListComponent; @@ -39,6 +43,7 @@ describe('MembersListComponent', () => { let allGroups; let epersonMembers; let subgroupMembers; + let paginationService; beforeEach(waitForAsync(() => { activeGroup = GroupMock; @@ -113,6 +118,17 @@ describe('MembersListComponent', () => { }; builderService = getMockFormBuilderService(); translateService = getMockTranslateService(); + + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + clearPagination : {}, + }); TestBed.configureTestingModule({ imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, TranslateModule.forRoot({ @@ -129,6 +145,7 @@ describe('MembersListComponent', () => { { provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: FormBuilderService, useValue: builderService }, { provide: Router, useValue: new RouterMock() }, + { provide: PaginationService, useValue: paginationService }, ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/+admin/admin-access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts b/src/app/+admin/admin-access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts index 9841d2b02e..ea65e1b290 100644 --- a/src/app/+admin/admin-access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts +++ b/src/app/+admin/admin-access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts @@ -35,6 +35,10 @@ import { getMockTranslateService } from '../../../../../shared/mocks/translate.s import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock'; import { NotificationsServiceStub } from '../../../../../shared/testing/notifications-service.stub'; import { map } from 'rxjs/operators'; +import { PaginationComponentOptions } from '../../../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../../core/data/request.models'; +import { PaginationService } from '../../../../../core/pagination/pagination.service'; describe('SubgroupsListComponent', () => { let component: SubgroupsListComponent; @@ -47,6 +51,7 @@ describe('SubgroupsListComponent', () => { let subgroups; let allGroups; let routerStub; + let paginationService; beforeEach(waitForAsync(() => { activeGroup = GroupMock; @@ -100,6 +105,18 @@ describe('SubgroupsListComponent', () => { routerStub = new RouterMock(); builderService = getMockFormBuilderService(); translateService = getMockTranslateService(); + + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {}, + clearPagination: {} + }); TestBed.configureTestingModule({ imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, TranslateModule.forRoot({ @@ -115,6 +132,7 @@ describe('SubgroupsListComponent', () => { { provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: FormBuilderService, useValue: builderService }, { provide: Router, useValue: routerStub }, + { provide: PaginationService, useValue: paginationService }, ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts index dd08ea6772..ff75988607 100644 --- a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts +++ b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts @@ -28,6 +28,10 @@ import { TranslateLoaderMock } from '../../../shared/testing/translate-loader.mo import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; import { routeServiceStub } from '../../../shared/testing/route-service.stub'; import { RouterMock } from '../../../shared/mocks/router.mock'; +import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('GroupRegistryComponent', () => { let component: GroupsRegistryComponent; @@ -39,6 +43,7 @@ describe('GroupRegistryComponent', () => { let mockGroups; let mockEPeople; + let paginationService; beforeEach(waitForAsync(() => { mockGroups = [GroupMock, GroupMock2]; @@ -131,6 +136,16 @@ describe('GroupRegistryComponent', () => { authorizationService = jasmine.createSpyObj('authorizationService', { isAuthorized: observableOf(true) }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {} + }); TestBed.configureTestingModule({ imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, TranslateModule.forRoot({ @@ -149,6 +164,7 @@ describe('GroupRegistryComponent', () => { { provide: RouteService, useValue: routeServiceStub }, { provide: Router, useValue: new RouterMock() }, { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: PaginationService, useValue: paginationService }, { provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeByHrefSubstring']) } ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts index 6083efd6f7..cb55f0f2cd 100644 --- a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts +++ b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts @@ -9,7 +9,7 @@ import { of as observableOf, Subscription } from 'rxjs'; -import { catchError, map, switchMap, take, tap } from 'rxjs/operators'; +import { catchError, map, switchMap, take } from 'rxjs/operators'; import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service'; import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; @@ -25,9 +25,9 @@ import { RouteService } from '../../../core/services/route.service'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { getAllSucceededRemoteData, - getAllSucceededRemoteDataPayload, getFirstCompletedRemoteData, - getFirstSucceededRemoteData + getFirstSucceededRemoteData, + getRemoteDataPayload } from '../../../core/shared/operators'; import { PageInfo } from '../../../core/shared/page-info.model'; import { hasValue } from '../../../shared/empty.util'; @@ -113,72 +113,58 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy { * @param data Contains query param */ search(data: any) { - - const query: string = data.query; - if (query != null && this.currentSearchQuery !== query) { - this.router.navigateByUrl(this.groupService.getGroupRegistryRouterLink()); - this.currentSearchQuery = query; - this.config.currentPage = 1; - } if (hasValue(this.searchSub)) { this.searchSub.unsubscribe(); this.subs = this.subs.filter((sub: Subscription) => sub !== this.searchSub); } - this.searchSub = this.paginationService.getCurrentPagination(this.config.id, this.config).pipe( switchMap((paginationOptions) => { const query: string = data.query; if (query != null && this.currentSearchQuery !== query) { - this.router.navigate([], { - queryParamsHandling: 'merge' - }); this.currentSearchQuery = query; - this.paginationService.resetPage(this.config.id); - } - if (hasValue(this.searchSub)) { - this.searchSub.unsubscribe(); - this.subs = this.subs.filter((sub: Subscription) => sub !== this.searchSub); + this.paginationService.updateRouteWithUrl(this.config.id, [], {page: 1}); } return this.groupService.searchGroups(this.currentSearchQuery.trim(), { currentPage: paginationOptions.currentPage, elementsPerPage: paginationOptions.pageSize - }).pipe( - getAllSucceededRemoteData() - switchMap((groups: PaginatedList) => { - if (groups.page.length === 0) { - return observableOf(buildPaginatedList(groups.pageInfo, [])); - } - return observableCombineLatest(groups.page.map((group: Group) => { - if (!this.deletedGroupsIds.includes(group.id)) { - return observableCombineLatest([ - this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined), - this.hasLinkedDSO(group), - this.getSubgroups(group), - this.getMembers(group) - ]).pipe( - map(([isAuthorized, hasLinkedDSO, subgroups, members]: - [boolean, boolean, RemoteData>, RemoteData>]) => { - const groupDtoModel: GroupDtoModel = new GroupDtoModel(); - groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO; - groupDtoModel.group = group; - groupDtoModel.subgroups = subgroups.payload; - groupDtoModel.epersons = members.payload; - return groupDtoModel; - } - ) - ); - } - })).pipe(map((dtos: GroupDtoModel[]) => { - return buildPaginatedList(groups.pageInfo, dtos); - })); - }) - ). - subscribe((value: PaginatedList) => { - this.groupsDto$.next(value); - this.pageInfoState$.next(value.pageInfo); }); - this.subs.push(this.searchSub); + }), + getAllSucceededRemoteData(), + getRemoteDataPayload(), + switchMap((groups: PaginatedList) => { + if (groups.page.length === 0) { + return observableOf(buildPaginatedList(groups.pageInfo, [])); + } + return observableCombineLatest(groups.page.map((group: Group) => { + if (!this.deletedGroupsIds.includes(group.id)) { + return observableCombineLatest([ + this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined), + this.hasLinkedDSO(group), + this.getSubgroups(group), + this.getMembers(group) + ]).pipe( + map(([isAuthorized, hasLinkedDSO, subgroups, members]: + [boolean, boolean, RemoteData>, RemoteData>]) => { + const groupDtoModel: GroupDtoModel = new GroupDtoModel(); + groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO; + groupDtoModel.group = group; + groupDtoModel.subgroups = subgroups.payload; + groupDtoModel.epersons = members.payload; + return groupDtoModel; + } + ) + ); + } + })).pipe(map((dtos: GroupDtoModel[]) => { + return buildPaginatedList(groups.pageInfo, dtos); + })); + }) + ).subscribe((value: PaginatedList) => { + this.groupsDto$.next(value); + this.pageInfoState$.next(value.pageInfo); + }); + this.subs.push(this.searchSub); } /** diff --git a/src/app/+admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts b/src/app/+admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts index 74ca566029..5bed34d46b 100644 --- a/src/app/+admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts +++ b/src/app/+admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts @@ -23,6 +23,10 @@ import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { createPaginatedList } from '../../../shared/testing/utils.test'; +import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('BitstreamFormatsComponent', () => { let comp: BitstreamFormatsComponent; @@ -30,6 +34,7 @@ describe('BitstreamFormatsComponent', () => { let bitstreamFormatService; let scheduler: TestScheduler; let notificationsServiceStub; + let paginationService; const bitstreamFormat1 = new BitstreamFormat(); bitstreamFormat1.uuid = 'test-uuid-1'; @@ -79,6 +84,10 @@ describe('BitstreamFormatsComponent', () => { ]; const mockFormatsRD = createSuccessfulRemoteDataObject(createPaginatedList(mockFormatsList)); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const initAsync = () => { notificationsServiceStub = new NotificationsServiceStub(); @@ -95,13 +104,23 @@ describe('BitstreamFormatsComponent', () => { clearBitStreamFormatRequests: observableOf('cleared') }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + + + TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], declarations: [BitstreamFormatsComponent, PaginationComponent, EnumKeysPipe], providers: [ { provide: BitstreamFormatDataService, useValue: bitstreamFormatService }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, - { provide: NotificationsService, useValue: notificationsServiceStub } + { provide: NotificationsService, useValue: notificationsServiceStub }, + { provide: PaginationService, useValue: paginationService } ] }).compileComponents(); }; @@ -217,13 +236,23 @@ describe('BitstreamFormatsComponent', () => { clearBitStreamFormatRequests: observableOf('cleared') }); - TestBed.configureTestingModule({ + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + + + + TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], declarations: [BitstreamFormatsComponent, PaginationComponent, EnumKeysPipe], providers: [ { provide: BitstreamFormatDataService, useValue: bitstreamFormatService }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, - { provide: NotificationsService, useValue: notificationsServiceStub } + { provide: NotificationsService, useValue: notificationsServiceStub }, + { provide: PaginationService, useValue: paginationService } ] }).compileComponents(); } @@ -263,13 +292,22 @@ describe('BitstreamFormatsComponent', () => { clearBitStreamFormatRequests: observableOf('cleared') }); - TestBed.configureTestingModule({ + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + + + TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], declarations: [BitstreamFormatsComponent, PaginationComponent, EnumKeysPipe], providers: [ { provide: BitstreamFormatDataService, useValue: bitstreamFormatService }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, - { provide: NotificationsService, useValue: notificationsServiceStub } + { provide: NotificationsService, useValue: notificationsServiceStub }, + { provide: PaginationService, useValue: paginationService } ] }).compileComponents(); } diff --git a/src/app/+admin/admin-registries/metadata-registry/metadata-registry.component.spec.ts b/src/app/+admin/admin-registries/metadata-registry/metadata-registry.component.spec.ts index a5a65198af..beb900c17f 100644 --- a/src/app/+admin/admin-registries/metadata-registry/metadata-registry.component.spec.ts +++ b/src/app/+admin/admin-registries/metadata-registry/metadata-registry.component.spec.ts @@ -18,11 +18,16 @@ import { NotificationsServiceStub } from '../../../shared/testing/notifications- import { RestResponse } from '../../../core/cache/response.models'; import { MetadataSchema } from '../../../core/metadata/metadata-schema.model'; import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; +import { PaginationService } from '../../../core/pagination/pagination.service'; +import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; describe('MetadataRegistryComponent', () => { let comp: MetadataRegistryComponent; let fixture: ComponentFixture; let registryService: RegistryService; + let paginationService: PaginationService; const mockSchemasList = [ { id: 1, @@ -62,6 +67,15 @@ describe('MetadataRegistryComponent', () => { }; /* tslint:enable:no-empty */ + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], @@ -69,6 +83,7 @@ describe('MetadataRegistryComponent', () => { providers: [ { provide: RegistryService, useValue: registryServiceStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: PaginationService, useValue: paginationService }, { provide: NotificationsService, useValue: new NotificationsServiceStub() } ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/+admin/admin-registries/metadata-schema/metadata-schema.component.spec.ts b/src/app/+admin/admin-registries/metadata-schema/metadata-schema.component.spec.ts index 8c685c7012..35522462aa 100644 --- a/src/app/+admin/admin-registries/metadata-schema/metadata-schema.component.spec.ts +++ b/src/app/+admin/admin-registries/metadata-schema/metadata-schema.component.spec.ts @@ -23,6 +23,10 @@ import { MetadataSchema } from '../../../core/metadata/metadata-schema.model'; import { MetadataField } from '../../../core/metadata/metadata-field.model'; import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { VarDirective } from '../../../shared/utils/var.directive'; +import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('MetadataSchemaComponent', () => { let comp: MetadataSchemaComponent; @@ -125,6 +129,16 @@ describe('MetadataSchemaComponent', () => { }) }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], @@ -134,6 +148,7 @@ describe('MetadataSchemaComponent', () => { { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, { provide: Router, useValue: new RouterStub() }, + { provide: PaginationService, useValue: paginationService }, { provide: NotificationsService, useValue: new NotificationsServiceStub() } ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/+browse-by/+browse-by-date-page/browse-by-date-page.component.spec.ts b/src/app/+browse-by/+browse-by-date-page/browse-by-date-page.component.spec.ts index 87473a876b..50761b9521 100644 --- a/src/app/+browse-by/+browse-by-date-page/browse-by-date-page.component.spec.ts +++ b/src/app/+browse-by/+browse-by-date-page/browse-by-date-page.component.spec.ts @@ -18,11 +18,16 @@ import { BrowseEntrySearchOptions } from '../../core/browse/browse-entry-search- import { toRemoteData } from '../+browse-by-metadata-page/browse-by-metadata-page.component.spec'; import { VarDirective } from '../../shared/utils/var.directive'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../core/data/request.models'; +import { PaginationService } from '../../core/pagination/pagination.service'; describe('BrowseByDatePageComponent', () => { let comp: BrowseByDatePageComponent; let fixture: ComponentFixture; let route: ActivatedRoute; + let paginationService; const mockCommunity = Object.assign(new Community(), { id: 'test-uuid', @@ -65,6 +70,16 @@ describe('BrowseByDatePageComponent', () => { detectChanges: () => fixture.detectChanges() }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], @@ -74,6 +89,7 @@ describe('BrowseByDatePageComponent', () => { { provide: BrowseService, useValue: mockBrowseService }, { provide: DSpaceObjectDataService, useValue: mockDsoService }, { provide: Router, useValue: new RouterMock() }, + { provide: PaginationService, useValue: paginationService }, { provide: ChangeDetectorRef, useValue: mockCdRef } ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/+browse-by/+browse-by-metadata-page/browse-by-metadata-page.component.spec.ts b/src/app/+browse-by/+browse-by-metadata-page/browse-by-metadata-page.component.spec.ts index faa75af2f2..1c6336c2c8 100644 --- a/src/app/+browse-by/+browse-by-metadata-page/browse-by-metadata-page.component.spec.ts +++ b/src/app/+browse-by/+browse-by-metadata-page/browse-by-metadata-page.component.spec.ts @@ -14,7 +14,7 @@ import { RemoteData } from '../../core/data/remote-data'; import { buildPaginatedList, PaginatedList } from '../../core/data/paginated-list.model'; import { PageInfo } from '../../core/shared/page-info.model'; import { BrowseEntrySearchOptions } from '../../core/browse/browse-entry-search-options.model'; -import { SortDirection } from '../../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { Item } from '../../core/shared/item.model'; import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service'; import { Community } from '../../core/shared/community.model'; @@ -22,12 +22,18 @@ import { RouterMock } from '../../shared/mocks/router.mock'; import { BrowseEntry } from '../../core/shared/browse-entry.model'; import { VarDirective } from '../../shared/utils/var.directive'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; +import { PaginationService } from '../../core/pagination/pagination.service'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; describe('BrowseByMetadataPageComponent', () => { let comp: BrowseByMetadataPageComponent; let fixture: ComponentFixture; let browseService: BrowseService; let route: ActivatedRoute; + let paginationService: PaginationService; + + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); const mockCommunity = Object.assign(new Community(), { id: 'test-uuid', @@ -82,6 +88,12 @@ describe('BrowseByMetadataPageComponent', () => { params: observableOf({}) }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getRouteParameterValue: observableOf('') + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], @@ -90,6 +102,7 @@ describe('BrowseByMetadataPageComponent', () => { { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: BrowseService, useValue: mockBrowseService }, { provide: DSpaceObjectDataService, useValue: mockDsoService }, + { provide: PaginationService, useValue: paginationService }, { provide: Router, useValue: new RouterMock() } ], schemas: [NO_ERRORS_SCHEMA] @@ -133,18 +146,23 @@ describe('BrowseByMetadataPageComponent', () => { let result: BrowseEntrySearchOptions; beforeEach(() => { - const paramsWithPaginationAndScope = { - page: 5, - pageSize: 10, - sortDirection: SortDirection.ASC, - sortField: 'fake-field', + const paramsScope = { scope: 'fake-scope' }; + const paginationOptions = Object.assign(new PaginationComponentOptions(), { + currentPage: 5, + pageSize: 10, + }); + const sortOptions = { + direction: SortDirection.ASC, + field: 'fake-field', + }; - result = browseParamsToOptions(paramsWithPaginationAndScope, Object.assign({}), Object.assign({}), 'author'); + result = browseParamsToOptions(paramsScope, paginationOptions, sortOptions, 'author'); }); it('should return BrowseEntrySearchOptions with the correct properties', () => { + expect(result.metadataDefinition).toEqual('author'); expect(result.pagination.currentPage).toEqual(5); expect(result.pagination.pageSize).toEqual(10); diff --git a/src/app/+browse-by/+browse-by-title-page/browse-by-title-page.component.spec.ts b/src/app/+browse-by/+browse-by-title-page/browse-by-title-page.component.spec.ts index 4f7b2d5255..6ae10c6696 100644 --- a/src/app/+browse-by/+browse-by-title-page/browse-by-title-page.component.spec.ts +++ b/src/app/+browse-by/+browse-by-title-page/browse-by-title-page.component.spec.ts @@ -18,6 +18,10 @@ import { BrowseService } from '../../core/browse/browse.service'; import { RouterMock } from '../../shared/mocks/router.mock'; import { VarDirective } from '../../shared/utils/var.directive'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../core/data/request.models'; +import { PaginationService } from '../../core/pagination/pagination.service'; describe('BrowseByTitlePageComponent', () => { let comp: BrowseByTitlePageComponent; @@ -61,6 +65,16 @@ describe('BrowseByTitlePageComponent', () => { data: observableOf({ metadata: 'title' }) }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], @@ -69,6 +83,7 @@ describe('BrowseByTitlePageComponent', () => { { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: BrowseService, useValue: mockBrowseService }, { provide: DSpaceObjectDataService, useValue: mockDsoService }, + { provide: PaginationService, useValue: paginationService }, { provide: Router, useValue: new RouterMock() } ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.spec.ts b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.spec.ts index 13a91563c8..abb3d957bc 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.spec.ts +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.spec.ts @@ -18,6 +18,10 @@ import { PageInfo } from '../../core/shared/page-info.model'; import { HostWindowService } from '../../shared/host-window.service'; import { HostWindowServiceStub } from '../../shared/testing/host-window-service.stub'; import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../../core/pagination/pagination.service'; import { getMockThemeService } from '../../shared/mocks/theme-service.mock'; import { ThemeService } from '../../shared/theme-support/theme.service'; @@ -113,6 +117,17 @@ describe('CommunityPageSubCollectionList Component', () => { } }; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {} + }); + themeService = getMockThemeService(); beforeEach(waitForAsync(() => { @@ -128,6 +143,7 @@ describe('CommunityPageSubCollectionList Component', () => { providers: [ { provide: CollectionDataService, useValue: collectionDataServiceStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: PaginationService, useValue: paginationService }, { provide: SelectableListService, useValue: {} }, { provide: ThemeService, useValue: themeService }, ], @@ -161,28 +177,4 @@ describe('CommunityPageSubCollectionList Component', () => { const subComHead = fixture.debugElement.queryAll(By.css('h2')); expect(subComHead.length).toEqual(0); }); - - it('should update list of collections on pagination change', () => { - subCollList = collections; - fixture.detectChanges(); - - const pagination = Object.create({ - pagination:{ - id: comp.pageId, - currentPage: 2, - pageSize: 5 - }, - sort: { - field: 'dc.title', - direction: 'ASC' - } - }); - comp.onPaginationChange(pagination); - fixture.detectChanges(); - - const collList = fixture.debugElement.queryAll(By.css('li')); - expect(collList.length).toEqual(2); - expect(collList[0].nativeElement.textContent).toContain('Collection 6'); - expect(collList[1].nativeElement.textContent).toContain('Collection 7'); - }); }); diff --git a/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.spec.ts b/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.spec.ts index 21ba1b28b0..1054879f0e 100644 --- a/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.spec.ts +++ b/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.spec.ts @@ -18,6 +18,10 @@ import { HostWindowService } from '../../shared/host-window.service'; import { HostWindowServiceStub } from '../../shared/testing/host-window-service.stub'; import { CommunityDataService } from '../../core/data/community-data.service'; import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../../core/pagination/pagination.service'; import { getMockThemeService } from '../../shared/mocks/theme-service.mock'; import { ThemeService } from '../../shared/theme-support/theme.service'; @@ -114,6 +118,16 @@ describe('CommunityPageSubCommunityListComponent Component', () => { } }; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + themeService = getMockThemeService(); beforeEach(waitForAsync(() => { @@ -129,6 +143,7 @@ describe('CommunityPageSubCommunityListComponent Component', () => { providers: [ { provide: CommunityDataService, useValue: communityDataServiceStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: PaginationService, useValue: paginationService }, { provide: SelectableListService, useValue: {} }, { provide: ThemeService, useValue: themeService }, ], @@ -163,28 +178,4 @@ describe('CommunityPageSubCommunityListComponent Component', () => { const subComHead = fixture.debugElement.queryAll(By.css('h2')); expect(subComHead.length).toEqual(0); }); - - it('should update list of sub-communities on pagination change', () => { - subCommList = subcommunities; - fixture.detectChanges(); - - const pagination = Object.create({ - pagination:{ - id: comp.pageId, - currentPage: 2, - pageSize: 5 - }, - sort: { - field: 'dc.title', - direction: 'ASC' - } - }); - comp.onPaginationChange(pagination); - fixture.detectChanges(); - - const collList = fixture.debugElement.queryAll(By.css('li')); - expect(collList.length).toEqual(2); - expect(collList[0].nativeElement.textContent).toContain('SubCommunity 6'); - expect(collList[1].nativeElement.textContent).toContain('SubCommunity 7'); - }); }); diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.spec.ts b/src/app/+home-page/top-level-community-list/top-level-community-list.component.spec.ts index 0daa0a0ae0..4a5549cf4a 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.spec.ts +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.spec.ts @@ -18,6 +18,10 @@ import { HostWindowService } from '../../shared/host-window.service'; import { HostWindowServiceStub } from '../../shared/testing/host-window-service.stub'; import { CommunityDataService } from '../../core/data/community-data.service'; import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service'; +import { of as observableOf } from 'rxjs'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; +import { PaginationService } from '../../core/pagination/pagination.service'; import { getMockThemeService } from '../../shared/mocks/theme-service.mock'; import { ThemeService } from '../../shared/theme-support/theme.service'; @@ -25,6 +29,7 @@ describe('TopLevelCommunityList Component', () => { let comp: TopLevelCommunityListComponent; let fixture: ComponentFixture; let communityDataServiceStub: any; + let paginationService; let themeService; const topCommList = [Object.assign(new Community(), { @@ -104,6 +109,15 @@ describe('TopLevelCommunityList Component', () => { } }; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getRouteParameterValue: observableOf('') + }); + themeService = getMockThemeService(); beforeEach(waitForAsync(() => { @@ -119,6 +133,7 @@ describe('TopLevelCommunityList Component', () => { providers: [ { provide: CommunityDataService, useValue: communityDataServiceStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: PaginationService, useValue: paginationService }, { provide: SelectableListService, useValue: {} }, { provide: ThemeService, useValue: themeService }, ], @@ -143,25 +158,4 @@ describe('TopLevelCommunityList Component', () => { expect(subComList[3].nativeElement.textContent).toContain('TopCommunity 4'); expect(subComList[4].nativeElement.textContent).toContain('TopCommunity 5'); }); - - it('should update list of top-communities on pagination change', () => { - const pagination = Object.create({ - pagination: { - id: comp.pageId, - currentPage: 2, - pageSize: 5 - }, - sort: { - field: 'dc.title', - direction: 'ASC' - } - }); - comp.onPaginationChange(pagination); - fixture.detectChanges(); - - const collList = fixture.debugElement.queryAll(By.css('li')); - expect(collList.length).toEqual(2); - expect(collList[0].nativeElement.textContent).toContain('TopCommunity 6'); - expect(collList[1].nativeElement.textContent).toContain('TopCommunity 7'); - }); }); diff --git a/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/paginated-drag-and-drop-bitstream-list/paginated-drag-and-drop-bitstream-list.component.spec.ts b/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/paginated-drag-and-drop-bitstream-list/paginated-drag-and-drop-bitstream-list.component.spec.ts index 717c5873d2..f3c50f4d13 100644 --- a/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/paginated-drag-and-drop-bitstream-list/paginated-drag-and-drop-bitstream-list.component.spec.ts +++ b/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/paginated-drag-and-drop-bitstream-list/paginated-drag-and-drop-bitstream-list.component.spec.ts @@ -16,6 +16,10 @@ import { ResponsiveColumnSizes } from '../../../../../shared/responsive-table-si import { createSuccessfulRemoteDataObject$ } from '../../../../../shared/remote-data.utils'; import { createPaginatedList } from '../../../../../shared/testing/utils.test'; import { RequestService } from '../../../../../core/data/request.service'; +import { PaginationService } from '../../../../../core/pagination/pagination.service'; +import { PaginationComponentOptions } from '../../../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../../core/data/request.models'; describe('PaginatedDragAndDropBitstreamListComponent', () => { let comp: PaginatedDragAndDropBitstreamListComponent; @@ -24,6 +28,7 @@ describe('PaginatedDragAndDropBitstreamListComponent', () => { let bundleService: BundleDataService; let objectValuesPipe: ObjectValuesPipe; let requestService: RequestService; + let paginationService: PaginationService; const columnSizes = new ResponsiveTableSizes([ new ResponsiveColumnSizes(2, 2, 3, 4, 4), @@ -109,6 +114,16 @@ describe('PaginatedDragAndDropBitstreamListComponent', () => { hasByHref$: observableOf(true) }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], declarations: [PaginatedDragAndDropBitstreamListComponent, VarDirective], @@ -116,7 +131,8 @@ describe('PaginatedDragAndDropBitstreamListComponent', () => { { provide: ObjectUpdatesService, useValue: objectUpdatesService }, { provide: BundleDataService, useValue: bundleService }, { provide: ObjectValuesPipe, useValue: objectValuesPipe }, - { provide: RequestService, useValue: requestService } + { provide: RequestService, useValue: requestService }, + { provide: PaginationService, useValue: paginationService } ], schemas: [ NO_ERRORS_SCHEMA ] diff --git a/src/app/+item-page/full/field-components/file-section/full-file-section.component.spec.ts b/src/app/+item-page/full/field-components/file-section/full-file-section.component.spec.ts index 1773a0fe74..0723354ef5 100644 --- a/src/app/+item-page/full/field-components/file-section/full-file-section.component.spec.ts +++ b/src/app/+item-page/full/field-components/file-section/full-file-section.component.spec.ts @@ -16,6 +16,10 @@ import { MockBitstreamFormat1 } from '../../../../shared/mocks/item.mock'; import { By } from '@angular/platform-browser'; import { NotificationsService } from '../../../../shared/notifications/notifications.service'; import { NotificationsServiceStub } from '../../../../shared/testing/notifications-service.stub'; +import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../core/data/request.models'; +import { PaginationService } from '../../../../core/pagination/pagination.service'; describe('FullFileSectionComponent', () => { let comp: FullFileSectionComponent; @@ -52,6 +56,16 @@ describe('FullFileSectionComponent', () => { findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(createPaginatedList([mockBitstream, mockBitstream, mockBitstream])) }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ @@ -64,7 +78,8 @@ describe('FullFileSectionComponent', () => { declarations: [FullFileSectionComponent, VarDirective, FileSizePipe, MetadataFieldWrapperComponent], providers: [ { provide: BitstreamDataService, useValue: bitstreamDataService }, - { provide: NotificationsService, useValue: new NotificationsServiceStub() } + { provide: NotificationsService, useValue: new NotificationsServiceStub() }, + { provide: PaginationService, useValue: paginationService } ], schemas: [NO_ERRORS_SCHEMA] @@ -82,39 +97,5 @@ describe('FullFileSectionComponent', () => { const fileSection = fixture.debugElement.queryAll(By.css('.file-section')); expect(fileSection.length).toEqual(6); }); - - describe('when we press the pageChange button for original bundle', () => { - beforeEach(() => { - comp.switchOriginalPage(2); - fixture.detectChanges(); - }); - - it('should give the value to the currentpage', () => { - expect(comp.originalOptions.currentPage).toBe(2); - }); - it('should call the next function on the originalCurrentPage', (done) => { - comp.originalCurrentPage$.subscribe((event) => { - expect(event).toEqual(2); - done(); - }); - }); - }); - - describe('when we press the pageChange button for license bundle', () => { - beforeEach(() => { - comp.switchLicensePage(2); - fixture.detectChanges(); - }); - - it('should give the value to the currentpage', () => { - expect(comp.licenseOptions.currentPage).toBe(2); - }); - it('should call the next function on the licenseCurrentPage', (done) => { - comp.licenseCurrentPage$.subscribe((event) => { - expect(event).toEqual(2); - done(); - }); - }); - }); }); }); diff --git a/src/app/+my-dspace-page/my-dspace-configuration.service.spec.ts b/src/app/+my-dspace-page/my-dspace-configuration.service.spec.ts index 6cbab8125b..86489019d9 100644 --- a/src/app/+my-dspace-page/my-dspace-configuration.service.spec.ts +++ b/src/app/+my-dspace-page/my-dspace-configuration.service.spec.ts @@ -34,12 +34,18 @@ describe('MyDSpaceConfigurationService', () => { getRouteDataValue: observableOf({}) }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(defaults.pagination), + getCurrentSort: observableOf(defaults.sort), + getRouteParameterValue: observableOf('') + }); + const activatedRoute: any = new ActivatedRouteStub(); const roleService: any = new RoleServiceMock(); beforeEach(() => { - service = new MyDSpaceConfigurationService(roleService, spy, activatedRoute); + service = new MyDSpaceConfigurationService(roleService, spy, paginationService, activatedRoute); }); describe('when the scope is called', () => { @@ -102,25 +108,19 @@ describe('MyDSpaceConfigurationService', () => { describe('when getCurrentSort is called', () => { beforeEach(() => { - // service.getCurrentSort({} as any); + service.getCurrentSort('page-id', defaults.sort); }); - it('should call getQueryParameterValue on the routeService with parameter name \'sortDirection\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('sortDirection'); - }); - it('should call getQueryParameterValue on the routeService with parameter name \'sortField\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('sortField'); + it('should call getCurrentSort on the paginationService with the provided id and sort options', () => { + expect((service as any).paginationService.getCurrentSort).toHaveBeenCalledWith('page-id', defaults.sort); }); }); describe('when getCurrentPagination is called', () => { beforeEach(() => { - // service.getCurrentPagination({ currentPage: 1, pageSize: 10 } as any); + service.getCurrentPagination('page-id', defaults.pagination); }); - it('should call getQueryParameterValue on the routeService with parameter name \'page\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('page'); - }); - it('should call getQueryParameterValue on the routeService with parameter name \'pageSize\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('pageSize'); + it('should call getCurrentPagination on the paginationService with the provided id and sort options', () => { + expect((service as any).paginationService.getCurrentPagination).toHaveBeenCalledWith('page-id', defaults.pagination); }); }); @@ -152,7 +152,7 @@ describe('MyDSpaceConfigurationService', () => { describe('when subscribeToPaginatedSearchOptions is called', () => { beforeEach(() => { - (service as any).subscribeToPaginatedSearchOptions(defaults); + (service as any).subscribeToPaginatedSearchOptions('id', defaults); }); it('should call all getters it needs', () => { expect(service.getCurrentPagination).toHaveBeenCalled(); diff --git a/src/app/+my-dspace-page/my-dspace-configuration.service.ts b/src/app/+my-dspace-page/my-dspace-configuration.service.ts index 19eba0fa06..82f76eb776 100644 --- a/src/app/+my-dspace-page/my-dspace-configuration.service.ts +++ b/src/app/+my-dspace-page/my-dspace-configuration.service.ts @@ -56,6 +56,7 @@ export class MyDSpaceConfigurationService extends SearchConfigurationService { * * @param {roleService} roleService * @param {RouteService} routeService + * @param {PaginationService} paginationService * @param {ActivatedRoute} route */ constructor(protected roleService: RoleService, diff --git a/src/app/core/pagination/pagination.service.spec.ts b/src/app/core/pagination/pagination.service.spec.ts new file mode 100644 index 0000000000..990dcd9b90 --- /dev/null +++ b/src/app/core/pagination/pagination.service.spec.ts @@ -0,0 +1,149 @@ +import { PaginationService } from './pagination.service'; +import { RouterStub } from '../../shared/testing/router.stub'; +import { of as observableOf } from 'rxjs'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../cache/models/sort-options.model'; +import { FindListOptions } from '../data/request.models'; + + +describe('PaginationService', () => { + let service: PaginationService; + let router; + let routeService; + + const defaultPagination = new PaginationComponentOptions(); + const defaultSort = new SortOptions('id', SortDirection.DESC); + const defaultFindListOptions = new FindListOptions(); + + beforeEach(() => { + router = new RouterStub(); + routeService = { + getQueryParameterValue: (param) => { + let value; + if (param.startsWith('p.')) { + value = 5; + } + if (param.startsWith('rpp.')) { + value = 10; + } + if (param.startsWith('sd.')) { + value = 'ASC'; + } + if (param.startsWith('sf.')) { + value = 'score'; + } + return observableOf(value); + } + }; + + service = new PaginationService(routeService, router); + }); + + + describe('getCurrentPagination', () => { + it('should retrieve the current pagination info from the routerService', () => { + service.getCurrentPagination('test-id', defaultPagination).subscribe((currentPagination) => { + expect(currentPagination).toEqual(Object.assign(new PaginationComponentOptions(), { + currentPage: 5, + pageSize: 10 + })); + }); + }); + }); + describe('getCurrentSort', () => { + it('should retrieve the current sort info from the routerService', () => { + service.getCurrentSort('test-id', defaultSort).subscribe((currentSort) => { + expect(currentSort).toEqual(Object.assign(new SortOptions('score', SortDirection.ASC ))); + }); + }); + }); + describe('getFindListOptions', () => { + it('should retrieve the current findListOptions info from the routerService', () => { + service.getFindListOptions('test-id', defaultFindListOptions).subscribe((findListOptions) => { + expect(findListOptions).toEqual(Object.assign(new FindListOptions(), + { + sort: new SortOptions('score', SortDirection.ASC ), + currentPage: 5, + elementsPerPage: 10 + })); + }); + }); + }); + describe('resetPage', () => { + it('should call the updateRoute method with the id and page 1', () => { + spyOn(service, 'updateRoute'); + service.resetPage('test'); + + expect(service.updateRoute).toHaveBeenCalledWith('test', {page: 1}); + }); + }); + + describe('updateRoute', () => { + it('should update the route with the provided page params', () => { + service.updateRoute('test', {page: 2, pageSize: 5, sortField: 'title', sortDirection: SortDirection.DESC}); + + const navigateParams = {}; + navigateParams[`p.test`] = `2`; + navigateParams[`rpp.test`] = `5`; + navigateParams[`sf.test`] = `title`; + navigateParams[`sd.test`] = `DESC`; + + expect(router.navigate).toHaveBeenCalledWith([], {queryParams: navigateParams, queryParamsHandling: 'merge'}); + }); + it('should update the route with the provided page params while keeping the existing non provided ones', () => { + service.updateRoute('test', {page: 2}); + + const navigateParams = {}; + navigateParams[`p.test`] = `2`; + navigateParams[`rpp.test`] = `10`; + navigateParams[`sf.test`] = `score`; + navigateParams[`sd.test`] = `ASC`; + + expect(router.navigate).toHaveBeenCalledWith([], {queryParams: navigateParams, queryParamsHandling: 'merge'}); + }); + }); + describe('updateRouteWithUrl', () => { + it('should update the route with the provided page params and url', () => { + service.updateRouteWithUrl('test', ['someUrl'], {page: 2, pageSize: 5, sortField: 'title', sortDirection: SortDirection.DESC}); + + const navigateParams = {}; + navigateParams[`p.test`] = `2`; + navigateParams[`rpp.test`] = `5`; + navigateParams[`sf.test`] = `title`; + navigateParams[`sd.test`] = `DESC`; + + expect(router.navigate).toHaveBeenCalledWith(['someUrl'], {queryParams: navigateParams, queryParamsHandling: 'merge'}); + }); + it('should update the route with the provided page params and url while keeping the existing non provided ones', () => { + service.updateRouteWithUrl('test',['someUrl'], {page: 2}); + + const navigateParams = {}; + navigateParams[`p.test`] = `2`; + navigateParams[`rpp.test`] = `10`; + navigateParams[`sf.test`] = `score`; + navigateParams[`sd.test`] = `ASC`; + + expect(router.navigate).toHaveBeenCalledWith(['someUrl'], {queryParams: navigateParams, queryParamsHandling: 'merge'}); + }); + + }); + describe('clearPagination', () => { + it('should clear the pagination info from the route for the current id', () => { + service.clearPagination('test'); + + const params = {}; + params[`p.test`] = null; + params[`rpp.test`] = null; + params[`sf.test`] = null; + params[`sd.test`] = null; + + expect(router.navigate).toHaveBeenCalledWith([], {queryParams: params, queryParamsHandling: 'merge'}); + }); + }); + describe('getPageParam', () => { + it('should return the name of the page param', () => { + const pageParam = service.getPageParam('test'); + expect(pageParam).toEqual('p.test'); + }); + }); +}); diff --git a/src/app/core/pagination/pagination.service.ts b/src/app/core/pagination/pagination.service.ts index 0143d20923..29e57214c1 100644 --- a/src/app/core/pagination/pagination.service.ts +++ b/src/app/core/pagination/pagination.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { Router } from '@angular/router'; import { RouteService } from '../services/route.service'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; @@ -9,7 +9,6 @@ import { FindListOptions } from '../data/request.models'; import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; import { difference } from '../../shared/object.util'; import { isNumeric } from 'rxjs/internal-compatibility'; -import { Location } from '@angular/common'; @Injectable({ @@ -20,9 +19,7 @@ export class PaginationService { private defaultSortOptions = new SortOptions('id', SortDirection.ASC); constructor(protected routeService: RouteService, - protected route: ActivatedRoute, - protected router: Router, - protected location: Location + protected router: Router ) { } @@ -33,6 +30,7 @@ export class PaginationService { const page$ = this.routeService.getQueryParameterValue(`p.${paginationId}`); const size$ = this.routeService.getQueryParameterValue(`rpp.${paginationId}`); return observableCombineLatest([page$, size$]).pipe(map(([page, size]) => { + console.log(page, size); return Object.assign(new PaginationComponentOptions(), defaultPagination, { currentPage: this.convertToNumeric(page, defaultPagination.currentPage), pageSize: this.getBestMatchPageSize(size, defaultPagination) @@ -80,7 +78,7 @@ export class PaginationService { this.updateRoute(paginationId, {page: 1}); } - getCurrentRouting(paginationId: string) { + private getCurrentRouting(paginationId: string) { return this.getFindListOptions(paginationId, {}, true).pipe( take(1), map((findListoptions: FindListOptions) => { @@ -88,7 +86,7 @@ export class PaginationService { page: findListoptions.currentPage, pageSize: findListoptions.elementsPerPage, sortField: findListoptions.sort.field, - sortDir: findListoptions.sort.direction, + sortDirection: findListoptions.sort.direction, }; }) ); @@ -101,12 +99,12 @@ export class PaginationService { sortDirection?: SortDirection }, extraParams?, retainScrollPosition?: boolean) { this.getCurrentRouting(paginationId).subscribe((currentFindListOptions) => { + console.log('currentFindListOptions',currentFindListOptions ); const currentParametersWithIdName = this.getParametersWithIdName(paginationId, currentFindListOptions); const parametersWithIdName = this.getParametersWithIdName(paginationId, params); if (isNotEmpty(difference(parametersWithIdName, currentParametersWithIdName)) || isNotEmpty(extraParams)) { const queryParams = Object.assign({}, currentParametersWithIdName, parametersWithIdName, extraParams); - console.log(retainScrollPosition); if (retainScrollPosition) { this.router.navigate([], { queryParams: queryParams, @@ -169,7 +167,7 @@ export class PaginationService { return `p.${paginationId}`; } - getParametersWithIdName(paginationId: string, params: { + private getParametersWithIdName(paginationId: string, params: { page?: number pageSize?: number sortField?: string diff --git a/src/app/core/shared/search/search-configuration.service.spec.ts b/src/app/core/shared/search/search-configuration.service.spec.ts index 43c2c54427..f1f9dc7b9b 100644 --- a/src/app/core/shared/search/search-configuration.service.spec.ts +++ b/src/app/core/shared/search/search-configuration.service.spec.ts @@ -15,7 +15,7 @@ describe('SearchConfigurationService', () => { 'f.date.max': ['2018'] }; const defaults = new PaginatedSearchOptions({ - pagination: Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }), + pagination: Object.assign(new PaginationComponentOptions(), { id: 'page-id', currentPage: 1, pageSize: 20 }), sort: new SortOptions('score', SortDirection.DESC), configuration: 'default', query: '', @@ -30,10 +30,17 @@ describe('SearchConfigurationService', () => { getRouteParameterValue: observableOf('') }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(defaults.pagination), + getCurrentSort: observableOf(defaults.sort), + getRouteParameterValue: observableOf('') + }); + + const activatedRoute: any = new ActivatedRouteStub(); beforeEach(() => { - service = new SearchConfigurationService(routeService, activatedRoute); + service = new SearchConfigurationService(routeService, paginationService, activatedRoute); }); describe('when the scope is called', () => { beforeEach(() => { @@ -95,25 +102,19 @@ describe('SearchConfigurationService', () => { describe('when getCurrentSort is called', () => { beforeEach(() => { - service.getCurrentSort({} as any); + service.getCurrentSort(defaults.pagination.id, {} as any); }); - it('should call getQueryParameterValue on the routeService with parameter name \'sortDirection\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('sortDirection'); - }); - it('should call getQueryParameterValue on the routeService with parameter name \'sortField\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('sortField'); + it('should call getCurrentSort on the paginationService with the provided id and sort options', () => { + expect((service as any).paginationService.getCurrentSort).toHaveBeenCalledWith(defaults.pagination.id, {}); }); }); describe('when getCurrentPagination is called', () => { beforeEach(() => { - service.getCurrentPagination({ currentPage: 1, pageSize: 10 } as any); + service.getCurrentPagination(defaults.pagination.id, defaults.pagination); }); - it('should call getQueryParameterValue on the routeService with parameter name \'page\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('page'); - }); - it('should call getQueryParameterValue on the routeService with parameter name \'pageSize\'', () => { - expect((service as any).routeService.getQueryParameterValue).toHaveBeenCalledWith('pageSize'); + it('should call getCurrentPagination on the paginationService with the provided id and sort options', () => { + expect((service as any).paginationService.getCurrentPagination).toHaveBeenCalledWith(defaults.pagination.id, defaults.pagination); }); }); @@ -145,7 +146,7 @@ describe('SearchConfigurationService', () => { describe('when subscribeToPaginatedSearchOptions is called', () => { beforeEach(() => { - (service as any).subscribeToPaginatedSearchOptions(defaults); + (service as any).subscribeToPaginatedSearchOptions(defaults.pagination.id, defaults); }); it('should call all getters it needs', () => { expect(service.getCurrentPagination).toHaveBeenCalled(); diff --git a/src/app/core/shared/search/search.service.spec.ts b/src/app/core/shared/search/search.service.spec.ts index 06208094bd..9eb650219b 100644 --- a/src/app/core/shared/search/search.service.spec.ts +++ b/src/app/core/shared/search/search.service.spec.ts @@ -22,6 +22,11 @@ import { routeServiceStub } from '../../../shared/testing/route-service.stub'; import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service'; import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { SearchObjects } from '../../../shared/search/search-objects.model'; +import { PaginationService } from '../../pagination/pagination.service'; +import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../cache/models/sort-options.model'; +import { FindListOptions } from '../../data/request.models'; +import { SearchConfigurationService } from './search-configuration.service'; @Component({ template: '' }) class DummyComponent { @@ -32,6 +37,7 @@ describe('SearchService', () => { let searchService: SearchService; const router = new RouterStub(); const route = new ActivatedRouteStub(); + const searchConfigService = {paginationID: 'page-id'}; beforeEach(() => { TestBed.configureTestingModule({ imports: [ @@ -51,6 +57,8 @@ describe('SearchService', () => { { provide: HALEndpointService, useValue: {} }, { provide: CommunityDataService, useValue: {} }, { provide: DSpaceObjectDataService, useValue: {} }, + { provide: PaginationService, useValue: {} }, + { provide: SearchConfigurationService, useValue: searchConfigService }, SearchService ], }); @@ -94,6 +102,18 @@ describe('SearchService', () => { } }; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {} + }); + const searchConfigService = {paginationID: 'page-id'}; + beforeEach(() => { TestBed.configureTestingModule({ imports: [ @@ -113,6 +133,8 @@ describe('SearchService', () => { { provide: HALEndpointService, useValue: halService }, { provide: CommunityDataService, useValue: {} }, { provide: DSpaceObjectDataService, useValue: {} }, + { provide: PaginationService, useValue: paginationService }, + { provide: SearchConfigurationService, useValue: searchConfigService }, SearchService ], }); @@ -124,18 +146,14 @@ describe('SearchService', () => { it('should call the navigate method on the Router with view mode list parameter as a parameter when setViewMode is called', () => { searchService.setViewMode(ViewMode.ListElement); - expect(router.navigate).toHaveBeenCalledWith(['/search'], { - queryParams: { view: ViewMode.ListElement, page: 1 }, - queryParamsHandling: 'merge' - }); + expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.ListElement } + ); }); it('should call the navigate method on the Router with view mode grid parameter as a parameter when setViewMode is called', () => { searchService.setViewMode(ViewMode.GridElement); - expect(router.navigate).toHaveBeenCalledWith(['/search'], { - queryParams: { view: ViewMode.GridElement, page: 1 }, - queryParamsHandling: 'merge' - }); + expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.GridElement } + ); }); it('should return ViewMode.List when the viewMode is set to ViewMode.List in the ActivatedRoute', () => { diff --git a/src/app/process-page/overview/process-overview.component.spec.ts b/src/app/process-page/overview/process-overview.component.spec.ts index ffbcbb10cf..1da2ac2b5b 100644 --- a/src/app/process-page/overview/process-overview.component.spec.ts +++ b/src/app/process-page/overview/process-overview.component.spec.ts @@ -12,6 +12,11 @@ import { By } from '@angular/platform-browser'; import { ProcessStatus } from '../processes/process-status.model'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; import { createPaginatedList } from '../../shared/testing/utils.test'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../../core/pagination/pagination.service'; +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../core/data/request.models'; describe('ProcessOverviewComponent', () => { let component: ProcessOverviewComponent; @@ -19,10 +24,15 @@ describe('ProcessOverviewComponent', () => { let processService: ProcessDataService; let ePersonService: EPersonDataService; + let paginationService: PaginationService; let processes: Process[]; let ePerson: EPerson; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + function init() { processes = [ Object.assign(new Process(), { @@ -69,6 +79,12 @@ describe('ProcessOverviewComponent', () => { ePersonService = jasmine.createSpyObj('ePersonService', { findById: createSuccessfulRemoteDataObject$(ePerson) }); + + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + }); } beforeEach(waitForAsync(() => { @@ -78,7 +94,8 @@ describe('ProcessOverviewComponent', () => { imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], providers: [ { provide: ProcessDataService, useValue: processService }, - { provide: EPersonDataService, useValue: ePersonService } + { provide: EPersonDataService, useValue: ePersonService }, + { provide: PaginationService, useValue: paginationService } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); @@ -143,16 +160,4 @@ describe('ProcessOverviewComponent', () => { }); }); }); - - describe('onPageChange', () => { - const toPage = 2; - - beforeEach(() => { - component.onPageChange(toPage); - }); - - it('should call a new findAll with the corresponding page', () => { - expect(processService.findAll).toHaveBeenCalledWith(jasmine.objectContaining({ currentPage: toPage })); - }); - }); }); diff --git a/src/app/search-navbar/search-navbar.component.spec.ts b/src/app/search-navbar/search-navbar.component.spec.ts index 9eef81a42e..87b75328bb 100644 --- a/src/app/search-navbar/search-navbar.component.spec.ts +++ b/src/app/search-navbar/search-navbar.component.spec.ts @@ -8,6 +8,11 @@ import { SearchService } from '../core/shared/search/search.service'; import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock'; import { SearchNavbarComponent } from './search-navbar.component'; +import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../core/pagination/pagination.service'; +import { SearchConfigurationService } from '../core/shared/search/search-configuration.service'; describe('SearchNavbarComponent', () => { let component: SearchNavbarComponent; @@ -15,6 +20,7 @@ describe('SearchNavbarComponent', () => { let mockSearchService: any; let router: Router; let routerStub; + let paginationService; beforeEach(waitForAsync(() => { mockSearchService = { @@ -26,6 +32,18 @@ describe('SearchNavbarComponent', () => { routerStub = { navigate: (commands) => commands }; + + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getRouteParameterValue: observableOf(''), + updateRouteWithUrl: {}, + clearPagination : {} + }); + TestBed.configureTestingModule({ imports: [ FormsModule, @@ -40,7 +58,9 @@ describe('SearchNavbarComponent', () => { declarations: [SearchNavbarComponent], providers: [ { provide: SearchService, useValue: mockSearchService }, - { provide: Router, useValue: routerStub } + { provide: PaginationService, useValue: paginationService }, + { provide: Router, useValue: routerStub }, + { provide: SearchConfigurationService, useValue: {paginationID: 'page-id'} } ] }) .compileComponents(); @@ -88,7 +108,7 @@ describe('SearchNavbarComponent', () => { })); it('to search page with empty query', () => { expect(component.onSubmit).toHaveBeenCalledWith({ query: '' }); - expect(router.navigate).toHaveBeenCalled(); + expect(paginationService.updateRouteWithUrl).toHaveBeenCalled(); }); }); }); @@ -112,7 +132,7 @@ describe('SearchNavbarComponent', () => { })); it('to search page with query', async () => { expect(component.onSubmit).toHaveBeenCalledWith({ query: 'test' }); - expect(router.navigate).toHaveBeenCalled(); + expect(paginationService.updateRouteWithUrl).toHaveBeenCalled(); }); }); }); diff --git a/src/app/shared/browse-by/browse-by.component.spec.ts b/src/app/shared/browse-by/browse-by.component.spec.ts index 9f3ceade1a..4c9ac9204d 100644 --- a/src/app/shared/browse-by/browse-by.component.spec.ts +++ b/src/app/shared/browse-by/browse-by.component.spec.ts @@ -18,6 +18,8 @@ import { PaginationComponentOptions } from '../pagination/pagination-component-o import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils'; import { storeModuleConfig } from '../../app.reducer'; +import { FindListOptions } from '../../core/data/request.models'; +import { PaginationService } from '../../core/pagination/pagination.service'; describe('BrowseByComponent', () => { let comp: BrowseByComponent; @@ -45,6 +47,22 @@ describe('BrowseByComponent', () => { ]; const mockItemsRD$ = createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), mockItems)); + const paginationConfig = Object.assign(new PaginationComponentOptions(), { + id: 'test-pagination', + currentPage: 1, + pageSizeOptions: [5, 10, 15, 20], + pageSize: 15 + }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(paginationConfig), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + updateRoute: {}, + resetPage: {}, + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [ @@ -63,7 +81,9 @@ describe('BrowseByComponent', () => { BrowserAnimationsModule ], declarations: [], - providers: [], + providers: [ + {provide: PaginationService, useValue: paginationService} + ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); })); @@ -95,12 +115,8 @@ describe('BrowseByComponent', () => { beforeEach(() => { comp.enableArrows = true; comp.objects$ = mockItemsRD$; - comp.paginationConfig = Object.assign(new PaginationComponentOptions(), { - id: 'test-pagination', - currentPage: 1, - pageSizeOptions: [5, 10, 15, 20], - pageSize: 15 - }); + + comp.paginationConfig = paginationConfig; comp.sortConfig = Object.assign(new SortOptions('dc.title', SortDirection.ASC)); fixture.detectChanges(); }); @@ -136,8 +152,8 @@ describe('BrowseByComponent', () => { fixture.detectChanges(); }); - it('should emit a signal to the EventEmitter', () => { - expect(comp.pageSizeChange.emit).toHaveBeenCalled(); + it('should call the updateRoute method from the paginationService', () => { + expect(paginationService.updateRoute).toHaveBeenCalledWith('test-pagination', {pageSize: paginationConfig.pageSizeOptions[0]}); }); }); @@ -148,8 +164,8 @@ describe('BrowseByComponent', () => { fixture.detectChanges(); }); - it('should emit a signal to the EventEmitter', () => { - expect(comp.sortDirectionChange.emit).toHaveBeenCalled(); + it('should call the updateRoute method from the paginationService', () => { + expect(paginationService.updateRoute).toHaveBeenCalledWith('test-pagination', {sortDirection: 'ASC'}); }); }); }); diff --git a/src/app/shared/browse-by/browse-by.component.ts b/src/app/shared/browse-by/browse-by.component.ts index 8920726c8b..1f05ad2258 100644 --- a/src/app/shared/browse-by/browse-by.component.ts +++ b/src/app/shared/browse-by/browse-by.component.ts @@ -144,7 +144,7 @@ export class BrowseByComponent implements OnInit { this.objectInjector = Injector.create({ providers: [ { provide: 'startsWithOptions', useFactory: () => (this.startsWithOptions), deps:[] }, - { provide: 'paginationId', useFactory: () => (this.paginationConfig.id), deps:[] } + { provide: 'paginationId', useFactory: () => (this.paginationConfig?.id), deps:[] } ], parent: this.injector }); diff --git a/src/app/shared/item/item-versions/item-versions.component.spec.ts b/src/app/shared/item/item-versions/item-versions.component.spec.ts index f35ec1993d..33e99eb88f 100644 --- a/src/app/shared/item/item-versions/item-versions.component.spec.ts +++ b/src/app/shared/item/item-versions/item-versions.component.spec.ts @@ -11,11 +11,18 @@ import { VersionHistoryDataService } from '../../../core/data/version-history-da import { By } from '@angular/platform-browser'; import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils'; import { createPaginatedList } from '../../testing/utils.test'; +import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('ItemVersionsComponent', () => { let component: ItemVersionsComponent; let fixture: ComponentFixture; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const versionHistory = Object.assign(new VersionHistory(), { id: '1' }); @@ -52,12 +59,19 @@ describe('ItemVersionsComponent', () => { getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions)) }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getRouteParameterValue: observableOf('') + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [ItemVersionsComponent, VarDirective], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], providers: [ - { provide: VersionHistoryDataService, useValue: versionHistoryService } + { provide: VersionHistoryDataService, useValue: versionHistoryService }, + { provide: PaginationService, useValue: paginationService } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); @@ -107,16 +121,4 @@ describe('ItemVersionsComponent', () => { expect(summary.nativeElement.textContent).toEqual(version.summary); }); }); - - describe('switchPage', () => { - const page = 5; - - beforeEach(() => { - component.switchPage(page); - }); - - it('should set the option\'s currentPage to the new page', () => { - expect(component.options.currentPage).toEqual(page); - }); - }); }); diff --git a/src/app/shared/object-select/collection-select/collection-select.component.spec.ts b/src/app/shared/object-select/collection-select/collection-select.component.spec.ts index fd4a239cc4..60cce1ae09 100644 --- a/src/app/shared/object-select/collection-select/collection-select.component.spec.ts +++ b/src/app/shared/object-select/collection-select/collection-select.component.spec.ts @@ -13,6 +13,10 @@ import { CollectionSelectComponent } from './collection-select.component'; import { Collection } from '../../../core/shared/collection.model'; import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils'; import { createPaginatedList } from '../../testing/utils.test'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('CollectionSelectComponent', () => { let comp: CollectionSelectComponent; @@ -36,13 +40,24 @@ describe('CollectionSelectComponent', () => { currentPage: 1 }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), SharedModule, RouterTestingModule.withRoutes([])], declarations: [], providers: [ { provide: ObjectSelectService, useValue: new ObjectSelectServiceStub([mockCollectionList[1].id]) }, - { provide: HostWindowService, useValue: new HostWindowServiceStub(0) } + { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: PaginationService, useValue: paginationService } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/shared/object-select/item-select/item-select.component.spec.ts b/src/app/shared/object-select/item-select/item-select.component.spec.ts index f99991f391..2ca3cd4fa8 100644 --- a/src/app/shared/object-select/item-select/item-select.component.spec.ts +++ b/src/app/shared/object-select/item-select/item-select.component.spec.ts @@ -11,14 +11,18 @@ import { HostWindowService } from '../../host-window.service'; import { HostWindowServiceStub } from '../../testing/host-window-service.stub'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { of } from 'rxjs'; +import { of as observableOf, of } from 'rxjs'; import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils'; import { createPaginatedList } from '../../testing/utils.test'; +import { PaginationService } from '../../../core/pagination/pagination.service'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; describe('ItemSelectComponent', () => { let comp: ItemSelectComponent; let fixture: ComponentFixture; let objectSelectService: ObjectSelectService; + let paginationService: PaginationService; const mockItemList = [ Object.assign(new Item(), { @@ -59,13 +63,25 @@ describe('ItemSelectComponent', () => { currentPage: 1 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(mockPaginationOptions), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + + + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), SharedModule, RouterTestingModule.withRoutes([])], declarations: [], providers: [ { provide: ObjectSelectService, useValue: new ObjectSelectServiceStub([mockItemList[1].id]) }, - { provide: HostWindowService, useValue: new HostWindowServiceStub(0) } + { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: PaginationService, useValue: paginationService } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/shared/page-size-selector/page-size-selector.component.spec.ts b/src/app/shared/page-size-selector/page-size-selector.component.spec.ts index f75b5841af..cf7f1d5e11 100644 --- a/src/app/shared/page-size-selector/page-size-selector.component.spec.ts +++ b/src/app/shared/page-size-selector/page-size-selector.component.spec.ts @@ -12,6 +12,7 @@ import { SortDirection, SortOptions } from '../../core/cache/models/sort-options import { EnumKeysPipe } from '../utils/enum-keys-pipe'; import { VarDirective } from '../utils/var.directive'; import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component'; +import { PaginationService } from '../../core/pagination/pagination.service'; describe('PageSizeSelectorComponent', () => { @@ -33,6 +34,12 @@ describe('PageSizeSelectorComponent', () => { sort }; + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getRouteParameterValue: observableOf('') + }); + const activatedRouteStub = { queryParams: observableOf({ query: queryParam, @@ -46,6 +53,7 @@ describe('PageSizeSelectorComponent', () => { declarations: [PageSizeSelectorComponent, EnumKeysPipe, VarDirective], providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: PaginationService, useValue: paginationService }, { provide: SEARCH_CONFIG_SERVICE, useValue: { diff --git a/src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.spec.ts b/src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.spec.ts index 905b739270..4c29e2af9d 100644 --- a/src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.spec.ts +++ b/src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.spec.ts @@ -11,6 +11,9 @@ import { PaginationComponent } from '../pagination/pagination.component'; import { createSuccessfulRemoteDataObject } from '../remote-data.utils'; import { createPaginatedList } from '../testing/utils.test'; import { ObjectValuesPipe } from '../utils/object-values-pipe'; +import { PaginationService } from '../../core/pagination/pagination.service'; +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; @Component({ selector: 'ds-mock-paginated-drag-drop-abstract', @@ -22,8 +25,9 @@ class MockAbstractPaginatedDragAndDropListComponent extends AbstractPaginatedDra protected elRef: ElementRef, protected objectValuesPipe: ObjectValuesPipe, protected mockUrl: string, - protected mockObjectsRD$: Observable>>) { - super(objectUpdatesService, elRef, objectValuesPipe); + protected paginationService: PaginationService, + protected mockObjectsRD$: Observable>>) { + super(objectUpdatesService, elRef, objectValuesPipe, paginationService); } initializeObjectsRD(): void { @@ -43,10 +47,14 @@ describe('AbstractPaginatedDragAndDropListComponent', () => { const url = 'mock-abstract-paginated-drag-and-drop-list-component'; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const object1 = Object.assign(new DSpaceObject(), { uuid: 'object-1' }); const object2 = Object.assign(new DSpaceObject(), { uuid: 'object-2' }); const objectsRD = createSuccessfulRemoteDataObject(createPaginatedList([object1, object2])); let objectsRD$: BehaviorSubject>>; + let paginationService; const updates = { [object1.uuid]: { field: object1, changeType: undefined }, @@ -69,8 +77,13 @@ describe('AbstractPaginatedDragAndDropListComponent', () => { paginationComponent = jasmine.createSpyObj('paginationComponent', { doPageChange: {} }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getRouteParameterValue: observableOf('') + }); objectsRD$ = new BehaviorSubject(objectsRD); - component = new MockAbstractPaginatedDragAndDropListComponent(objectUpdatesService, elRef, objectValuesPipe, url, objectsRD$); + component = new MockAbstractPaginatedDragAndDropListComponent(objectUpdatesService, elRef, objectValuesPipe, url, paginationService, objectsRD$); component.paginationComponent = paginationComponent; component.ngOnInit(); }); @@ -86,18 +99,6 @@ describe('AbstractPaginatedDragAndDropListComponent', () => { }); }); - describe('switchPage', () => { - const page = 3; - - beforeEach(() => { - component.switchPage(page); - }); - - it('should set currentPage$ to the new page', () => { - expect(component.currentPage$.value).toEqual(page); - }); - }); - describe('drop', () => { const event = { previousIndex: 0, diff --git a/src/app/shared/pagination/pagination.component.spec.ts b/src/app/shared/pagination/pagination.component.spec.ts index 684ffb55e8..bad54d6e83 100644 --- a/src/app/shared/pagination/pagination.component.spec.ts +++ b/src/app/shared/pagination/pagination.component.spec.ts @@ -31,10 +31,15 @@ import { SortDirection, SortOptions } from '../../core/cache/models/sort-options import { createTestComponent } from '../testing/utils.test'; import { storeModuleConfig } from '../../app.reducer'; +import { PaginationService } from '../../core/pagination/pagination.service'; +import { FindListOptions } from '../../core/data/request.models'; +import { BehaviorSubject, of as observableOf } from 'rxjs'; function expectPages(fixture: ComponentFixture, pagesDef: string[]): void { const de = fixture.debugElement.query(By.css('.pagination')); const pages = de.nativeElement.querySelectorAll('li'); + console.log('pages', pages.length, pagesDef.length); + console.log(pages); expect(pages.length).toEqual(pagesDef.length); @@ -105,14 +110,39 @@ describe('Pagination component', () => { let activatedRouteStub: MockActivatedRoute; let routerStub: RouterMock; + let paginationService: PaginationService; + // Define initial state and test state const _initialState = { width: 1600, height: 770 }; + const pagination = new PaginationComponentOptions(); + pagination.currentPage = 1; + pagination.pageSize = 10; + + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 10 }); + let currentPagination; + let currentSort; + let currentFindListOptions; + // waitForAsync beforeEach beforeEach(waitForAsync(() => { activatedRouteStub = new MockActivatedRoute(); - routerStub = new RouterMock(); - hostWindowServiceStub = new HostWindowServiceMock(_initialState.width); + routerStub = new RouterMock(); hostWindowServiceStub = new HostWindowServiceMock(_initialState.width); + + currentPagination = new BehaviorSubject(pagination); + currentSort = new BehaviorSubject(sort); + currentFindListOptions = new BehaviorSubject(findlistOptions); + + + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: currentPagination, + getCurrentSort: currentSort, + getFindListOptions: currentFindListOptions, + resetPage: {}, + updateRoute: {}, + updateRouteWithUrl: {} + }); TestBed.configureTestingModule({ imports: [ @@ -138,6 +168,7 @@ describe('Pagination component', () => { { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useValue: routerStub }, { provide: HostWindowService, useValue: hostWindowServiceStub }, + { provide: PaginationService, useValue: paginationService }, ChangeDetectorRef, PaginationComponent ], @@ -179,11 +210,17 @@ describe('Pagination component', () => { it('should render and respond to page change', () => { testComp.collectionSize = 30; + testFixture.detectChanges(); + + + currentPagination.next(Object.assign(new PaginationComponentOptions(), pagination, {currentPage: 3})); + testFixture.detectChanges(); - changePage(testFixture, 3); expectPages(testFixture, ['« Previous', '1', '2', '+3', '-» Next']); - changePage(testFixture, 0); + currentPagination.next(Object.assign(new PaginationComponentOptions(), pagination, {currentPage: 2})); + testFixture.detectChanges(); + expectPages(testFixture, ['« Previous', '1', '+2', '3', '» Next']); }); @@ -205,58 +242,41 @@ describe('Pagination component', () => { testFixture.detectChanges(); expectPages(testFixture, ['-« Previous', '+1', '2', '3', '» Next']); - paginationComponent.setPageSize(5); + currentPagination.next(Object.assign(new PaginationComponentOptions(), pagination, {pageSize: 5})); testFixture.detectChanges(); + expectPages(testFixture, ['-« Previous', '+1', '2', '3', '4', '5', '6', '» Next']); - paginationComponent.setPageSize(10); + currentPagination.next(Object.assign(new PaginationComponentOptions(), pagination, {pageSize: 10})); testFixture.detectChanges(); expectPages(testFixture, ['-« Previous', '+1', '2', '3', '» Next']); - paginationComponent.setPageSize(20); + currentPagination.next(Object.assign(new PaginationComponentOptions(), pagination, {pageSize: 20})); testFixture.detectChanges(); expectPages(testFixture, ['-« Previous', '+1', '2', '» Next']); }); - it('should emit pageChange event with correct value', fakeAsync(() => { - const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p; - - spyOn(testComp, 'pageChanged'); - - paginationComponent.setPage(3); - tick(); - - expect(testComp.pageChanged).toHaveBeenCalledWith(3); - })); - it('should emit pageSizeChange event with correct value', fakeAsync(() => { const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p; spyOn(testComp, 'pageSizeChanged'); - paginationComponent.setPageSize(5); + testComp.pageSizeChanged(5); tick(); expect(testComp.pageSizeChanged).toHaveBeenCalledWith(5); })); - it('should set correct page route parameters', fakeAsync(() => { - routerStub = testFixture.debugElement.injector.get(Router) as any; - + it('should call the updateRoute method on the paginationService with the correct params', fakeAsync(() => { testComp.collectionSize = 60; changePage(testFixture, 3); tick(); - expect(routerStub.navigate).toHaveBeenCalledWith([], { - queryParams: { - pageId: 'test', - page: '3', - pageSize: 10, - sortDirection: 'ASC', - sortField: 'dc.title' - }, queryParamsHandling: 'merge' - }); + expect(paginationService.updateRoute).toHaveBeenCalledWith('test', Object.assign({ page: '3'}), {}, false); + changePage(testFixture, 0); + tick(); + expect(paginationService.updateRoute).toHaveBeenCalledWith('test', Object.assign({ page: '2'}), {}, false); })); it('should set correct pageSize route parameters', fakeAsync(() => { @@ -266,58 +286,9 @@ describe('Pagination component', () => { changePageSize(testFixture, '20'); tick(); - expect(routerStub.navigate).toHaveBeenCalledWith([], { - queryParams: { - pageId: 'test', - page: 1, - pageSize: 20, - sortDirection: 'ASC', - sortField: 'dc.title' - }, queryParamsHandling: 'merge' - }); + expect(paginationService.updateRoute).toHaveBeenCalledWith('test', Object.assign({ pageId: 'test', page: 1, pageSize: 20}), {}, false); })); - it('should set correct values', fakeAsync(() => { - const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p; - routerStub = testFixture.debugElement.injector.get(Router) as any; - - testComp.collectionSize = 60; - - paginationComponent.setPage(3); - expect(paginationComponent.currentPage).toEqual(3); - - paginationComponent.setPageSize(20); - expect(paginationComponent.pageSize).toEqual(20); - })); - - it('should get parameters from route', () => { - - activatedRouteStub = testFixture.debugElement.injector.get(ActivatedRoute) as any; - activatedRouteStub.testParams = { - pageId: 'test', - page: 2, - pageSize: 20 - }; - - testFixture.detectChanges(); - - expectPages(testFixture, ['« Previous', '1', '+2', '3', '4', '5', '» Next']); - expect(testComp.paginationOptions.currentPage).toEqual(2); - expect(testComp.paginationOptions.pageSize).toEqual(20); - - activatedRouteStub.testParams = { - pageId: 'test', - page: 3, - pageSize: 40 - }; - - testFixture.detectChanges(); - - expectPages(testFixture, ['« Previous', '1', '2', '+3', '-» Next']); - expect(testComp.paginationOptions.currentPage).toEqual(3); - expect(testComp.paginationOptions.pageSize).toEqual(40); - }); - it('should respond to windows resize', () => { const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p; hostWindowServiceStub = testFixture.debugElement.injector.get(HostWindowService) as any; diff --git a/src/app/shared/pagination/pagination.component.ts b/src/app/shared/pagination/pagination.component.ts index d126565e8f..4a181d7090 100644 --- a/src/app/shared/pagination/pagination.component.ts +++ b/src/app/shared/pagination/pagination.component.ts @@ -20,6 +20,7 @@ import { hasValue } from '../empty.util'; import { PageInfo } from '../../core/shared/page-info.model'; import { PaginationService } from '../../core/pagination/pagination.service'; import { map } from 'rxjs/operators'; +import { tap } from 'rxjs/internal/operators/tap'; /** * The default pagination controls component. @@ -194,11 +195,14 @@ export class PaginationComponent implements OnDestroy, OnInit { this.id = this.paginationOptions.id || null; this.pageSizeOptions = this.paginationOptions.pageSizeOptions; this.currentPage$ = this.paginationService.getCurrentPagination(this.id, this.paginationOptions).pipe( + tap((v) => console.log('currentPage', v)), map((currentPagination) => currentPagination.currentPage) ); this.pageSize$ = this.paginationService.getCurrentPagination(this.id, this.paginationOptions).pipe( map((currentPagination) => currentPagination.pageSize) ); + this.pageSize$.subscribe((v) => console.log('this.pageSize$', v)); + this.currentPage$.subscribe((v) => console.log('this.currentPage$', v)); let sortOptions; if (this.sortOptions) { @@ -237,6 +241,7 @@ export class PaginationComponent implements OnDestroy, OnInit { */ public doPageChange(page: number) { this.updateParams({page: page.toString()}); + this.emitPaginationChange(); } /** @@ -247,6 +252,7 @@ export class PaginationComponent implements OnDestroy, OnInit { */ public doPageSizeChange(pageSize: number) { this.updateParams({ pageId: this.id, page: 1, pageSize: pageSize }); + this.emitPaginationChange(); } /** @@ -257,6 +263,7 @@ export class PaginationComponent implements OnDestroy, OnInit { */ public doSortDirectionChange(sortDirection: SortDirection) { this.updateParams({ pageId: this.id, page: 1, sortDirection: sortDirection }); + this.emitPaginationChange(); } /** @@ -267,50 +274,6 @@ export class PaginationComponent implements OnDestroy, OnInit { */ public doSortFieldChange(field: string) { this.updateParams({ pageId: this.id, page: 1, sortField: field }); - } - - /** - * Method to set the current page and trigger page change events - * - * @param page - * The new page value - */ - public setPage(page: number) { - this.pageChange.emit(page); - this.emitPaginationChange(); - } - - /** - * Method to set the current page size and trigger page size change events - * - * @param pageSize - * The new page size value. - */ - public setPageSize(pageSize: number) { - this.pageSizeChange.emit(pageSize); - this.emitPaginationChange(); - } - - /** - * Method to set the current sort direction and trigger sort direction change events - * - * @param sortDirection - * The new sort directionvalue. - */ - public setSortDirection(sortDirection: SortDirection) { - this.sortDirectionChange.emit(sortDirection); - this.emitPaginationChange(); - } - - /** - * Method to set the current sort field and trigger sort field change events - * - * @param sortField - * The new sort field. - */ - public setSortField(field: string) { - // this.sortField = field; - this.sortFieldChange.emit(field); this.emitPaginationChange(); } @@ -370,21 +333,6 @@ export class PaginationComponent implements OnDestroy, OnInit { } } - /** - * Method to check if none of the query params necessary for pagination are filled out. - * - * @param paginateOptions - * The paginate options object. - */ - private isEmptyPaginationParams(paginateOptions): boolean { - const properties = ['id', 'currentPage', 'pageSize', 'pageSizeOptions']; - const missing = properties.filter((prop) => { - return !(prop in paginateOptions); - }); - - return properties.length === missing.length; - } - /** * Property to check whether the current pagination object has multiple pages * @returns true if there are multiple pages, else returns false diff --git a/src/app/shared/resource-policies/form/eperson-group-list/eperson-group-list.component.spec.ts b/src/app/shared/resource-policies/form/eperson-group-list/eperson-group-list.component.spec.ts index db01146bfe..a683a536b4 100644 --- a/src/app/shared/resource-policies/form/eperson-group-list/eperson-group-list.component.spec.ts +++ b/src/app/shared/resource-policies/form/eperson-group-list/eperson-group-list.component.spec.ts @@ -19,6 +19,9 @@ import { PaginationComponentOptions } from '../../../pagination/pagination-compo import { buildPaginatedList } from '../../../../core/data/paginated-list.model'; import { PageInfo } from '../../../../core/shared/page-info.model'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../core/data/request.models'; +import { PaginationService } from '../../../../core/pagination/pagination.service'; describe('EpersonGroupListComponent test suite', () => { let comp: EpersonGroupListComponent; @@ -27,6 +30,7 @@ describe('EpersonGroupListComponent test suite', () => { let de; let groupService: any; let epersonService: any; + let paginationService; const paginationOptions: PaginationComponentOptions = new PaginationComponentOptions(); paginationOptions.id = uniqueId('eperson-group-list-pagination-test'); @@ -60,6 +64,16 @@ describe('EpersonGroupListComponent test suite', () => { const groupPaginatedList = buildPaginatedList(new PageInfo(), [GroupMock, GroupMock]); const groupPaginatedListRD = createSuccessfulRemoteDataObject(groupPaginatedList); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(paginationOptions), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + clearPagination: {} + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [ @@ -74,6 +88,7 @@ describe('EpersonGroupListComponent test suite', () => { { provide: EPersonDataService, useValue: mockEpersonService }, { provide: GroupDataService, useValue: mockGroupService }, { provide: RequestService, useValue: getMockRequestService() }, + { provide: PaginationService, useValue: paginationService }, EpersonGroupListComponent, ChangeDetectorRef, Injector @@ -177,12 +192,6 @@ describe('EpersonGroupListComponent test suite', () => { a: false })); }); - - it('should update list on page change', () => { - spyOn(comp, 'updateList'); - - expect(compAsAny.updateList).toHaveBeenCalled(); - }); }); describe('when is list of group', () => { @@ -254,12 +263,6 @@ describe('EpersonGroupListComponent test suite', () => { })); }); - it('should update list on page change', () => { - spyOn(comp, 'updateList'); - - expect(compAsAny.updateList).toHaveBeenCalled(); - }); - it('should update list on search triggered', () => { const options: PaginationComponentOptions = comp.paginationOptions; const event: SearchEvent = { @@ -269,7 +272,7 @@ describe('EpersonGroupListComponent test suite', () => { spyOn(comp, 'updateList'); comp.onSearch(event); - expect(compAsAny.updateList).toHaveBeenCalledWith(options, 'metadata', 'test'); + expect(compAsAny.updateList).toHaveBeenCalledWith('metadata', 'test'); }); }); }); 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 f2293afeca..635d11f0d0 100644 --- a/src/app/shared/search-form/search-form.component.spec.ts +++ b/src/app/shared/search-form/search-form.component.spec.ts @@ -8,6 +8,12 @@ import { Community } from '../../core/shared/community.model'; import { TranslateModule } from '@ngx-translate/core'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { SearchService } from '../../core/shared/search/search.service'; +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../core/data/request.models'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../../core/pagination/pagination.service'; +import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; describe('SearchFormComponent', () => { let comp: SearchFormComponent; @@ -15,6 +21,19 @@ describe('SearchFormComponent', () => { let de: DebugElement; let el: HTMLElement; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {} + }); + + const searchConfigService = {paginationID: 'test-id'}; + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [FormsModule, RouterTestingModule, TranslateModule.forRoot()], @@ -22,7 +41,9 @@ describe('SearchFormComponent', () => { { provide: SearchService, useValue: {} - } + }, + { provide: PaginationService, useValue: paginationService }, + { provide: SearchConfigurationService, useValue: searchConfigService } ], declarations: [SearchFormComponent] }).compileComponents(); diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts index 4b2e5d2344..a01843248e 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts @@ -15,6 +15,10 @@ import { FacetValue } from '../../../../facet-value.model'; import { FilterType } from '../../../../filter-type.model'; import { SearchFilterConfig } from '../../../../search-filter-config.model'; import { SearchFacetOptionComponent } from './search-facet-option.component'; +import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../../../core/data/request.models'; +import { PaginationService } from '../../../../../../core/pagination/pagination.service'; describe('SearchFacetOptionComponent', () => { let comp: SearchFacetOptionComponent; @@ -81,6 +85,17 @@ describe('SearchFacetOptionComponent', () => { let router; const page = observableOf(0); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + getPageParam: 'p.page-id', + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule], @@ -88,8 +103,10 @@ describe('SearchFacetOptionComponent', () => { providers: [ { provide: SearchService, useValue: new SearchServiceStub(searchLink) }, { provide: Router, useValue: new RouterStub() }, + { provide: PaginationService, useValue: paginationService }, { provide: SearchConfigurationService, useValue: { + paginationID: 'page-id', searchOptions: observableOf({}) } }, @@ -131,7 +148,7 @@ describe('SearchFacetOptionComponent', () => { (comp as any).updateAddParams(selectedValues); expect(comp.addQueryParams).toEqual({ [mockFilterConfig.paramName]: [`${value1},${operator}`, value.value + ',equals'], - page: 1 + ['p.page-id']: 1 }); }); }); @@ -146,7 +163,7 @@ describe('SearchFacetOptionComponent', () => { (comp as any).updateAddParams(selectedValues); expect(comp.addQueryParams).toEqual({ [mockAuthorityFilterConfig.paramName]: [value1 + ',equals', `${value2},${operator}`], - page: 1 + ['p.page-id']: 1 }); }); }); diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.spec.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.spec.ts index f5df1f038a..6329655eca 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.spec.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-range-option/search-facet-range-option.component.spec.ts @@ -19,6 +19,10 @@ import { RANGE_FILTER_MAX_SUFFIX, RANGE_FILTER_MIN_SUFFIX } from '../../search-range-filter/search-range-filter.component'; +import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../../../core/data/request.models'; +import { PaginationService } from '../../../../../../core/pagination/pagination.service'; describe('SearchFacetRangeOptionComponent', () => { let comp: SearchFacetRangeOptionComponent; @@ -54,6 +58,18 @@ describe('SearchFacetRangeOptionComponent', () => { let router; const page = observableOf(0); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {}, + getPageParam: 'p.page-id', + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule], @@ -61,9 +77,11 @@ describe('SearchFacetRangeOptionComponent', () => { providers: [ { provide: SearchService, useValue: new SearchServiceStub(searchLink) }, { provide: Router, useValue: new RouterStub() }, + { provide: PaginationService, useValue: paginationService }, { provide: SearchConfigurationService, useValue: { - searchOptions: observableOf({}) + searchOptions: observableOf({}), + paginationId: 'page-id' } }, { @@ -116,7 +134,7 @@ describe('SearchFacetRangeOptionComponent', () => { expect(comp.changeQueryParams).toEqual({ [mockFilterConfig.paramName + RANGE_FILTER_MIN_SUFFIX]: ['50'], [mockFilterConfig.paramName + RANGE_FILTER_MAX_SUFFIX]: ['60'], - page: 1 + ['p.page-id']: 1 }); }); }); diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.spec.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.spec.ts index 69945d86f2..60c4fd5721 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.spec.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-selected-option/search-facet-selected-option.component.spec.ts @@ -14,6 +14,10 @@ import { FacetValue } from '../../../../facet-value.model'; import { FilterType } from '../../../../filter-type.model'; import { SearchFilterConfig } from '../../../../search-filter-config.model'; import { SearchFacetSelectedOptionComponent } from './search-facet-selected-option.component'; +import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../../../core/data/request.models'; +import { PaginationService } from '../../../../../../core/pagination/pagination.service'; describe('SearchFacetSelectedOptionComponent', () => { let comp: SearchFacetSelectedOptionComponent; @@ -106,6 +110,18 @@ describe('SearchFacetSelectedOptionComponent', () => { let router; const page = observableOf(0); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {}, + getPageParam: 'p.page-id' + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule], @@ -113,6 +129,7 @@ describe('SearchFacetSelectedOptionComponent', () => { providers: [ { provide: SearchService, useValue: new SearchServiceStub(searchLink) }, { provide: Router, useValue: new RouterStub() }, + { provide: PaginationService, useValue: paginationService }, { provide: SearchConfigurationService, useValue: { searchOptions: observableOf({}) @@ -156,7 +173,7 @@ describe('SearchFacetSelectedOptionComponent', () => { (comp as any).updateRemoveParams(selectedValues); expect(comp.removeQueryParams).toEqual({ [mockFilterConfig.paramName]: [value1], - page: 1 + ['p.page-id']: 1 }); }); }); @@ -172,7 +189,7 @@ describe('SearchFacetSelectedOptionComponent', () => { (comp as any).updateRemoveParams(selectedAuthorityValues); expect(comp.removeQueryParams).toEqual({ [mockAuthorityFilterConfig.paramName]: [`${value1},${operator}`], - page: 1 + ['p.page-id']: 1 }); }); }); diff --git a/src/app/shared/search/search-labels/search-label/search-label.component.spec.ts b/src/app/shared/search/search-labels/search-label/search-label.component.spec.ts index 00868a86a2..fe9959aa3a 100644 --- a/src/app/shared/search/search-labels/search-label/search-label.component.spec.ts +++ b/src/app/shared/search/search-labels/search-label/search-label.component.spec.ts @@ -11,6 +11,11 @@ import { SEARCH_CONFIG_SERVICE } from '../../../../+my-dspace-page/my-dspace-pag import { SearchServiceStub } from '../../../testing/search-service.stub'; import { SearchConfigurationServiceStub } from '../../../testing/search-configuration-service.stub'; import { SearchService } from '../../../../core/shared/search/search.service'; +import { PaginationComponentOptions } from '../../../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../../core/data/request.models'; +import { PaginationService } from '../../../../core/pagination/pagination.service'; +import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; describe('SearchLabelComponent', () => { let comp: SearchLabelComponent; @@ -33,6 +38,18 @@ describe('SearchLabelComponent', () => { filter2 ]; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + updateRouteWithUrl: {}, + getPageParam: 'p.test-id' + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule], @@ -40,6 +57,8 @@ describe('SearchLabelComponent', () => { providers: [ { provide: SearchService, useValue: new SearchServiceStub(searchLink) }, { provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }, + { provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() }, + { provide: PaginationService, useValue: paginationService }, { provide: Router, useValue: {} } // { provide: SearchConfigurationService, useValue: {getCurrentFrontendFilters : () => observableOf({})} } ], diff --git a/src/app/shared/search/search-settings/search-settings.component.spec.ts b/src/app/shared/search/search-settings/search-settings.component.spec.ts index cd4a872815..5ae1f7eaf2 100644 --- a/src/app/shared/search/search-settings/search-settings.component.spec.ts +++ b/src/app/shared/search/search-settings/search-settings.component.spec.ts @@ -16,6 +16,7 @@ import { take } from 'rxjs/operators'; import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component'; import { SidebarService } from '../../sidebar/sidebar.service'; import { SidebarServiceStub } from '../../testing/sidebar-service.stub'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('SearchSettingsComponent', () => { @@ -32,6 +33,8 @@ describe('SearchSettingsComponent', () => { let scopeParam; let paginatedSearchOptions; + let paginationService; + let activatedRouteStub; beforeEach(waitForAsync(() => { @@ -62,6 +65,12 @@ describe('SearchSettingsComponent', () => { }), }; + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + resetPage: {}, + }); + TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective], @@ -77,6 +86,10 @@ describe('SearchSettingsComponent', () => { provide: SearchFilterService, useValue: {}, }, + { + provide: PaginationService, + useValue: paginationService, + }, { provide: SEARCH_CONFIG_SERVICE, useValue: { diff --git a/src/app/shared/starts-with/date/starts-with-date.component.spec.ts b/src/app/shared/starts-with/date/starts-with-date.component.spec.ts index 33edcfa5fd..4b4556f511 100644 --- a/src/app/shared/starts-with/date/starts-with-date.component.spec.ts +++ b/src/app/shared/starts-with/date/starts-with-date.component.spec.ts @@ -11,12 +11,17 @@ import { StartsWithDateComponent } from './starts-with-date.component'; import { ActivatedRouteStub } from '../../testing/active-router.stub'; import { EnumKeysPipe } from '../../utils/enum-keys-pipe'; import { RouterStub } from '../../testing/router.stub'; +import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('StartsWithDateComponent', () => { let comp: StartsWithDateComponent; let fixture: ComponentFixture; let route: ActivatedRoute; let router: Router; + let paginationService; const options = [2019, 2018, 2017, 2016, 2015]; @@ -25,13 +30,25 @@ describe('StartsWithDateComponent', () => { queryParams: observableOf({}) }); + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + + paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], declarations: [StartsWithDateComponent, EnumKeysPipe], providers: [ { provide: 'startsWithOptions', useValue: options }, + { provide: 'paginationId', useValue: 'page-id' }, { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: PaginationService, useValue: paginationService }, { provide: Router, useValue: new RouterStub() } ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/shared/starts-with/text/starts-with-text.component.spec.ts b/src/app/shared/starts-with/text/starts-with-text.component.spec.ts index 780c221294..1295f0a33a 100644 --- a/src/app/shared/starts-with/text/starts-with-text.component.spec.ts +++ b/src/app/shared/starts-with/text/starts-with-text.component.spec.ts @@ -8,6 +8,11 @@ import { EnumKeysPipe } from '../../utils/enum-keys-pipe'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; import { StartsWithTextComponent } from './starts-with-text.component'; +import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; +import { FindListOptions } from '../../../core/data/request.models'; +import { of as observableOf } from 'rxjs'; +import { PaginationService } from '../../../core/pagination/pagination.service'; describe('StartsWithTextComponent', () => { let comp: StartsWithTextComponent; @@ -17,12 +22,24 @@ describe('StartsWithTextComponent', () => { const options = ['0-9', 'A', 'B', 'C']; + const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }); + const sort = new SortOptions('score', SortDirection.DESC); + const findlistOptions = Object.assign(new FindListOptions(), { currentPage: 1, elementsPerPage: 20 }); + const paginationService = jasmine.createSpyObj('PaginationService', { + getCurrentPagination: observableOf(pagination), + getCurrentSort: observableOf(sort), + getFindListOptions: observableOf(findlistOptions), + resetPage: {}, + }); + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule], declarations: [StartsWithTextComponent, EnumKeysPipe], providers: [ - { provide: 'startsWithOptions', useValue: options } + { provide: 'startsWithOptions', useValue: options }, + { provide: 'paginationId', useValue: 'page-id' }, + { provide: PaginationService, useValue: paginationService } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/shared/testing/search-configuration-service.stub.ts b/src/app/shared/testing/search-configuration-service.stub.ts index 4c9402afb1..4b8f1d6f12 100644 --- a/src/app/shared/testing/search-configuration-service.stub.ts +++ b/src/app/shared/testing/search-configuration-service.stub.ts @@ -2,6 +2,8 @@ import { BehaviorSubject, of as observableOf } from 'rxjs'; export class SearchConfigurationServiceStub { + public paginationID = 'test-id'; + private searchOptions: BehaviorSubject = new BehaviorSubject({}); private paginatedSearchOptions: BehaviorSubject = new BehaviorSubject({}); diff --git a/src/app/submission/import-external/submission-import-external.component.spec.ts b/src/app/submission/import-external/submission-import-external.component.spec.ts index 3a69a3727e..c0b85b696b 100644 --- a/src/app/submission/import-external/submission-import-external.component.spec.ts +++ b/src/app/submission/import-external/submission-import-external.component.spec.ts @@ -115,15 +115,22 @@ describe('SubmissionImportExternalComponent test suite', () => { spyOn(compAsAny.routeService, 'getQueryParameterValue').and.returnValues(observableOf('source'), observableOf('dummy')); fixture.detectChanges(); - expect(compAsAny.retrieveExternalSources).toHaveBeenCalledWith('source', 'dummy'); + expect(compAsAny.retrieveExternalSources).toHaveBeenCalled(); }); it('Should call \'getExternalSourceEntries\' properly', () => { - comp.routeData = { sourceId: '', query: '' }; - scheduler.schedule(() => compAsAny.retrieveExternalSources('orcidV2', 'test')); - scheduler.flush(); + spyOn(routeServiceStub, 'getQueryParameterValue').and.callFake((param) => { + if (param === 'source') { + return observableOf('orcidV2'); + } else if (param === 'query') { + return observableOf('test'); + } + return observableOf({}); + }); + + fixture.detectChanges(); + - expect(comp.routeData).toEqual({ sourceId: 'orcidV2', query: 'test' }); expect(comp.isLoading$.value).toBe(false); expect(compAsAny.externalService.getExternalSourceEntries).toHaveBeenCalled(); }); diff --git a/src/app/submission/import-external/submission-import-external.component.ts b/src/app/submission/import-external/submission-import-external.component.ts index d8801880dc..2c407a1edb 100644 --- a/src/app/submission/import-external/submission-import-external.component.ts +++ b/src/app/submission/import-external/submission-import-external.component.ts @@ -20,7 +20,6 @@ import { fadeIn } from '../../shared/animations/fade'; import { PageInfo } from '../../core/shared/page-info.model'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { getFinishedRemoteData } from '../../core/shared/operators'; -import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model'; /** * This component allows to submit a new workspaceitem importing the data from an external source. @@ -46,7 +45,7 @@ export class SubmissionImportExternalComponent implements OnInit, OnDestroy { */ public isLoading$: BehaviorSubject = new BehaviorSubject(false); - public reload$: BehaviorSubject<{query: string, source: string}>; + public reload$: BehaviorSubject<{query: string, source: string}> = new BehaviorSubject<{query: string; source: string}>({query: '', source: ''}); /** * Configuration to use for the import buttons */ @@ -122,9 +121,10 @@ export class SubmissionImportExternalComponent implements OnInit, OnDestroy { ]).pipe( take(1) ).subscribe(([source, query]: [string, string]) => { - this.reload$ = new BehaviorSubject<{query: string; source: string}>({query: query, source: source}); - this.retrieveExternalSources(source, query); + this.reload$.next({query: query, source: source}); + this.retrieveExternalSources(); })); + this.reload$.subscribe((v) => console.log('this.reload$', v)); } /** @@ -167,8 +167,9 @@ export class SubmissionImportExternalComponent implements OnInit, OnDestroy { * @param source The source tupe * @param query The query string to search */ - private retrieveExternalSources(sourcesss: string, querysss: string): void { + private retrieveExternalSources(): void { this.reload$.subscribe((sourceQueryObject: {source: string, query: string}) => { + console.log('ping?', sourceQueryObject); const source = sourceQueryObject.source; const query = sourceQueryObject.query; if (isNotEmpty(source) && isNotEmpty(query)) { @@ -177,6 +178,7 @@ export class SubmissionImportExternalComponent implements OnInit, OnDestroy { this.isLoading$.next(true); this.subs.push( this.searchConfigService.paginatedSearchOptions.pipe( + tap((v) => console.log('searchpag?', v)), filter((searchOptions) => searchOptions.query === query), mergeMap((searchOptions) => this.externalService.getExternalSourceEntries(this.routeData.sourceId, searchOptions).pipe( getFinishedRemoteData(),