64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
import './paging.js';
|
|
|
|
describe('Component vnPaging', () => {
|
|
let $scope;
|
|
let controller;
|
|
|
|
beforeEach(ngModule('vnCore'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
|
$scope = $rootScope.$new();
|
|
controller = $componentController('vnPaging', {$scope});
|
|
}));
|
|
|
|
describe('$onChanges()', () => {
|
|
it(`should define numberPage and currentPage based on index.filter properties`, () => {
|
|
controller.index = {filter: {size: 'something', page: 'something else'}};
|
|
controller.$onChanges({index: 'simpleChange', currentValue: 'current value', previousValue: 'previous value'});
|
|
|
|
expect(controller.numPerPage).toBe(controller.index.filter.size);
|
|
expect(controller.currentPage).toEqual(controller.index.filter.page);
|
|
});
|
|
|
|
it(`should define numItems based on changes.total.currentValue`, () => {
|
|
controller.index = {filter: {size: 'something', page: 'something else'}};
|
|
controller.$onChanges({total: {currentValue: 'current value'}});
|
|
|
|
expect(controller.numItems).toEqual('current value');
|
|
});
|
|
});
|
|
|
|
describe('onModelUpdated()', () => {
|
|
it(`should define controllers numItems as the result of page times size plus one`, () => {
|
|
controller.numPerPage = 2;
|
|
controller.index = {
|
|
filter: {size: 10, page: 10},
|
|
model: ['one mother..', 'another model..', 'last model..']
|
|
};
|
|
controller.onModelUpdated();
|
|
|
|
expect(controller.numItems).toBe(101);
|
|
});
|
|
});
|
|
|
|
describe('onPageChange()', () => {
|
|
it(`should call accept() since pageChange property is undefined`, () => {
|
|
controller.index = {accept: () => {}, filter: {page: 0}};
|
|
spyOn(controller.index, 'accept');
|
|
controller.onPageChange(100);
|
|
|
|
expect(controller.index.accept).toHaveBeenCalledWith();
|
|
});
|
|
|
|
it(`should call pageChange() since pageChange property isn't undefined`, () => {
|
|
controller.index = {accept: () => {}, filter: {page: 0}};
|
|
controller.pageChange = true;
|
|
spyOn(controller, 'pageChange');
|
|
controller.onPageChange(100);
|
|
|
|
expect(controller.pageChange).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
});
|
|
|