mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
44239: test fixes
This commit is contained in:
@@ -223,43 +223,48 @@ describe('Pagination component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render and respond to pageSize change', () => {
|
it('should render and respond to pageSize change', () => {
|
||||||
|
const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p;
|
||||||
|
|
||||||
testComp.collectionSize = 30;
|
testComp.collectionSize = 30;
|
||||||
testFixture.detectChanges();
|
testFixture.detectChanges();
|
||||||
expectPages(testFixture, ['-« Previous', '+1', '2', '3', '» Next']);
|
expectPages(testFixture, ['-« Previous', '+1', '2', '3', '» Next']);
|
||||||
|
|
||||||
changePageSize(testFixture, '5');
|
paginationComponent.setPageSize(5);
|
||||||
|
testFixture.detectChanges();
|
||||||
expectPages(testFixture, ['-« Previous', '+1', '2', '3', '4', '5', '6', '» Next']);
|
expectPages(testFixture, ['-« Previous', '+1', '2', '3', '4', '5', '6', '» Next']);
|
||||||
|
|
||||||
changePageSize(testFixture, '10');
|
paginationComponent.setPageSize(10);
|
||||||
|
testFixture.detectChanges();
|
||||||
expectPages(testFixture, ['-« Previous', '+1', '2', '3', '» Next']);
|
expectPages(testFixture, ['-« Previous', '+1', '2', '3', '» Next']);
|
||||||
|
|
||||||
changePageSize(testFixture, '20');
|
paginationComponent.setPageSize(20);
|
||||||
|
testFixture.detectChanges();
|
||||||
expectPages(testFixture, ['-« Previous', '+1', '2', '» Next']);
|
expectPages(testFixture, ['-« Previous', '+1', '2', '» Next']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit pageChange event with correct value', fakeAsync(() => {
|
it('should emit pageChange event with correct value', fakeAsync(() => {
|
||||||
|
const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p;
|
||||||
|
|
||||||
spyOn(testComp, 'pageChanged');
|
spyOn(testComp, 'pageChanged');
|
||||||
|
|
||||||
changePage(testFixture, 3);
|
paginationComponent.setPage(3);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(testComp.pageChanged).toHaveBeenCalledWith(3);
|
expect(testComp.pageChanged).toHaveBeenCalledWith(3);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should emit pageSizeChange event with correct value', fakeAsync(() => {
|
it('should emit pageSizeChange event with correct value', fakeAsync(() => {
|
||||||
|
const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p;
|
||||||
|
|
||||||
spyOn(testComp, 'pageSizeChanged');
|
spyOn(testComp, 'pageSizeChanged');
|
||||||
|
|
||||||
changePageSize(testFixture, '5');
|
paginationComponent.setPageSize(5);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(testComp.pageSizeChanged).toHaveBeenCalledWith(5);
|
expect(testComp.pageSizeChanged).toHaveBeenCalledWith(5);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should set correct route parameters', fakeAsync(() => {
|
it('should set correct page route parameters', fakeAsync(() => {
|
||||||
const paginationComponent: PaginationComponent = testFixture.debugElement.query(By.css('ds-pagination')).references.p;
|
|
||||||
routerStub = testFixture.debugElement.injector.get(Router) as any;
|
routerStub = testFixture.debugElement.injector.get(Router) as any;
|
||||||
|
|
||||||
testComp.collectionSize = 60;
|
testComp.collectionSize = 60;
|
||||||
@@ -267,11 +272,29 @@ describe('Pagination component', () => {
|
|||||||
changePage(testFixture, 3);
|
changePage(testFixture, 3);
|
||||||
tick();
|
tick();
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 10, sortDirection: 0, sortField: 'name' } });
|
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 10, sortDirection: 0, sortField: 'name' } });
|
||||||
expect(paginationComponent.currentPage).toEqual(3);
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should set correct pageSize route parameters', fakeAsync(() => {
|
||||||
|
routerStub = testFixture.debugElement.injector.get(Router) as any;
|
||||||
|
|
||||||
|
testComp.collectionSize = 60;
|
||||||
|
|
||||||
changePageSize(testFixture, '20');
|
changePageSize(testFixture, '20');
|
||||||
tick();
|
tick();
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 20, sortDirection: 0, sortField: 'name' } });
|
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 1, pageSize: 20, sortDirection: 0, sortField: 'name' } });
|
||||||
|
}));
|
||||||
|
|
||||||
|
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);
|
expect(paginationComponent.pageSize).toEqual(20);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ import { HostWindowService } from '../host-window.service';
|
|||||||
import { HostWindowState } from '../host-window.reducer';
|
import { HostWindowState } from '../host-window.reducer';
|
||||||
import { PaginationComponentOptions } from './pagination-component-options.model';
|
import { PaginationComponentOptions } from './pagination-component-options.model';
|
||||||
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||||
import { hasNoValue, hasValue, isEmpty, isNotEmpty } from '../empty.util';
|
import { hasValue, isNotEmpty } from '../empty.util';
|
||||||
import { PageInfo } from '../../core/shared/page-info.model';
|
import { PageInfo } from '../../core/shared/page-info.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,11 +151,6 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
*/
|
*/
|
||||||
public sortField = 'id';
|
public sortField = 'id';
|
||||||
|
|
||||||
/**
|
|
||||||
* Local variable, which can be used in the template to access the paginate controls ngbDropdown methods and properties
|
|
||||||
*/
|
|
||||||
public paginationControls;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array to track all subscriptions and unsubscribe them onDestroy
|
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
@@ -214,6 +209,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
this.sortDirection = this.sortOptions.direction;
|
this.sortDirection = this.sortOptions.direction;
|
||||||
this.sortField = this.sortOptions.field;
|
this.sortField = this.sortOptions.field;
|
||||||
this.currentQueryParams = {
|
this.currentQueryParams = {
|
||||||
|
pageId: this.id,
|
||||||
page: this.currentPage,
|
page: this.currentPage,
|
||||||
pageSize: this.pageSize,
|
pageSize: this.pageSize,
|
||||||
sortDirection: this.sortDirection,
|
sortDirection: this.sortDirection,
|
||||||
@@ -326,6 +322,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
*/
|
*/
|
||||||
private emitPaginationChange() {
|
private emitPaginationChange() {
|
||||||
this.paginationChange.emit({
|
this.paginationChange.emit({
|
||||||
|
pageId: this.id,
|
||||||
page: this.currentPage,
|
page: this.currentPage,
|
||||||
pageSize: this.pageSize,
|
pageSize: this.pageSize,
|
||||||
sortDirection: this.sortDirection,
|
sortDirection: this.sortDirection,
|
||||||
|
Reference in New Issue
Block a user