Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7ce7e09

Browse files
committed
test(input): ensure Date objects work for min/max in date input types
Tests that - interpolated Date objects work for min/max - Date objects work for ng-min/ng-max
1 parent fa80a61 commit 7ce7e09

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/ng/directive/inputSpec.js

+58
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,16 @@ describe('input', function() {
18571857
it('should parse ISO-based date strings as a valid min date value', function() {
18581858
var inputElm = helper.compileInput('<input name="myControl" type="date" min="{{ min }}" ng-model="value">');
18591859

1860+
$rootScope.value = new Date(2010, 1, 1, 0, 0, 0);
1861+
$rootScope.min = new Date(2014, 10, 10, 0, 0, 0).toISOString();
1862+
$rootScope.$digest();
1863+
1864+
expect($rootScope.form.myControl.$error.min).toBeTruthy();
1865+
});
1866+
1867+
it('should parse interpolated Date objects as a valid min date value', function() {
1868+
var inputElm = helper.compileInput('<input name="myControl" type="date" min="{{ min }}" ng-model="value">');
1869+
18601870
$rootScope.value = new Date(2010, 1, 1, 0, 0, 0);
18611871
$rootScope.min = new Date(2014, 10, 10, 0, 0, 0);
18621872
$rootScope.$digest();
@@ -1896,6 +1906,16 @@ describe('input', function() {
18961906
it('should parse ISO-based date strings as a valid max date value', function() {
18971907
var inputElm = helper.compileInput('<input name="myControl" type="date" max="{{ max }}" ng-model="value">');
18981908

1909+
$rootScope.value = new Date(2020, 1, 1, 0, 0, 0);
1910+
$rootScope.max = new Date(2014, 10, 10, 0, 0, 0).toISOString();
1911+
$rootScope.$digest();
1912+
1913+
expect($rootScope.form.myControl.$error.max).toBeTruthy();
1914+
});
1915+
1916+
it('should parse interpolated Date objects as a valid max date value', function() {
1917+
var inputElm = helper.compileInput('<input name="myControl" type="date" max="{{ max }}" ng-model="value">');
1918+
18991919
$rootScope.value = new Date(2020, 1, 1, 0, 0, 0);
19001920
$rootScope.max = new Date(2014, 10, 10, 0, 0, 0);
19011921
$rootScope.$digest();
@@ -1990,6 +2010,44 @@ describe('input', function() {
19902010
expect(inputElm).toBeValid();
19912011
});
19922012

2013+
2014+
it('should allow Date objects as valid ng-max values', function() {
2015+
$rootScope.max = new Date(2012, 1, 1, 1, 2, 0);
2016+
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" name="alias" ng-max="max" />');
2017+
2018+
helper.changeInputValueTo('2014-01-01T12:34:00');
2019+
expect(inputElm).toBeInvalid();
2020+
2021+
$rootScope.max = new Date(2013, 1, 1, 1, 2, 0);
2022+
$rootScope.$digest();
2023+
2024+
expect(inputElm).toBeInvalid();
2025+
2026+
$rootScope.max = new Date(2014, 1, 1, 1, 2, 0);
2027+
$rootScope.$digest();
2028+
2029+
expect(inputElm).toBeValid();
2030+
});
2031+
2032+
2033+
it('should allow Date objects as valid ng-min values', function() {
2034+
$rootScope.min = new Date(2013, 1, 1, 1, 2, 0);
2035+
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" name="alias" ng-min="min" />');
2036+
2037+
helper.changeInputValueTo('2010-01-01T12:34:00');
2038+
expect(inputElm).toBeInvalid();
2039+
2040+
$rootScope.min = new Date(2014, 1, 1, 1, 2, 0);
2041+
$rootScope.$digest();
2042+
2043+
expect(inputElm).toBeInvalid();
2044+
2045+
$rootScope.min = new Date(2009, 1, 1, 1, 2, 0);
2046+
$rootScope.$digest();
2047+
2048+
expect(inputElm).toBeValid();
2049+
});
2050+
19932051
describe('ISO_DATE_REGEXP', function() {
19942052
var dates = [
19952053
// Validate date

0 commit comments

Comments
 (0)