Matteo Scandolo | 686547a | 2017-08-08 13:05:25 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | a5d03d5 | 2016-07-21 11:35:46 -0700 | [diff] [blame] | 19 | (function () { |
| 20 | 'use strict'; |
| 21 | |
| 22 | describe('The xos.helper module', function(){ |
| 23 | describe('The xos-pagination component', () => { |
| 24 | |
| 25 | let scope, element, isolatedScope; |
| 26 | let cb = jasmine.createSpy('callback') |
| 27 | |
| 28 | beforeEach(module('xos.helpers')); |
| 29 | |
| 30 | beforeEach(inject(function ($compile, $rootScope) { |
| 31 | scope = $rootScope.$new(); |
| 32 | |
| 33 | scope.pageSize = 2; |
| 34 | |
| 35 | scope.totalElements = 5; |
| 36 | |
| 37 | scope.change = cb; |
| 38 | |
| 39 | element = angular.element('<xos-pagination page-size="pageSize" total-elements="totalElements" change="change"></xos-table>'); |
| 40 | $compile(element)(scope); |
| 41 | scope.$digest(); |
| 42 | isolatedScope = element.isolateScope().vm; |
| 43 | })); |
| 44 | |
| 45 | it('should contain 3 pages', function() { |
| 46 | const li = element[0].getElementsByTagName('li'); |
| 47 | expect(li.length).toEqual(5); |
| 48 | }); |
| 49 | |
| 50 | it('should call the change function', () => { |
| 51 | const li = element[0].getElementsByTagName('li')[3]; |
| 52 | let link = li.getElementsByTagName('a')[0]; |
| 53 | link.click(); |
| 54 | expect(cb).toHaveBeenCalledWith(2); |
| 55 | }); |
| 56 | |
| 57 | describe('when elements number is less than page size', () => { |
| 58 | beforeEach(() => { |
| 59 | isolatedScope.pageSize = 10; |
| 60 | isolatedScope.totalElements = 9; |
| 61 | scope.$digest(); |
| 62 | }); |
| 63 | |
| 64 | it('should not be rendered', () => { |
| 65 | const pagination = element[0].getElementsByClassName('pagination'); |
| 66 | expect(pagination.length).toEqual(0); |
| 67 | }); |
| 68 | }); |
| 69 | }); |
| 70 | }); |
| 71 | })(); |