From b18cfcbd25c9ab332fef4cc5205d56a3c9f99665 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 23 Dec 2019 17:23:17 +0100 Subject: [PATCH] fixed issue with type of object emitted onPaginationChange event --- ...page-sub-collection-list.component.spec.ts | 35 ++++++++++++------ ...nity-page-sub-collection-list.component.ts | 8 ++-- ...-page-sub-community-list.component.spec.ts | 37 +++++++++++++------ ...unity-page-sub-community-list.component.ts | 8 ++-- .../top-level-community-list.component.ts | 23 +++++++----- 5 files changed, 71 insertions(+), 40 deletions(-) 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 2150676dd6..09332dda16 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 @@ -5,6 +5,8 @@ import { By } from '@angular/platform-browser'; import { RouterTestingModule } from '@angular/router/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; + import { CommunityPageSubCollectionListComponent } from './community-page-sub-collection-list.component'; import { Community } from '../../core/shared/community.model'; import { SharedModule } from '../../shared/shared.module'; @@ -15,8 +17,9 @@ import { PaginatedList } from '../../core/data/paginated-list'; 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'; -describe('CommunityPageSubCollectionListComponent Component', () => { +describe('CommunityPageSubCollectionList Component', () => { let comp: CommunityPageSubCollectionListComponent; let fixture: ComponentFixture; let collectionDataServiceStub: any; @@ -109,13 +112,18 @@ describe('CommunityPageSubCollectionListComponent Component', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), SharedModule, + imports: [ + TranslateModule.forRoot(), + SharedModule, RouterTestingModule.withRoutes([]), - NoopAnimationsModule], + NgbModule.forRoot(), + NoopAnimationsModule + ], declarations: [CommunityPageSubCollectionListComponent], providers: [ { provide: CollectionDataService, useValue: collectionDataServiceStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: SelectableListService, useValue: {} }, ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); @@ -140,7 +148,7 @@ describe('CommunityPageSubCollectionListComponent Component', () => { expect(collList[4].nativeElement.textContent).toContain('Collection 5'); }); - it('should not display the header when collection list is empty', () => { + it('should not display the header when list of collections is empty', () => { subCollList = []; fixture.detectChanges(); @@ -148,16 +156,21 @@ describe('CommunityPageSubCollectionListComponent Component', () => { expect(subComHead.length).toEqual(0); }); - it('should update list of collection on pagination change', () => { + it('should update list of collections on pagination change', () => { subCollList = collections; fixture.detectChanges(); - const pagination = Object.create({}); - pagination.pageId = comp.pageId; - pagination.page = 2; - pagination.pageSize = 5; - pagination.sortField = 'dc.title'; - pagination.sortDirection = 'ASC'; + const pagination = Object.create({ + pagination:{ + id: comp.pageId, + currentPage: 2, + pageSize: 5 + }, + sort: { + field: 'dc.title', + direction: 'ASC' + } + }); comp.onPaginationChange(pagination); fixture.detectChanges(); diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts index 18f48c3482..64c274444e 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts @@ -57,10 +57,10 @@ export class CommunityPageSubCollectionListComponent implements OnInit { * @param event The new pagination data */ onPaginationChange(event) { - this.config.currentPage = event.page; - this.config.pageSize = event.pageSize; - this.sortConfig.field = event.sortField; - this.sortConfig.direction = event.sortDirection; + this.config.currentPage = event.pagination.currentPage; + this.config.pageSize = event.pagination.pageSize; + this.sortConfig.field = event.sort.field; + this.sortConfig.direction = event.sort.direction; this.updatePage(); } 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 ff3eb4d074..41502e7bd4 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 @@ -5,6 +5,8 @@ import { RouterTestingModule } from '@angular/router/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { By } from '@angular/platform-browser'; +import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; + import { CommunityPageSubCommunityListComponent } from './community-page-sub-community-list.component'; import { Community } from '../../core/shared/community.model'; import { PaginatedList } from '../../core/data/paginated-list'; @@ -15,8 +17,9 @@ import { FindListOptions } from '../../core/data/request.models'; 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'; -describe('SubCommunityList Component', () => { +describe('CommunityPageSubCommunityListComponent Component', () => { let comp: CommunityPageSubCommunityListComponent; let fixture: ComponentFixture; let communityDataServiceStub: any; @@ -110,13 +113,18 @@ describe('SubCommunityList Component', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), SharedModule, + imports: [ + TranslateModule.forRoot(), + SharedModule, RouterTestingModule.withRoutes([]), - NoopAnimationsModule], + NgbModule.forRoot(), + NoopAnimationsModule + ], declarations: [CommunityPageSubCommunityListComponent], providers: [ { provide: CommunityDataService, useValue: communityDataServiceStub }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, + { provide: SelectableListService, useValue: {} }, ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); @@ -129,7 +137,7 @@ describe('SubCommunityList Component', () => { }); - it('should display a list of subCommunities', () => { + it('should display a list of sub-communities', () => { subCommList = subcommunities; fixture.detectChanges(); @@ -142,7 +150,7 @@ describe('SubCommunityList Component', () => { expect(subComList[4].nativeElement.textContent).toContain('SubCommunity 5'); }); - it('should not display the header when subCommunities are empty', () => { + it('should not display the header when list of sub-communities is empty', () => { subCommList = []; fixture.detectChanges(); @@ -150,16 +158,21 @@ describe('SubCommunityList Component', () => { expect(subComHead.length).toEqual(0); }); - it('should update list of collection on pagination change', () => { + it('should update list of sub-communities on pagination change', () => { subCommList = subcommunities; fixture.detectChanges(); - const pagination = Object.create({}); - pagination.pageId = comp.pageId; - pagination.page = 2; - pagination.pageSize = 5; - pagination.sortField = 'dc.title'; - pagination.sortDirection = 'ASC'; + const pagination = Object.create({ + pagination:{ + id: comp.pageId, + currentPage: 2, + pageSize: 5 + }, + sort: { + field: 'dc.title', + direction: 'ASC' + } + }); comp.onPaginationChange(pagination); fixture.detectChanges(); diff --git a/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.ts b/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.ts index 34ef05c2c4..1bd664021e 100644 --- a/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.ts +++ b/src/app/+community-page/sub-community-list/community-page-sub-community-list.component.ts @@ -60,10 +60,10 @@ export class CommunityPageSubCommunityListComponent implements OnInit { * @param event The new pagination data */ onPaginationChange(event) { - this.config.currentPage = event.page; - this.config.pageSize = event.pageSize; - this.sortConfig.field = event.sortField; - this.sortConfig.direction = event.sortDirection; + this.config.currentPage = event.pagination.currentPage; + this.config.pageSize = event.pagination.pageSize; + this.sortConfig.field = event.sort.field; + this.sortConfig.direction = event.sort.direction; this.updatePage(); } diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts index 1115d785a3..02c3cb54a0 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts @@ -1,15 +1,15 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; -import { BehaviorSubject, Observable } from 'rxjs'; + +import { BehaviorSubject } from 'rxjs'; +import { take } from 'rxjs/operators'; + import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { CommunityDataService } from '../../core/data/community-data.service'; import { PaginatedList } from '../../core/data/paginated-list'; - import { RemoteData } from '../../core/data/remote-data'; import { Community } from '../../core/shared/community.model'; - import { fadeInOut } from '../../shared/animations/fade'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; -import { take } from 'rxjs/operators'; /** * this component renders the Top-Level Community list @@ -33,6 +33,11 @@ export class TopLevelCommunityListComponent implements OnInit { */ config: PaginationComponentOptions; + /** + * The pagination id + */ + pageId = 'top-level-pagination'; + /** * The sorting configuration */ @@ -40,7 +45,7 @@ export class TopLevelCommunityListComponent implements OnInit { constructor(private cds: CommunityDataService) { this.config = new PaginationComponentOptions(); - this.config.id = 'top-level-pagination'; + this.config.id = this.pageId; this.config.pageSize = 5; this.config.currentPage = 1; this.sortConfig = new SortOptions('dc.title', SortDirection.ASC); @@ -55,10 +60,10 @@ export class TopLevelCommunityListComponent implements OnInit { * @param event The new pagination data */ onPaginationChange(event) { - this.config.currentPage = event.page; - this.config.pageSize = event.pageSize; - this.sortConfig.field = event.sortField; - this.sortConfig.direction = event.sortDirection; + this.config.currentPage = event.pagination.currentPage; + this.config.pageSize = event.pagination.pageSize; + this.sortConfig.field = event.sort.field; + this.sortConfig.direction = event.sort.direction; this.updatePage(); }