|
1 | 1 | describe('mdProgressLinear', function() {
|
2 | 2 |
|
3 |
| - beforeEach(module('material.components.progressLinear')); |
4 |
| - |
5 |
| - it('should auto-set the md-mode to "indeterminate" if not specified', inject(function($compile, $rootScope, $mdConstant) { |
6 |
| - var element = $compile('<div>' + |
7 |
| - '<md-progress-linear></md-progress-linear>' + |
8 |
| - '</div>')($rootScope); |
9 |
| - |
10 |
| - $rootScope.$apply(function() { |
11 |
| - $rootScope.progress = 50; |
12 |
| - $rootScope.mode = ""; |
| 3 | + var element, $rootScope, $compile, $mdConstant; |
| 4 | + |
| 5 | + function makeElement(attrs) { |
| 6 | + element = $compile( |
| 7 | + '<div>' + |
| 8 | + '<md-progress-linear ' + (attrs || '') + '></md-progress-linear>' + |
| 9 | + '</div>' |
| 10 | + )($rootScope); |
| 11 | + |
| 12 | + $rootScope.$digest(); |
| 13 | + return element; |
| 14 | + } |
| 15 | + |
| 16 | + beforeEach(function() { |
| 17 | + module('material.components.progressLinear'); |
| 18 | + |
| 19 | + inject(function(_$compile_, _$rootScope_, _$mdConstant_) { |
| 20 | + $rootScope = _$rootScope_; |
| 21 | + $compile = _$compile_; |
| 22 | + $mdConstant = _$mdConstant_; |
13 | 23 | });
|
| 24 | + }); |
14 | 25 |
|
15 |
| - var progress = element.find('md-progress-linear'); |
16 |
| - expect(progress.attr('md-mode')).toEqual('indeterminate'); |
17 |
| - })); |
18 |
| - |
19 |
| - it('should auto-set the md-mode to "indeterminate" if specified a not valid mode', inject(function($compile, $rootScope, $mdConstant) { |
20 |
| - var element = $compile('<div>' + |
21 |
| - '<md-progress-linear md-mode="test"></md-progress-linear>' + |
22 |
| - '</div>')($rootScope); |
23 |
| - |
24 |
| - $rootScope.$apply(function() { |
25 |
| - $rootScope.progress = 50; |
26 |
| - $rootScope.mode = ""; |
27 |
| - }); |
| 26 | + afterEach(function() { |
| 27 | + element && element.remove(); |
| 28 | + }); |
28 | 29 |
|
| 30 | + it('should auto-set the md-mode to "indeterminate" if not specified', function() { |
| 31 | + var element = makeElement(); |
29 | 32 | var progress = element.find('md-progress-linear');
|
| 33 | + |
30 | 34 | expect(progress.attr('md-mode')).toEqual('indeterminate');
|
31 |
| - })); |
| 35 | + }); |
32 | 36 |
|
33 |
| - it('should trim the md-mode value', inject(function($compile, $rootScope, $mdConstant) { |
34 |
| - element = $compile('<div>' + |
35 |
| - '<md-progress-linear md-mode=" indeterminate"></md-progress-linear>' + |
36 |
| - '</div>')($rootScope); |
| 37 | + it('should auto-set the md-mode to "indeterminate" if specified a not valid mode', function() { |
| 38 | + var element = makeElement('md-mode="test"'); |
| 39 | + var progress = element.find('md-progress-linear'); |
37 | 40 |
|
38 |
| - $rootScope.$apply(function() { |
39 |
| - }); |
| 41 | + expect(progress.attr('md-mode')).toEqual('indeterminate'); |
| 42 | + }); |
40 | 43 |
|
| 44 | + it('should trim the md-mode value', function() { |
| 45 | + var element = makeElement('md-mode=" indeterminate"'); |
41 | 46 | var progress = element.find('md-progress-linear');
|
| 47 | + |
42 | 48 | expect(progress.attr('md-mode')).toEqual('indeterminate');
|
43 |
| - })); |
| 49 | + }); |
44 | 50 |
|
45 |
| - it('should auto-set the md-mode to "determinate" if not specified but has value', inject(function($compile, $rootScope, $mdConstant) { |
46 |
| - var element = $compile('<div>' + |
47 |
| - '<md-progress-linear value="{{progress}}"></md-progress-linear>' + |
48 |
| - '</div>')($rootScope); |
| 51 | + it('should auto-set the md-mode to "determinate" if not specified but has value', function() { |
| 52 | + var element = makeElement('value="{{progress}}"'); |
| 53 | + var progress = element.find('md-progress-linear'); |
49 | 54 |
|
50 |
| - $rootScope.$apply(function() { |
51 |
| - $rootScope.progress = 50; |
52 |
| - $rootScope.mode = ""; |
53 |
| - }); |
| 55 | + $rootScope.$apply('progress = 50'); |
54 | 56 |
|
55 |
| - var progress = element.find('md-progress-linear'); |
56 | 57 | expect(progress.attr('md-mode')).toEqual('determinate');
|
57 |
| - })); |
| 58 | + }); |
58 | 59 |
|
59 |
| - it('should set not transform if mode is undefined', inject(function($compile, $rootScope, $mdConstant) { |
60 |
| - var element = $compile('<div>' + |
61 |
| - '<md-progress-linear value="{{progress}}" md-mode="{{mode}}">' + |
62 |
| - '</md-progress-linear>' + |
63 |
| - '</div>')($rootScope); |
| 60 | + it('should set not transform if mode is undefined', function() { |
| 61 | + var element = makeElement('value="{{progress}}" md-mode="{{mode}}"'); |
| 62 | + var bar2 = element[0].querySelector('._md-bar2'); |
64 | 63 |
|
65 | 64 | $rootScope.$apply(function() {
|
66 | 65 | $rootScope.progress = 50;
|
67 |
| - $rootScope.mode = ""; |
| 66 | + $rootScope.mode = ''; |
68 | 67 | });
|
69 | 68 |
|
70 |
| - var progress = element.find('md-progress-linear'), |
71 |
| - bar2 = angular.element(progress[0].querySelectorAll('._md-bar2'))[0]; |
72 |
| - |
73 | 69 | expect(bar2.style[$mdConstant.CSS.TRANSFORM]).toEqual('');
|
74 |
| - })); |
75 |
| - |
76 |
| - it('should set transform based on value', inject(function($compile, $rootScope, $mdConstant) { |
77 |
| - var element = $compile('<div>' + |
78 |
| - '<md-progress-linear value="{{progress}}" md-mode="determinate">' + |
79 |
| - '</md-progress-linear>' + |
80 |
| - '</div>')($rootScope); |
81 |
| - |
82 |
| - $rootScope.$apply(function() { |
83 |
| - $rootScope.progress = 50; |
84 |
| - }); |
| 70 | + }); |
85 | 71 |
|
86 |
| - var progress = element.find('md-progress-linear'), |
87 |
| - bar2 = angular.element(progress[0].querySelectorAll('._md-bar2'))[0]; |
| 72 | + it('should set transform based on value', function() { |
| 73 | + var element = makeElement('value="{{progress}}" md-mode="determinate"'); |
| 74 | + var bar2 = element[0].querySelector('._md-bar2'); |
88 | 75 |
|
| 76 | + $rootScope.$apply('progress = 50'); |
89 | 77 | expect(bar2.style[$mdConstant.CSS.TRANSFORM]).toEqual('translateX(-25%) scale(0.5, 1)');
|
90 |
| - })); |
91 |
| - |
92 |
| - it('should update aria-valuenow', inject(function($compile, $rootScope) { |
93 |
| - var element = $compile('<div>' + |
94 |
| - '<md-progress-linear value="{{progress}}">' + |
95 |
| - '</md-progress-linear>' + |
96 |
| - '</div>')($rootScope); |
97 |
| - |
98 |
| - $rootScope.$apply(function() { |
99 |
| - $rootScope.progress = 50; |
100 |
| - }); |
| 78 | + }); |
101 | 79 |
|
| 80 | + it('should update aria-valuenow', function() { |
| 81 | + var element = makeElement('value="{{progress}}"'); |
102 | 82 | var progress = element.find('md-progress-linear');
|
103 | 83 |
|
| 84 | + $rootScope.$apply('progress = 50'); |
104 | 85 | expect(progress.eq(0).attr('aria-valuenow')).toEqual('50');
|
105 |
| - })); |
| 86 | + }); |
106 | 87 |
|
107 |
| - it('should set transform based on buffer value', inject(function($compile, $rootScope, $mdConstant) { |
108 |
| - var element = $compile('<div>' + |
109 |
| - '<md-progress-linear value="{{progress}}" md-buffer-value="{{progress2}}" md-mode="buffer">' + |
110 |
| - '</md-progress-linear>' + |
111 |
| - '</div>')($rootScope); |
| 88 | + it('should set transform based on buffer value', function() { |
| 89 | + var element = makeElement('value="{{progress}}" md-buffer-value="{{progress2}}" md-mode="buffer"'); |
| 90 | + var bar1 = element[0].querySelector('._md-bar1'); |
112 | 91 |
|
113 | 92 | $rootScope.$apply(function() {
|
114 | 93 | $rootScope.progress = 50;
|
115 | 94 | $rootScope.progress2 = 75;
|
116 | 95 | });
|
117 | 96 |
|
118 |
| - var progress = element.find('md-progress-linear'), |
119 |
| - bar1 = angular.element(progress[0].querySelectorAll('._md-bar1'))[0]; |
120 |
| - |
121 | 97 | expect(bar1.style[$mdConstant.CSS.TRANSFORM]).toEqual('translateX(-12.5%) scale(0.75, 1)');
|
122 |
| - })); |
| 98 | + }); |
123 | 99 |
|
124 |
| - it('should not set transform in query mode', inject(function($compile, $rootScope, $mdConstant) { |
125 |
| - var element = $compile('<div>' + |
126 |
| - '<md-progress-linear md-mode="query" value="{{progress}}">' + |
127 |
| - '</md-progress-linear>' + |
128 |
| - '</div>')($rootScope); |
| 100 | + it('should not set transform in query mode', function() { |
| 101 | + var element = makeElement('md-mode="query" value="{{progress}}"'); |
| 102 | + var bar2 = element[0].querySelector('._md-bar2'); |
129 | 103 |
|
130 |
| - $rootScope.$apply(function() { |
131 |
| - $rootScope.progress = 80; |
| 104 | + $rootScope.$apply('progress = 80'); |
| 105 | + expect(bar2.style[$mdConstant.CSS.TRANSFORM]).toBeFalsy(); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('disabled mode', function() { |
| 109 | + it('should hide the element', function() { |
| 110 | + var element = makeElement('disabled'); |
| 111 | + var progress = element.find('md-progress-linear').eq(0); |
| 112 | + expect(progress.hasClass('_md-progress-linear-disabled')).toBe(true); |
132 | 113 | });
|
133 | 114 |
|
134 |
| - var progress = element.find('md-progress-linear'), |
135 |
| - bar2 = angular.element(progress[0].querySelectorAll('._md-bar2'))[0]; |
| 115 | + it('should toggle the mode on the container', function() { |
| 116 | + var element = makeElement('md-mode="query" ng-disabled="isDisabled"'); |
| 117 | + var container = angular.element(element[0].querySelector('._md-container')); |
| 118 | + var modeClass = '_md-mode-query'; |
136 | 119 |
|
137 |
| - expect(bar2.style[$mdConstant.CSS.TRANSFORM]).toBeFalsy(); |
138 |
| - })); |
| 120 | + expect(container.hasClass(modeClass)).toBe(true); |
139 | 121 |
|
140 |
| - it('should hide the element if it is disabled', inject(function($compile, $rootScope) { |
141 |
| - var element = $compile('<div>' + |
142 |
| - '<md-progress-linear value="25" disabled>' + |
143 |
| - '</md-progress-linear>' + |
144 |
| - '</div>')($rootScope); |
| 122 | + $rootScope.$apply('isDisabled = true'); |
| 123 | + expect(container.hasClass(modeClass)).toBe(false); |
145 | 124 |
|
146 |
| - var progress = element.find('md-progress-linear').eq(0); |
147 |
| - |
148 |
| - expect(progress.hasClass('_md-progress-linear-disabled')).toBe(true); |
149 |
| - })); |
| 125 | + $rootScope.$apply('isDisabled = false'); |
| 126 | + expect(container.hasClass(modeClass)).toBe(true); |
| 127 | + }); |
| 128 | + }); |
150 | 129 | });
|
0 commit comments