Matteo Scandolo | d72d490 | 2016-04-15 13:00:01 -0700 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
| 3 | |
| 4 | describe('The xos.helper module', function(){ |
| 5 | describe('The xos-pagination component', () => { |
| 6 | |
| 7 | let scope, element, isolatedScope; |
| 8 | let cb = jasmine.createSpy('callback') |
| 9 | |
| 10 | beforeEach(module('xos.helpers')); |
| 11 | |
| 12 | beforeEach(inject(function ($compile, $rootScope) { |
| 13 | scope = $rootScope.$new(); |
| 14 | |
| 15 | scope.pageSize = 2; |
| 16 | |
| 17 | scope.totalElements = 5; |
| 18 | |
| 19 | scope.change = cb; |
| 20 | |
| 21 | element = angular.element('<xos-pagination page-size="pageSize" total-elements="totalElements" change="change"></xos-table>'); |
| 22 | $compile(element)(scope); |
| 23 | scope.$digest(); |
| 24 | isolatedScope = element.isolateScope().vm; |
| 25 | })); |
| 26 | |
| 27 | it('should contain 3 pages', function() { |
| 28 | var li = element[0].getElementsByTagName('li'); |
| 29 | expect(li.length).toEqual(5); |
| 30 | }); |
| 31 | |
| 32 | it('should call the change function', () => { |
| 33 | var li = element[0].getElementsByTagName('li')[3]; |
| 34 | let link = li.getElementsByTagName('a')[0]; |
| 35 | link.click(); |
| 36 | expect(cb).toHaveBeenCalledWith(2); |
| 37 | }); |
| 38 | |
| 39 | describe('when elements number is less than page size', () => { |
| 40 | beforeEach(() => { |
| 41 | isolatedScope.pageSize = 10; |
| 42 | isolatedScope.totalElements = 9; |
| 43 | scope.$digest(); |
| 44 | }); |
| 45 | |
| 46 | it('should not be rendered', () => { |
| 47 | var pagination = element[0].getElementsByClassName('pagination'); |
| 48 | expect(pagination.length).toEqual(0); |
| 49 | }); |
| 50 | }); |
| 51 | }); |
| 52 | }); |
| 53 | })(); |