|
| 1 | +describe('Docs Annotations', function() { |
| 2 | + |
| 3 | + beforeEach(module('docsApp')); |
| 4 | + |
| 5 | + var body; |
| 6 | + beforeEach(function() { |
| 7 | + body = angular.element(document.body); |
| 8 | + body.html(''); |
| 9 | + }); |
| 10 | + |
| 11 | + describe('popover directive', function() { |
| 12 | + |
| 13 | + var $scope, element; |
| 14 | + beforeEach(inject(function($rootScope, $compile) { |
| 15 | + $scope = $rootScope.$new(); |
| 16 | + element = angular.element( |
| 17 | + '<div style="margin:200px;" data-title="title_text" data-content="content_text" popover></div>' |
| 18 | + ); |
| 19 | + element.attr('id','idx'); |
| 20 | + body.append(element); |
| 21 | + $compile(element)($scope); |
| 22 | + $scope.$apply(); |
| 23 | + })); |
| 24 | + |
| 25 | + it('should be hidden by default', inject(function(popoverElement) { |
| 26 | + expect(popoverElement.visible()).toBe(false); |
| 27 | + })); |
| 28 | + |
| 29 | + it('should capture the click event and set the title and content and position the tip', inject(function(popoverElement) { |
| 30 | + element.triggerHandler('click'); |
| 31 | + expect(popoverElement.isSituatedAt(element)).toBe(true); |
| 32 | + expect(popoverElement.visible()).toBe(true); |
| 33 | + expect(popoverElement.title()).toBe('title_text'); |
| 34 | + expect(popoverElement.content()).toContain('content_text'); |
| 35 | + expect(popoverElement.besideElement.attr('id')).toBe('idx'); |
| 36 | + })); |
| 37 | + |
| 38 | + it('should hide and clear the title and content if the same element is clicked again', inject(function(popoverElement) { |
| 39 | + //show the element |
| 40 | + element.triggerHandler('click'); |
| 41 | + expect(popoverElement.isSituatedAt(element)).toBe(true); |
| 42 | + |
| 43 | + //hide the element |
| 44 | + element.triggerHandler('click'); |
| 45 | + expect(popoverElement.isSituatedAt(element)).toBe(false); |
| 46 | + expect(popoverElement.visible()).toBe(false); |
| 47 | + expect(popoverElement.title()).toBe(''); |
| 48 | + expect(popoverElement.content()).toBe(''); |
| 49 | + })); |
| 50 | + |
| 51 | + it('should parse markdown content', inject(function(popoverElement, $compile) { |
| 52 | + element = angular.element( |
| 53 | + '<div style="margin:200px;" data-title="#title_text" data-content="#heading" popover></div>' |
| 54 | + ); |
| 55 | + body.append(element); |
| 56 | + $compile(element)($scope); |
| 57 | + $scope.$apply(); |
| 58 | + element.triggerHandler('click'); |
| 59 | + expect(popoverElement.title()).toBe('#title_text'); |
| 60 | + expect(popoverElement.content()).toBe('<h1 id="heading">heading</h1>'); |
| 61 | + })); |
| 62 | + |
| 63 | + }); |
| 64 | + |
| 65 | + |
| 66 | + describe('foldout directive', function() { |
| 67 | + |
| 68 | + var $scope, parent, element, url, window; |
| 69 | + beforeEach(function() { |
| 70 | + module(function($provide, $animationProvider) { |
| 71 | + $provide.value('$window', window = angular.mock.createMockWindow()); |
| 72 | + $animationProvider.register('foldout-enter', function($window) { |
| 73 | + return { |
| 74 | + start : function(element, done) { |
| 75 | + $window.setTimeout(done, 1000); |
| 76 | + } |
| 77 | + } |
| 78 | + }); |
| 79 | + $animationProvider.register('foldout-hide', function($window) { |
| 80 | + return { |
| 81 | + start : function(element, done) { |
| 82 | + $window.setTimeout(done, 500); |
| 83 | + } |
| 84 | + } |
| 85 | + }); |
| 86 | + $animationProvider.register('foldout-show', function($window) { |
| 87 | + return { |
| 88 | + start : function(element, done) { |
| 89 | + $window.setTimeout(done, 200); |
| 90 | + } |
| 91 | + } |
| 92 | + }); |
| 93 | + }); |
| 94 | + inject(function($rootScope, $compile, $templateCache) { |
| 95 | + url = '/page.html'; |
| 96 | + $scope = $rootScope.$new(); |
| 97 | + parent = angular.element('<div class="parent"></div>'); |
| 98 | + element = angular.element('<div data-url="' + url + '" foldout></div>'); |
| 99 | + body.append(parent); |
| 100 | + parent.append(element); |
| 101 | + $compile(parent)($scope); |
| 102 | + $scope.$apply(); |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should inform that it is loading', inject(function($httpBackend) { |
| 107 | + $httpBackend.expect('GET', url).respond('hello'); |
| 108 | + element.triggerHandler('click'); |
| 109 | + |
| 110 | + var kids = body.children(); |
| 111 | + var foldout = angular.element(kids[kids.length-1]); |
| 112 | + expect(foldout.html()).toContain('loading'); |
| 113 | + })); |
| 114 | + |
| 115 | + it('should download a foldout HTML page and animate the contents', inject(function($httpBackend) { |
| 116 | + $httpBackend.expect('GET', url).respond('hello'); |
| 117 | + |
| 118 | + element.triggerHandler('click'); |
| 119 | + $httpBackend.flush(); |
| 120 | + |
| 121 | + window.setTimeout.expect(1).process(); |
| 122 | + window.setTimeout.expect(1000).process(); |
| 123 | + |
| 124 | + var kids = body.children(); |
| 125 | + var foldout = angular.element(kids[kids.length-1]); |
| 126 | + expect(foldout.text()).toContain('hello'); |
| 127 | + })); |
| 128 | + |
| 129 | + it('should hide then show when clicked again', inject(function($httpBackend) { |
| 130 | + $httpBackend.expect('GET', url).respond('hello'); |
| 131 | + |
| 132 | + //enter |
| 133 | + element.triggerHandler('click'); |
| 134 | + $httpBackend.flush(); |
| 135 | + window.setTimeout.expect(1).process(); |
| 136 | + window.setTimeout.expect(1000).process(); |
| 137 | + |
| 138 | + //hide |
| 139 | + element.triggerHandler('click'); |
| 140 | + window.setTimeout.expect(1).process(); |
| 141 | + window.setTimeout.expect(500).process(); |
| 142 | + |
| 143 | + //show |
| 144 | + element.triggerHandler('click'); |
| 145 | + window.setTimeout.expect(1).process(); |
| 146 | + window.setTimeout.expect(200).process(); |
| 147 | + })); |
| 148 | + |
| 149 | + }); |
| 150 | + |
| 151 | + describe('DocsController fold', function() { |
| 152 | + |
| 153 | + var window, $scope, ctrl; |
| 154 | + beforeEach(function() { |
| 155 | + module(function($provide, $animationProvider) { |
| 156 | + $provide.value('$window', window = angular.mock.createMockWindow()); |
| 157 | + }); |
| 158 | + inject(function($rootScope, $controller, $location, $cookies, sections) { |
| 159 | + $scope = $rootScope.$new(); |
| 160 | + ctrl = $controller('DocsController',{ |
| 161 | + $scope : $scope, |
| 162 | + $location : $location, |
| 163 | + $window : window, |
| 164 | + $cookies : $cookies, |
| 165 | + sections : sections |
| 166 | + }); |
| 167 | + }); |
| 168 | + }); |
| 169 | + |
| 170 | + it('should download and reveal the foldover container', inject(function($compile, $httpBackend) { |
| 171 | + var url = '/page.html'; |
| 172 | + var fullUrl = '/notes/' + url; |
| 173 | + $httpBackend.expect('GET', fullUrl).respond('hello'); |
| 174 | + |
| 175 | + var element = angular.element('<div ng-include="docs_fold"></div>'); |
| 176 | + $compile(element)($scope); |
| 177 | + $scope.$apply(); |
| 178 | + |
| 179 | + $scope.fold(url); |
| 180 | + |
| 181 | + $httpBackend.flush(); |
| 182 | + })); |
| 183 | + |
| 184 | + }); |
| 185 | + |
| 186 | +}); |
0 commit comments