@@ -1000,6 +1000,12 @@ describe('datepicker directive', function () {
1000
1000
expect ( $rootScope . date ) . toEqual ( new Date ( 'September 15, 2010 15:30:00' ) ) ;
1001
1001
} ) ;
1002
1002
1003
+ it ( 'should mark the input field dirty when a day is clicked' , function ( ) {
1004
+ expect ( inputEl ) . toHaveClass ( 'ng-pristine' ) ;
1005
+ clickOption ( 2 , 3 ) ;
1006
+ expect ( inputEl ) . toHaveClass ( 'ng-dirty' ) ;
1007
+ } ) ;
1008
+
1003
1009
it ( 'updates the input correctly when model changes' , function ( ) {
1004
1010
$rootScope . date = new Date ( "January 10, 1983 10:00:00" ) ;
1005
1011
$rootScope . $digest ( ) ;
@@ -1014,11 +1020,22 @@ describe('datepicker directive', function () {
1014
1020
expect ( dropdownEl . css ( 'display' ) ) . toBe ( 'none' ) ;
1015
1021
} ) ;
1016
1022
1017
- it ( 'updates the model when input value changes' , function ( ) {
1023
+ it ( 'updates the model & calendar when input value changes' , function ( ) {
1018
1024
changeInputValueTo ( inputEl , 'March 5, 1980' ) ;
1025
+
1019
1026
expect ( $rootScope . date . getFullYear ( ) ) . toEqual ( 1980 ) ;
1020
1027
expect ( $rootScope . date . getMonth ( ) ) . toEqual ( 2 ) ;
1021
1028
expect ( $rootScope . date . getDate ( ) ) . toEqual ( 5 ) ;
1029
+
1030
+ expect ( getOptions ( ) ) . toEqual ( [
1031
+ [ '24' , '25' , '26' , '27' , '28' , '29' , '01' ] ,
1032
+ [ '02' , '03' , '04' , '05' , '06' , '07' , '08' ] ,
1033
+ [ '09' , '10' , '11' , '12' , '13' , '14' , '15' ] ,
1034
+ [ '16' , '17' , '18' , '19' , '20' , '21' , '22' ] ,
1035
+ [ '23' , '24' , '25' , '26' , '27' , '28' , '29' ] ,
1036
+ [ '30' , '31' , '01' , '02' , '03' , '04' , '05' ]
1037
+ ] ) ;
1038
+ expectSelectedElement ( 1 , 3 ) ;
1022
1039
} ) ;
1023
1040
1024
1041
it ( 'closes when click outside of calendar' , function ( ) {
@@ -1074,7 +1091,7 @@ describe('datepicker directive', function () {
1074
1091
} ) ;
1075
1092
} ) ;
1076
1093
1077
- describe ( 'use with ng-required directive' , function ( ) {
1094
+ describe ( 'use with ` ng-required` directive' , function ( ) {
1078
1095
beforeEach ( inject ( function ( ) {
1079
1096
$rootScope . date = '' ;
1080
1097
var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup ng-required="true"><div>' ) ( $rootScope ) ;
@@ -1092,8 +1109,42 @@ describe('datepicker directive', function () {
1092
1109
} ) ;
1093
1110
} ) ;
1094
1111
1095
- } ) ;
1112
+ describe ( 'use with `ng-change` directive' , function ( ) {
1113
+ beforeEach ( inject ( function ( ) {
1114
+ $rootScope . changeHandler = jasmine . createSpy ( 'changeHandler' ) ;
1115
+ $rootScope . date = new Date ( ) ;
1116
+ var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup ng-required="true" ng-change="changeHandler()"><div>' ) ( $rootScope ) ;
1117
+ $rootScope . $digest ( ) ;
1118
+ assignElements ( wrapElement ) ;
1119
+ } ) ) ;
1096
1120
1121
+ it ( 'should not be called initially' , function ( ) {
1122
+ expect ( $rootScope . changeHandler ) . not . toHaveBeenCalled ( ) ;
1123
+ } ) ;
1124
+
1125
+ it ( 'should be called when a day is clicked' , function ( ) {
1126
+ clickOption ( 2 , 3 ) ;
1127
+ expect ( $rootScope . changeHandler ) . toHaveBeenCalled ( ) ;
1128
+ } ) ;
1129
+
1130
+ it ( 'should not be called when model changes programatically' , function ( ) {
1131
+ $rootScope . date = new Date ( ) ;
1132
+ $rootScope . $digest ( ) ;
1133
+ expect ( $rootScope . changeHandler ) . not . toHaveBeenCalled ( ) ;
1134
+ } ) ;
1135
+ } ) ;
1136
+
1137
+ describe ( 'to invalid input' , function ( ) {
1138
+ it ( 'sets `ng-invalid`' , function ( ) {
1139
+ changeInputValueTo ( inputEl , 'pizza' ) ;
1140
+
1141
+ expect ( inputEl ) . toHaveClass ( 'ng-invalid' ) ;
1142
+ expect ( inputEl ) . toHaveClass ( 'ng-invalid-date' ) ;
1143
+ expect ( $rootScope . date ) . toBeUndefined ( ) ;
1144
+ expect ( inputEl . val ( ) ) . toBe ( 'pizza' ) ;
1145
+ } ) ;
1146
+ } ) ;
1147
+ } ) ;
1097
1148
} ) ;
1098
1149
1099
1150
describe ( 'datepicker directive with empty initial state' , function ( ) {
0 commit comments