mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
fixed issue with type of object emitted onPaginationChange event
This commit is contained in:
@@ -5,6 +5,8 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
|
||||||
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
import { CommunityPageSubCollectionListComponent } from './community-page-sub-collection-list.component';
|
import { CommunityPageSubCollectionListComponent } from './community-page-sub-collection-list.component';
|
||||||
import { Community } from '../../core/shared/community.model';
|
import { Community } from '../../core/shared/community.model';
|
||||||
import { SharedModule } from '../../shared/shared.module';
|
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 { PageInfo } from '../../core/shared/page-info.model';
|
||||||
import { HostWindowService } from '../../shared/host-window.service';
|
import { HostWindowService } from '../../shared/host-window.service';
|
||||||
import { HostWindowServiceStub } from '../../shared/testing/host-window-service-stub';
|
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 comp: CommunityPageSubCollectionListComponent;
|
||||||
let fixture: ComponentFixture<CommunityPageSubCollectionListComponent>;
|
let fixture: ComponentFixture<CommunityPageSubCollectionListComponent>;
|
||||||
let collectionDataServiceStub: any;
|
let collectionDataServiceStub: any;
|
||||||
@@ -109,13 +112,18 @@ describe('CommunityPageSubCollectionListComponent Component', () => {
|
|||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), SharedModule,
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
SharedModule,
|
||||||
RouterTestingModule.withRoutes([]),
|
RouterTestingModule.withRoutes([]),
|
||||||
NoopAnimationsModule],
|
NgbModule.forRoot(),
|
||||||
|
NoopAnimationsModule
|
||||||
|
],
|
||||||
declarations: [CommunityPageSubCollectionListComponent],
|
declarations: [CommunityPageSubCollectionListComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: CollectionDataService, useValue: collectionDataServiceStub },
|
{ provide: CollectionDataService, useValue: collectionDataServiceStub },
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
||||||
|
{ provide: SelectableListService, useValue: {} },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -140,7 +148,7 @@ describe('CommunityPageSubCollectionListComponent Component', () => {
|
|||||||
expect(collList[4].nativeElement.textContent).toContain('Collection 5');
|
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 = [];
|
subCollList = [];
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
@@ -148,16 +156,21 @@ describe('CommunityPageSubCollectionListComponent Component', () => {
|
|||||||
expect(subComHead.length).toEqual(0);
|
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;
|
subCollList = collections;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const pagination = Object.create({});
|
const pagination = Object.create({
|
||||||
pagination.pageId = comp.pageId;
|
pagination:{
|
||||||
pagination.page = 2;
|
id: comp.pageId,
|
||||||
pagination.pageSize = 5;
|
currentPage: 2,
|
||||||
pagination.sortField = 'dc.title';
|
pageSize: 5
|
||||||
pagination.sortDirection = 'ASC';
|
},
|
||||||
|
sort: {
|
||||||
|
field: 'dc.title',
|
||||||
|
direction: 'ASC'
|
||||||
|
}
|
||||||
|
});
|
||||||
comp.onPaginationChange(pagination);
|
comp.onPaginationChange(pagination);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
@@ -57,10 +57,10 @@ export class CommunityPageSubCollectionListComponent implements OnInit {
|
|||||||
* @param event The new pagination data
|
* @param event The new pagination data
|
||||||
*/
|
*/
|
||||||
onPaginationChange(event) {
|
onPaginationChange(event) {
|
||||||
this.config.currentPage = event.page;
|
this.config.currentPage = event.pagination.currentPage;
|
||||||
this.config.pageSize = event.pageSize;
|
this.config.pageSize = event.pagination.pageSize;
|
||||||
this.sortConfig.field = event.sortField;
|
this.sortConfig.field = event.sort.field;
|
||||||
this.sortConfig.direction = event.sortDirection;
|
this.sortConfig.direction = event.sort.direction;
|
||||||
this.updatePage();
|
this.updatePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,8 @@ import { RouterTestingModule } from '@angular/router/testing';
|
|||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
import { CommunityPageSubCommunityListComponent } from './community-page-sub-community-list.component';
|
import { CommunityPageSubCommunityListComponent } from './community-page-sub-community-list.component';
|
||||||
import { Community } from '../../core/shared/community.model';
|
import { Community } from '../../core/shared/community.model';
|
||||||
import { PaginatedList } from '../../core/data/paginated-list';
|
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 { HostWindowService } from '../../shared/host-window.service';
|
||||||
import { HostWindowServiceStub } from '../../shared/testing/host-window-service-stub';
|
import { HostWindowServiceStub } from '../../shared/testing/host-window-service-stub';
|
||||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
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 comp: CommunityPageSubCommunityListComponent;
|
||||||
let fixture: ComponentFixture<CommunityPageSubCommunityListComponent>;
|
let fixture: ComponentFixture<CommunityPageSubCommunityListComponent>;
|
||||||
let communityDataServiceStub: any;
|
let communityDataServiceStub: any;
|
||||||
@@ -110,13 +113,18 @@ describe('SubCommunityList Component', () => {
|
|||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), SharedModule,
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
SharedModule,
|
||||||
RouterTestingModule.withRoutes([]),
|
RouterTestingModule.withRoutes([]),
|
||||||
NoopAnimationsModule],
|
NgbModule.forRoot(),
|
||||||
|
NoopAnimationsModule
|
||||||
|
],
|
||||||
declarations: [CommunityPageSubCommunityListComponent],
|
declarations: [CommunityPageSubCommunityListComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: CommunityDataService, useValue: communityDataServiceStub },
|
{ provide: CommunityDataService, useValue: communityDataServiceStub },
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
||||||
|
{ provide: SelectableListService, useValue: {} },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).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;
|
subCommList = subcommunities;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
@@ -142,7 +150,7 @@ describe('SubCommunityList Component', () => {
|
|||||||
expect(subComList[4].nativeElement.textContent).toContain('SubCommunity 5');
|
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 = [];
|
subCommList = [];
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
@@ -150,16 +158,21 @@ describe('SubCommunityList Component', () => {
|
|||||||
expect(subComHead.length).toEqual(0);
|
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;
|
subCommList = subcommunities;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const pagination = Object.create({});
|
const pagination = Object.create({
|
||||||
pagination.pageId = comp.pageId;
|
pagination:{
|
||||||
pagination.page = 2;
|
id: comp.pageId,
|
||||||
pagination.pageSize = 5;
|
currentPage: 2,
|
||||||
pagination.sortField = 'dc.title';
|
pageSize: 5
|
||||||
pagination.sortDirection = 'ASC';
|
},
|
||||||
|
sort: {
|
||||||
|
field: 'dc.title',
|
||||||
|
direction: 'ASC'
|
||||||
|
}
|
||||||
|
});
|
||||||
comp.onPaginationChange(pagination);
|
comp.onPaginationChange(pagination);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
@@ -60,10 +60,10 @@ export class CommunityPageSubCommunityListComponent implements OnInit {
|
|||||||
* @param event The new pagination data
|
* @param event The new pagination data
|
||||||
*/
|
*/
|
||||||
onPaginationChange(event) {
|
onPaginationChange(event) {
|
||||||
this.config.currentPage = event.page;
|
this.config.currentPage = event.pagination.currentPage;
|
||||||
this.config.pageSize = event.pageSize;
|
this.config.pageSize = event.pagination.pageSize;
|
||||||
this.sortConfig.field = event.sortField;
|
this.sortConfig.field = event.sort.field;
|
||||||
this.sortConfig.direction = event.sortDirection;
|
this.sortConfig.direction = event.sort.direction;
|
||||||
this.updatePage();
|
this.updatePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
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 { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||||
import { PaginatedList } from '../../core/data/paginated-list';
|
import { PaginatedList } from '../../core/data/paginated-list';
|
||||||
|
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
import { Community } from '../../core/shared/community.model';
|
import { Community } from '../../core/shared/community.model';
|
||||||
|
|
||||||
import { fadeInOut } from '../../shared/animations/fade';
|
import { fadeInOut } from '../../shared/animations/fade';
|
||||||
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
||||||
import { take } from 'rxjs/operators';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this component renders the Top-Level Community list
|
* this component renders the Top-Level Community list
|
||||||
@@ -33,6 +33,11 @@ export class TopLevelCommunityListComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
config: PaginationComponentOptions;
|
config: PaginationComponentOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pagination id
|
||||||
|
*/
|
||||||
|
pageId = 'top-level-pagination';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sorting configuration
|
* The sorting configuration
|
||||||
*/
|
*/
|
||||||
@@ -40,7 +45,7 @@ export class TopLevelCommunityListComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private cds: CommunityDataService) {
|
constructor(private cds: CommunityDataService) {
|
||||||
this.config = new PaginationComponentOptions();
|
this.config = new PaginationComponentOptions();
|
||||||
this.config.id = 'top-level-pagination';
|
this.config.id = this.pageId;
|
||||||
this.config.pageSize = 5;
|
this.config.pageSize = 5;
|
||||||
this.config.currentPage = 1;
|
this.config.currentPage = 1;
|
||||||
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
|
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
|
||||||
@@ -55,10 +60,10 @@ export class TopLevelCommunityListComponent implements OnInit {
|
|||||||
* @param event The new pagination data
|
* @param event The new pagination data
|
||||||
*/
|
*/
|
||||||
onPaginationChange(event) {
|
onPaginationChange(event) {
|
||||||
this.config.currentPage = event.page;
|
this.config.currentPage = event.pagination.currentPage;
|
||||||
this.config.pageSize = event.pageSize;
|
this.config.pageSize = event.pagination.pageSize;
|
||||||
this.sortConfig.field = event.sortField;
|
this.sortConfig.field = event.sort.field;
|
||||||
this.sortConfig.direction = event.sortDirection;
|
this.sortConfig.direction = event.sort.direction;
|
||||||
this.updatePage();
|
this.updatePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user