73 lines
2.9 KiB
JavaScript
73 lines
2.9 KiB
JavaScript
|
import './paging.js';
|
||
|
|
||
|
describe('Component vnPaging', () => {
|
||
|
let $componentController;
|
||
|
let $scope;
|
||
|
let $httpBackend;
|
||
|
|
||
|
beforeEach(() => {
|
||
|
angular.mock.module('client');
|
||
|
});
|
||
|
|
||
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
||
|
$componentController = _$componentController_;
|
||
|
$scope = $rootScope.$new();
|
||
|
$httpBackend = _$httpBackend_;
|
||
|
}));
|
||
|
|
||
|
describe('$onChanges()', () => {
|
||
|
it(`should define numberPage and currentPage based on index.filter properties`, () => {
|
||
|
let controller = $componentController('vnPaging', {$scope, $httpBackend});
|
||
|
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`, () => {
|
||
|
let controller = $componentController('vnPaging', {$scope, $httpBackend});
|
||
|
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`, () => {
|
||
|
let controller = $componentController('vnPaging', {$scope, $httpBackend});
|
||
|
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`, () => {
|
||
|
let myIndex = {accept: () => {}, filter: {page: 0}};
|
||
|
let controller = $componentController('vnPaging', {$scope, $httpBackend}, {index: myIndex});
|
||
|
spyOn(controller.index, 'accept');
|
||
|
controller.onPageChange(100);
|
||
|
|
||
|
expect(controller.index.accept).toHaveBeenCalledWith();
|
||
|
});
|
||
|
|
||
|
it(`should call pageChange() since pageChange property isn't undefined`, () => {
|
||
|
let myIndex = {accept: () => {}, filter: {page: 0}};
|
||
|
let controller = $componentController('vnPaging', {$scope, $httpBackend}, {index: myIndex});
|
||
|
controller.pageChange = true;
|
||
|
spyOn(controller, 'pageChange');
|
||
|
controller.onPageChange(100);
|
||
|
|
||
|
expect(controller.pageChange).toHaveBeenCalledWith();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|