|
5 | 5 | describe('input', function() { |
6 | 6 | var helper = {}, $compile, $rootScope, $browser, $sniffer, $timeout, $q; |
7 | 7 |
|
| 8 | + // UA sniffing to exclude Edge from some date input tests |
| 9 | + var isEdge = /\bEdge\//.test(window.navigator.userAgent); |
| 10 | + |
8 | 11 | generateInputCompilerHelper(helper); |
9 | 12 |
|
10 | 13 | beforeEach(inject(function(_$compile_, _$rootScope_, _$browser_, _$sniffer_, _$timeout_, _$q_) { |
@@ -688,18 +691,20 @@ describe('input', function() { |
688 | 691 | expect($rootScope.form.alias.$error.month).toBeTruthy(); |
689 | 692 | }); |
690 | 693 |
|
691 | | - it('should allow four or more digits in year', function() { |
692 | | - var inputElm = helper.compileInput('<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}"/>'); |
693 | 694 |
|
694 | | - helper.changeInputValueTo('10123-03'); |
695 | | - expect(+$rootScope.value).toBe(Date.UTC(10123, 2, 1, 0, 0, 0)); |
| 695 | + if (!isEdge) { |
| 696 | + it('should allow four or more digits in year', function() { |
| 697 | + var inputElm = helper.compileInput('<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}"/>'); |
696 | 698 |
|
697 | | - $rootScope.$apply(function() { |
698 | | - $rootScope.value = new Date(Date.UTC(20456, 3, 1, 0, 0, 0)); |
699 | | - }); |
700 | | - expect(inputElm.val()).toBe('20456-04'); |
701 | | - }); |
| 699 | + helper.changeInputValueTo('10123-03'); |
| 700 | + expect(+$rootScope.value).toBe(Date.UTC(10123, 2, 1, 0, 0, 0)); |
702 | 701 |
|
| 702 | + $rootScope.$apply(function() { |
| 703 | + $rootScope.value = new Date(Date.UTC(20456, 3, 1, 0, 0, 0)); |
| 704 | + }); |
| 705 | + expect(inputElm.val()).toBe('20456-04'); |
| 706 | + }); |
| 707 | + } |
703 | 708 |
|
704 | 709 | it('should only change the month of a bound date', function() { |
705 | 710 | var inputElm = helper.compileInput('<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />'); |
@@ -899,17 +904,19 @@ describe('input', function() { |
899 | 904 | expect(inputElm).toBeValid(); |
900 | 905 | }); |
901 | 906 |
|
902 | | - it('should allow four or more digits in year', function() { |
903 | | - var inputElm = helper.compileInput('<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}"/>'); |
| 907 | + if (!isEdge) { |
| 908 | + it('should allow four or more digits in year', function() { |
| 909 | + var inputElm = helper.compileInput('<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}"/>'); |
904 | 910 |
|
905 | | - helper.changeInputValueTo('10123-W03'); |
906 | | - expect(+$rootScope.value).toBe(Date.UTC(10123, 0, 21)); |
| 911 | + helper.changeInputValueTo('10123-W03'); |
| 912 | + expect(+$rootScope.value).toBe(Date.UTC(10123, 0, 21)); |
907 | 913 |
|
908 | | - $rootScope.$apply(function() { |
909 | | - $rootScope.value = new Date(Date.UTC(20456, 0, 28)); |
| 914 | + $rootScope.$apply(function() { |
| 915 | + $rootScope.value = new Date(Date.UTC(20456, 0, 28)); |
| 916 | + }); |
| 917 | + expect(inputElm.val()).toBe('20456-W04'); |
910 | 918 | }); |
911 | | - expect(inputElm.val()).toBe('20456-W04'); |
912 | | - }); |
| 919 | + } |
913 | 920 |
|
914 | 921 | it('should use UTC if specified in the options', function() { |
915 | 922 | var inputElm = helper.compileInput('<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />'); |
@@ -1195,18 +1202,22 @@ describe('input', function() { |
1195 | 1202 | expect(+$rootScope.value).toBe(+new Date(2000, 0, 1, 1, 2, 0)); |
1196 | 1203 | }); |
1197 | 1204 |
|
1198 | | - it('should allow four or more digits in year', function() { |
1199 | | - var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" />'); |
1200 | 1205 |
|
1201 | | - helper.changeInputValueTo('10123-01-01T01:02'); |
1202 | | - expect(+$rootScope.value).toBe(+new Date(10123, 0, 1, 1, 2, 0)); |
| 1206 | + if (!isEdge) { |
| 1207 | + it('should allow four or more digits in year', function() { |
| 1208 | + var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" />'); |
| 1209 | + |
| 1210 | + helper.changeInputValueTo('10123-01-01T01:02'); |
| 1211 | + expect(+$rootScope.value).toBe(+new Date(10123, 0, 1, 1, 2, 0)); |
| 1212 | + |
| 1213 | + $rootScope.$apply(function() { |
| 1214 | + $rootScope.value = new Date(20456, 1, 1, 1, 2, 0); |
| 1215 | + }); |
| 1216 | + expect(inputElm.val()).toBe('20456-02-01T01:02:00.000'); |
| 1217 | + } |
| 1218 | + ); |
| 1219 | + } |
1203 | 1220 |
|
1204 | | - $rootScope.$apply(function() { |
1205 | | - $rootScope.value = new Date(20456, 1, 1, 1, 2, 0); |
1206 | | - }); |
1207 | | - expect(inputElm.val()).toBe('20456-02-01T01:02:00.000'); |
1208 | | - } |
1209 | | - ); |
1210 | 1221 |
|
1211 | 1222 | it('should label parse errors as `datetimelocal`', function() { |
1212 | 1223 | var inputElm = helper.compileInput('<input type="datetime-local" ng-model="val" name="alias" />', { |
@@ -1800,19 +1811,20 @@ describe('input', function() { |
1800 | 1811 | } |
1801 | 1812 | ); |
1802 | 1813 |
|
1803 | | - it('should allow four or more digits in year', function() { |
1804 | | - var inputElm = helper.compileInput('<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />'); |
1805 | | - |
1806 | | - helper.changeInputValueTo('10123-01-01'); |
1807 | | - expect(+$rootScope.value).toBe(Date.UTC(10123, 0, 1, 0, 0, 0)); |
| 1814 | + if (!isEdge) { |
| 1815 | + it('should allow four or more digits in year', function() { |
| 1816 | + var inputElm = helper.compileInput('<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />'); |
1808 | 1817 |
|
1809 | | - $rootScope.$apply(function() { |
1810 | | - $rootScope.value = new Date(Date.UTC(20456, 1, 1, 0, 0, 0)); |
1811 | | - }); |
1812 | | - expect(inputElm.val()).toBe('20456-02-01'); |
1813 | | - } |
1814 | | - ); |
| 1818 | + helper.changeInputValueTo('10123-01-01'); |
| 1819 | + expect(+$rootScope.value).toBe(Date.UTC(10123, 0, 1, 0, 0, 0)); |
1815 | 1820 |
|
| 1821 | + $rootScope.$apply(function() { |
| 1822 | + $rootScope.value = new Date(Date.UTC(20456, 1, 1, 0, 0, 0)); |
| 1823 | + }); |
| 1824 | + expect(inputElm.val()).toBe('20456-02-01'); |
| 1825 | + } |
| 1826 | + ); |
| 1827 | + } |
1816 | 1828 |
|
1817 | 1829 | it('should label parse errors as `date`', function() { |
1818 | 1830 | var inputElm = helper.compileInput('<input type="date" ng-model="val" name="alias" />', { |
@@ -4224,10 +4236,14 @@ describe('input', function() { |
4224 | 4236 | }); |
4225 | 4237 |
|
4226 | 4238 | expect(inputElm[0].value).toBe(''); |
4227 | | - // Support: IE 9-11 |
| 4239 | + // Support: IE 9-11, Edge |
4228 | 4240 | // In IE it is not possible to remove the `value` attribute from an input element. |
4229 | | - if (!msie) { |
| 4241 | + if (!msie && !isEdge) { |
4230 | 4242 | expect(inputElm[0].getAttribute('value')).toBeNull(); |
| 4243 | + } else { |
| 4244 | + // Support: IE 9-11, Edge |
| 4245 | + // This will fail if the Edge bug gets fixed |
| 4246 | + expect(inputElm[0].getAttribute('value')).toBe('something'); |
4231 | 4247 | } |
4232 | 4248 | }); |
4233 | 4249 |
|
|
0 commit comments