|
30 | 30 |
|
31 | 31 | var enableAnimations;
|
32 | 32 |
|
33 |
| - afterEach(function() { |
34 |
| - enableAnimations && enableAnimations(); |
35 |
| - enableAnimations = null; |
36 |
| - }); |
37 |
| - |
38 |
| - beforeEach(function() { |
39 |
| - |
40 |
| - /** |
41 |
| - * Before each test, require that the 'ngMaterial-mock' module is ready for injection |
42 |
| - * NOTE: assumes that angular-material-mocks.js has been loaded. |
43 |
| - */ |
44 |
| - |
45 |
| - module('ngAnimate'); |
46 |
| - module('ngMaterial-mock'); |
47 |
| - |
48 |
| - module(function() { |
49 |
| - return function($mdUtil, $rootElement, $document, $animate) { |
50 |
| - var DISABLE_ANIMATIONS = 'disable_animations'; |
51 |
| - |
52 |
| - // Create special animation 'stop' function used |
53 |
| - // to set 0ms durations for all animations and transitions |
54 |
| - |
55 |
| - window.disableAnimations = function disableAnimations() { |
56 |
| - var body = angular.element($document[0].body); |
57 |
| - var head = angular.element($document[0].getElementsByTagName('head')[0]); |
58 |
| - var styleSheet = angular.element( buildStopTransitions() ); |
59 |
| - |
60 |
| - $animate.enabled(false); |
61 |
| - |
62 |
| - head.prepend(styleSheet); |
63 |
| - body.addClass(DISABLE_ANIMATIONS); |
64 |
| - |
65 |
| - // Prepare auto-restore |
66 |
| - enableAnimations = function() { |
67 |
| - body.removeClass(DISABLE_ANIMATIONS); |
68 |
| - styleSheet.remove(); |
69 |
| - }; |
70 |
| - }; |
71 |
| - |
72 |
| - /** |
73 |
| - * Build stylesheet to set all transition and animation |
74 |
| - * durations' to zero. |
75 |
| - */ |
76 |
| - function buildStopTransitions() { |
77 |
| - var style = "<style> .{0} * { {1} }</style>"; |
78 |
| - |
79 |
| - return $mdUtil.supplant(style,[ DISABLE_ANIMATIONS, |
80 |
| - "transition -webkit-transition animation -webkit-animation" |
81 |
| - .split(" ") |
82 |
| - .map(function(key){ |
83 |
| - return $mdUtil.supplant("{0}: 0s none !important",[key]); |
84 |
| - }) |
85 |
| - .join("; ") |
86 |
| - ]); |
87 |
| - |
88 |
| - } |
89 |
| - |
90 |
| - }; |
91 |
| - }); |
92 |
| - |
93 |
| - /** |
94 |
| - * Mocks the focus method from the HTMLElement prototype for the duration |
95 |
| - * of the running test. |
96 |
| - * |
97 |
| - * The mock will be automatically removed after the test finished. |
98 |
| - * |
99 |
| - * @example |
100 |
| - * |
101 |
| - * it('some focus test', inject(function($document) |
102 |
| - * { |
103 |
| - * jasmine.mockElementFocus(this); // 'this' is the test instance |
104 |
| - * |
105 |
| - * doSomething(); |
106 |
| - * expect($document.activeElement).toBe(someElement[0]); |
107 |
| - * |
108 |
| - * })); |
109 |
| - * |
110 |
| - */ |
111 |
| - jasmine.mockElementFocus = function() { |
112 |
| - var _focusFn = HTMLElement.prototype.focus; |
113 |
| - |
114 |
| - inject(function($document) { |
115 |
| - HTMLElement.prototype.focus = function() { |
116 |
| - $document.activeElement = this; |
117 |
| - }; |
118 |
| - }); |
119 |
| - |
120 |
| - // Un-mock focus after the test is done |
121 |
| - afterEach(function() { |
122 |
| - HTMLElement.prototype.focus = _focusFn; |
123 |
| - }); |
124 |
| - |
125 |
| - }; |
126 |
| - |
| 33 | + beforeAll(function () { |
127 | 34 | /**
|
128 | 35 | * Add special matchers used in the AngularJS-Material spec.
|
129 | 36 | */
|
|
279 | 186 | }
|
280 | 187 | });
|
281 | 188 |
|
| 189 | + /** |
| 190 | + * Mocks the focus method from the HTMLElement prototype for the duration |
| 191 | + * of the running test. |
| 192 | + * |
| 193 | + * The mock will be automatically removed after the test finished. |
| 194 | + * |
| 195 | + * @example |
| 196 | + * |
| 197 | + * it('some focus test', inject(function($document) |
| 198 | + * { |
| 199 | + * jasmine.mockElementFocus(this); // 'this' is the test instance |
| 200 | + * |
| 201 | + * doSomething(); |
| 202 | + * expect($document.activeElement).toBe(someElement[0]); |
| 203 | + * |
| 204 | + * })); |
| 205 | + * |
| 206 | + */ |
| 207 | + jasmine.mockElementFocus = function() { |
| 208 | + var _focusFn = HTMLElement.prototype.focus; |
| 209 | + |
| 210 | + inject(function($document) { |
| 211 | + HTMLElement.prototype.focus = function() { |
| 212 | + $document.activeElement = this; |
| 213 | + }; |
| 214 | + }); |
| 215 | + |
| 216 | + // Un-mock focus after the test is done |
| 217 | + afterEach(function() { |
| 218 | + HTMLElement.prototype.focus = _focusFn; |
| 219 | + }); |
| 220 | + |
| 221 | + }; |
| 222 | + |
282 | 223 | /**
|
283 | 224 | * Returns the angular element associated with a css selector or element.
|
284 | 225 | * @param el {string|!angular.JQLite|!Element}
|
|
289 | 230 | document.querySelector(el) : el;
|
290 | 231 | return angular.element(queryResult);
|
291 | 232 | }
|
| 233 | + }); |
| 234 | + |
| 235 | + afterEach(function() { |
| 236 | + enableAnimations && enableAnimations(); |
| 237 | + enableAnimations = null; |
| 238 | + }); |
| 239 | + |
| 240 | + beforeEach(function() { |
| 241 | + |
| 242 | + /** |
| 243 | + * Before each test, require that the 'ngMaterial-mock' module is ready for injection |
| 244 | + * NOTE: assumes that angular-material-mocks.js has been loaded. |
| 245 | + */ |
| 246 | + |
| 247 | + module('ngAnimate'); |
| 248 | + module('ngMaterial-mock'); |
| 249 | + |
| 250 | + module(function() { |
| 251 | + return function($mdUtil, $rootElement, $document, $animate) { |
| 252 | + var DISABLE_ANIMATIONS = 'disable_animations'; |
| 253 | + |
| 254 | + // Create special animation 'stop' function used |
| 255 | + // to set 0ms durations for all animations and transitions |
| 256 | + |
| 257 | + window.disableAnimations = function disableAnimations() { |
| 258 | + var body = angular.element($document[0].body); |
| 259 | + var head = angular.element($document[0].getElementsByTagName('head')[0]); |
| 260 | + var styleSheet = angular.element( buildStopTransitions() ); |
| 261 | + |
| 262 | + $animate.enabled(false); |
| 263 | + |
| 264 | + head.prepend(styleSheet); |
| 265 | + body.addClass(DISABLE_ANIMATIONS); |
| 266 | + |
| 267 | + // Prepare auto-restore |
| 268 | + enableAnimations = function() { |
| 269 | + body.removeClass(DISABLE_ANIMATIONS); |
| 270 | + styleSheet.remove(); |
| 271 | + }; |
| 272 | + }; |
| 273 | + |
| 274 | + /** |
| 275 | + * Build stylesheet to set all transition and animation |
| 276 | + * durations' to zero. |
| 277 | + */ |
| 278 | + function buildStopTransitions() { |
| 279 | + var style = "<style> .{0} * { {1} }</style>"; |
| 280 | + |
| 281 | + return $mdUtil.supplant(style,[ DISABLE_ANIMATIONS, |
| 282 | + "transition -webkit-transition animation -webkit-animation" |
| 283 | + .split(" ") |
| 284 | + .map(function(key){ |
| 285 | + return $mdUtil.supplant("{0}: 0s none !important",[key]); |
| 286 | + }) |
| 287 | + .join("; ") |
| 288 | + ]); |
| 289 | + |
| 290 | + } |
| 291 | + |
| 292 | + }; |
| 293 | + }); |
292 | 294 |
|
293 | 295 | });
|
294 | 296 |
|
|
0 commit comments