2017-10-04 11:27:39 +00:00
|
|
|
import './paging.js';
|
|
|
|
|
|
|
|
describe('Component vnPaging', () => {
|
|
|
|
let $scope;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
2017-10-04 11:27:39 +00:00
|
|
|
$scope = $rootScope.$new();
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnPaging', {$scope});
|
2017-10-04 11:27:39 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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`, () => {
|
2017-10-17 12:24:40 +00:00
|
|
|
controller.index = {accept: () => {}, filter: {page: 0}};
|
2017-10-04 11:27:39 +00:00
|
|
|
spyOn(controller.index, 'accept');
|
|
|
|
controller.onPageChange(100);
|
|
|
|
|
|
|
|
expect(controller.index.accept).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should call pageChange() since pageChange property isn't undefined`, () => {
|
2017-10-17 12:24:40 +00:00
|
|
|
controller.index = {accept: () => {}, filter: {page: 0}};
|
2017-10-04 11:27:39 +00:00
|
|
|
controller.pageChange = true;
|
|
|
|
spyOn(controller, 'pageChange');
|
|
|
|
controller.onPageChange(100);
|
|
|
|
|
|
|
|
expect(controller.pageChange).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|