@@ -28,6 +28,7 @@ describe('md-date-picker', function() {
28
28
'md-max-date="maxDate" ' +
29
29
'md-min-date="minDate" ' +
30
30
'ng-model="myDate" ' +
31
+ 'ng-required="isRequired" ' +
31
32
'ng-disabled="isDisabled">' +
32
33
'</md-datepicker>' ;
33
34
ngElement = $compile ( template ) ( pageScope ) ;
@@ -58,73 +59,6 @@ describe('md-date-picker', function() {
58
59
expect ( pageScope . myDate ) . toBeNull ( ) ;
59
60
} ) ;
60
61
61
- it ( 'should open and close the floating calendar pane element' , function ( ) {
62
- // We can asset that the calendarPane is in the DOM by checking if it has a height.
63
- expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
64
-
65
- element . querySelector ( 'md-button' ) . click ( ) ;
66
- $timeout . flush ( ) ;
67
-
68
- expect ( controller . calendarPane . offsetHeight ) . toBeGreaterThan ( 0 ) ;
69
- expect ( controller . inputMask . style . left ) . toBe ( controller . inputContainer . clientWidth + 'px' ) ;
70
-
71
- // Click off of the calendar.
72
- document . body . click ( ) ;
73
- expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
74
- } ) ;
75
-
76
- it ( 'should open and close the floating calendar pane element via keyboard' , function ( ) {
77
- controller . ngInputElement . triggerHandler ( {
78
- type : 'keydown' ,
79
- altKey : true ,
80
- keyCode : keyCodes . DOWN_ARROW
81
- } ) ;
82
- $timeout . flush ( ) ;
83
-
84
- expect ( controller . calendarPane . offsetHeight ) . toBeGreaterThan ( 0 ) ;
85
-
86
- // Fake an escape event closing the calendar.
87
- pageScope . $broadcast ( 'md-calendar-close' ) ;
88
-
89
- } ) ;
90
-
91
- it ( 'should adjust the position of the floating pane if it would go off-screen' , function ( ) {
92
- // Absolutely position the picker near the edge of the screen.
93
- var bodyRect = document . body . getBoundingClientRect ( ) ;
94
- element . style . position = 'absolute' ;
95
- element . style . top = bodyRect . bottom + 'px' ;
96
- element . style . left = bodyRect . right + 'px' ;
97
- document . body . appendChild ( element ) ;
98
-
99
- // Open the pane.
100
- element . querySelector ( 'md-button' ) . click ( ) ;
101
- $timeout . flush ( ) ;
102
-
103
- // Expect that the whole pane is on-screen.
104
- var paneRect = controller . calendarPane . getBoundingClientRect ( ) ;
105
- expect ( paneRect . right ) . toBeLessThan ( bodyRect . right + 1 ) ;
106
- expect ( paneRect . bottom ) . toBeLessThan ( bodyRect . bottom + 1 ) ;
107
- expect ( paneRect . top ) . toBeGreaterThan ( 0 ) ;
108
- expect ( paneRect . left ) . toBeGreaterThan ( 0 ) ;
109
-
110
- document . body . removeChild ( element ) ;
111
- } ) ;
112
-
113
- it ( 'should shink the calendar pane when it would otherwise not fit on the screen' , function ( ) {
114
- // Make the body narrow so that the calendar pane won't fit on-screen.
115
- document . body . style . width = '300px' ;
116
-
117
- // Open the calendar pane.
118
- element . querySelector ( 'md-button' ) . click ( ) ;
119
- $timeout . flush ( ) ;
120
-
121
- // Expect the calendarPane to be scaled by an amount between zero and one.
122
- expect ( controller . calendarPane . style . transform ) . toMatch ( / s c a l e \( 0 \. \d + \) / ) ;
123
-
124
- // Reset the body width.
125
- document . body . style . width = '' ;
126
- } ) ;
127
-
128
62
it ( 'should disable the internal inputs based on ng-disabled binding' , function ( ) {
129
63
expect ( controller . inputElement . disabled ) . toBe ( false ) ;
130
64
expect ( controller . calendarButton . disabled ) . toBe ( false ) ;
@@ -136,23 +70,41 @@ describe('md-date-picker', function() {
136
70
expect ( controller . calendarButton . disabled ) . toBe ( true ) ;
137
71
} ) ;
138
72
139
- it ( 'should not open the calendar pane if disabled' , function ( ) {
140
- controller . setDisabled ( true ) ;
141
- controller . openCalendarPane ( {
142
- target : controller . inputElement
143
- } ) ;
144
- scope . $apply ( ) ;
145
- expect ( controller . isCalendarOpen ) . toBeFalsy ( ) ;
146
- expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
147
- } ) ;
148
-
149
73
it ( 'should update the internal input placeholder' , function ( ) {
150
74
expect ( controller . inputElement . placeholder ) . toBeFalsy ( ) ;
151
75
controller . placeholder = 'Fancy new placeholder' ;
152
76
153
77
expect ( controller . inputElement . placeholder ) . toBe ( 'Fancy new placeholder' ) ;
154
78
} ) ;
155
79
80
+ describe ( 'ngMessages suport' , function ( ) {
81
+ it ( 'should set the `required` $error flag' , function ( ) {
82
+ pageScope . isRequired = true ;
83
+ populateInputElement ( '' ) ;
84
+ pageScope . $apply ( ) ;
85
+
86
+ expect ( controller . ngModelCtrl . $error [ 'required' ] ) . toBe ( true ) ;
87
+ } ) ;
88
+
89
+ it ( 'should set the `mindate` $error flag' , function ( ) {
90
+ pageScope . minDate = new Date ( 2015 , JAN , 1 ) ;
91
+ populateInputElement ( '2014-01-01' ) ;
92
+ pageScope . $apply ( ) ;
93
+ controller . ngModelCtrl . $render ( ) ;
94
+
95
+ expect ( controller . ngModelCtrl . $error [ 'mindate' ] ) . toBe ( true ) ;
96
+ } ) ;
97
+
98
+ it ( 'should set the `mindate` $error flag' , function ( ) {
99
+ pageScope . maxDate = new Date ( 2015 , JAN , 1 ) ;
100
+ populateInputElement ( '2016-01-01' ) ;
101
+ pageScope . $apply ( ) ;
102
+ controller . ngModelCtrl . $render ( ) ;
103
+
104
+ expect ( controller . ngModelCtrl . $error [ 'maxdate' ] ) . toBe ( true ) ;
105
+ } ) ;
106
+ } ) ;
107
+
156
108
describe ( 'input event' , function ( ) {
157
109
it ( 'should update the model value when user enters a valid date' , function ( ) {
158
110
var expectedDate = new Date ( 2015 , JUN , 1 ) ;
@@ -189,7 +141,85 @@ describe('md-date-picker', function() {
189
141
} ) ;
190
142
} ) ;
191
143
192
- it ( 'should close the calendar pane on md-calendar-close' , function ( ) {
144
+ describe ( 'floating calendar pane' , function ( ) {
145
+ it ( 'should open and close the floating calendar pane element' , function ( ) {
146
+ // We can asset that the calendarPane is in the DOM by checking if it has a height.
147
+ expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
148
+
149
+ element . querySelector ( 'md-button' ) . click ( ) ;
150
+ $timeout . flush ( ) ;
151
+
152
+ expect ( controller . calendarPane . offsetHeight ) . toBeGreaterThan ( 0 ) ;
153
+ expect ( controller . inputMask . style . left ) . toBe ( controller . inputContainer . clientWidth + 'px' ) ;
154
+
155
+ // Click off of the calendar.
156
+ document . body . click ( ) ;
157
+ expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
158
+ } ) ;
159
+
160
+ it ( 'should open and close the floating calendar pane element via keyboard' , function ( ) {
161
+ controller . ngInputElement . triggerHandler ( {
162
+ type : 'keydown' ,
163
+ altKey : true ,
164
+ keyCode : keyCodes . DOWN_ARROW
165
+ } ) ;
166
+ $timeout . flush ( ) ;
167
+
168
+ expect ( controller . calendarPane . offsetHeight ) . toBeGreaterThan ( 0 ) ;
169
+
170
+ // Fake an escape event closing the calendar.
171
+ pageScope . $broadcast ( 'md-calendar-close' ) ;
172
+
173
+ } ) ;
174
+
175
+ it ( 'should adjust the position of the floating pane if it would go off-screen' , function ( ) {
176
+ // Absolutely position the picker near the edge of the screen.
177
+ var bodyRect = document . body . getBoundingClientRect ( ) ;
178
+ element . style . position = 'absolute' ;
179
+ element . style . top = bodyRect . bottom + 'px' ;
180
+ element . style . left = bodyRect . right + 'px' ;
181
+ document . body . appendChild ( element ) ;
182
+
183
+ // Open the pane.
184
+ element . querySelector ( 'md-button' ) . click ( ) ;
185
+ $timeout . flush ( ) ;
186
+
187
+ // Expect that the whole pane is on-screen.
188
+ var paneRect = controller . calendarPane . getBoundingClientRect ( ) ;
189
+ expect ( paneRect . right ) . toBeLessThan ( bodyRect . right + 1 ) ;
190
+ expect ( paneRect . bottom ) . toBeLessThan ( bodyRect . bottom + 1 ) ;
191
+ expect ( paneRect . top ) . toBeGreaterThan ( 0 ) ;
192
+ expect ( paneRect . left ) . toBeGreaterThan ( 0 ) ;
193
+
194
+ document . body . removeChild ( element ) ;
195
+ } ) ;
196
+
197
+ it ( 'should shink the calendar pane when it would otherwise not fit on the screen' , function ( ) {
198
+ // Make the body narrow so that the calendar pane won't fit on-screen.
199
+ document . body . style . width = '300px' ;
200
+
201
+ // Open the calendar pane.
202
+ element . querySelector ( 'md-button' ) . click ( ) ;
203
+ $timeout . flush ( ) ;
204
+
205
+ // Expect the calendarPane to be scaled by an amount between zero and one.
206
+ expect ( controller . calendarPane . style . transform ) . toMatch ( / s c a l e \( 0 \. \d + \) / ) ;
207
+
208
+ // Reset the body width.
209
+ document . body . style . width = '' ;
210
+ } ) ;
211
+
212
+ it ( 'should not open the calendar pane if disabled' , function ( ) {
213
+ controller . setDisabled ( true ) ;
214
+ controller . openCalendarPane ( {
215
+ target : controller . inputElement
216
+ } ) ;
217
+ scope . $apply ( ) ;
218
+ expect ( controller . isCalendarOpen ) . toBeFalsy ( ) ;
219
+ expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
220
+ } ) ;
221
+
222
+ it ( 'should close the calendar pane on md-calendar-close' , function ( ) {
193
223
controller . openCalendarPane ( {
194
224
target : controller . inputElement
195
225
} ) ;
@@ -199,6 +229,7 @@ describe('md-date-picker', function() {
199
229
expect ( controller . calendarPaneOpenedFrom ) . toBe ( null ) ;
200
230
expect ( controller . isCalendarOpen ) . toBe ( false ) ;
201
231
} ) ;
232
+ } ) ;
202
233
203
234
describe ( 'md-calendar-change' , function ( ) {
204
235
it ( 'should update the model value and close the calendar pane' , function ( ) {
0 commit comments