|
| 1 | +/*globals describe, beforeEach, it, expect, module, inject, jQuery, spyOn */ |
| 2 | + |
| 3 | +/** |
| 4 | + * @license angular-bootstrap-datetimepicker |
| 5 | + * Copyright 2013 Knight Rider Consulting, Inc. http://www.knightrider.com |
| 6 | + * License: MIT |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * |
| 11 | + * @author Dale "Ducky" Lotts |
| 12 | + * @since 7/21/13 |
| 13 | + */ |
| 14 | + |
| 15 | +describe('renderOn', function () { |
| 16 | + 'use strict'; |
| 17 | + var $rootScope; |
| 18 | + var $compile; |
| 19 | + beforeEach(module('ui.bootstrap.datetimepicker')); |
| 20 | + beforeEach(inject(function (_$compile_, _$rootScope_) { |
| 21 | + $compile = _$compile_; |
| 22 | + $rootScope = _$rootScope_; |
| 23 | + $rootScope.date = null; |
| 24 | + })); |
| 25 | + |
| 26 | + describe('throws exception', function () { |
| 27 | + it('if value is an empty string', function () { |
| 28 | + function compile() { |
| 29 | + $compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="{ renderOn: \'\' }"></datetimepicker>')($rootScope); |
| 30 | + } |
| 31 | + |
| 32 | + expect(compile).toThrow('renderOn must not be an empty string'); |
| 33 | + }); |
| 34 | + it('if value is numeric', function () { |
| 35 | + function compile() { |
| 36 | + $compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="{ renderOn: 3 }"></datetimepicker>')($rootScope); |
| 37 | + } |
| 38 | + |
| 39 | + expect(compile).toThrow('renderOn must be a string'); |
| 40 | + }); |
| 41 | + }); |
| 42 | + describe('does NOT throw exception', function () { |
| 43 | + it('if value is a string', function () { |
| 44 | + |
| 45 | + $compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="{ renderOn: \'foo\' }"></datetimepicker>')($rootScope); |
| 46 | + }); |
| 47 | + }); |
| 48 | + describe('renderOn event', function () { |
| 49 | + it('causes view to re-render after event is received', function () { |
| 50 | + |
| 51 | + |
| 52 | + var selectable = true; |
| 53 | + |
| 54 | + $rootScope.config = { |
| 55 | + data: { |
| 56 | + startView: 'year', |
| 57 | + renderOn: 'valid-dates-changed' |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + $rootScope.beforeRender = function (dates) { |
| 62 | + dates[2].selectable = selectable; |
| 63 | + }; |
| 64 | + |
| 65 | + spyOn($rootScope, 'beforeRender').and.callThrough(); |
| 66 | + |
| 67 | + var element = $compile('<datetimepicker data-ng-model="date" data-before-render=\'beforeRender($dates)\' data-datetimepicker-config="config.data"></datetimepicker>')($rootScope); |
| 68 | + $rootScope.$digest(); |
| 69 | + |
| 70 | + |
| 71 | + var selectedElement = jQuery(jQuery('.year', element)[2]); |
| 72 | + expect(selectedElement.hasClass('disabled')).toBeFalsy(); |
| 73 | + |
| 74 | + selectable = false; |
| 75 | + |
| 76 | + $rootScope.$broadcast('valid-dates-changed'); |
| 77 | + $rootScope.$digest(); |
| 78 | + |
| 79 | + expect($rootScope.beforeRender.calls.count()).toBe(2); |
| 80 | + |
| 81 | + selectedElement = jQuery(jQuery('.year', element)[2]); |
| 82 | + expect(selectedElement.hasClass('disabled')).toBeTruthy(); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
| 86 | + |
0 commit comments