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

Commit

Permalink
test(input): ensure Date objects work for min/max in date input types
Browse files Browse the repository at this point in the history
Tests that
- interpolated Date objects work for min/max
- Date objects work for ng-min/ng-max
  • Loading branch information
Narretz committed Jun 28, 2016
1 parent fa80a61 commit 7ce7e09
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,16 @@ describe('input', function() {
it('should parse ISO-based date strings as a valid min date value', function() {
var inputElm = helper.compileInput('<input name="myControl" type="date" min="{{ min }}" ng-model="value">');

$rootScope.value = new Date(2010, 1, 1, 0, 0, 0);
$rootScope.min = new Date(2014, 10, 10, 0, 0, 0).toISOString();
$rootScope.$digest();

expect($rootScope.form.myControl.$error.min).toBeTruthy();
});

it('should parse interpolated Date objects as a valid min date value', function() {
var inputElm = helper.compileInput('<input name="myControl" type="date" min="{{ min }}" ng-model="value">');

$rootScope.value = new Date(2010, 1, 1, 0, 0, 0);
$rootScope.min = new Date(2014, 10, 10, 0, 0, 0);
$rootScope.$digest();
Expand Down Expand Up @@ -1896,6 +1906,16 @@ describe('input', function() {
it('should parse ISO-based date strings as a valid max date value', function() {
var inputElm = helper.compileInput('<input name="myControl" type="date" max="{{ max }}" ng-model="value">');

$rootScope.value = new Date(2020, 1, 1, 0, 0, 0);
$rootScope.max = new Date(2014, 10, 10, 0, 0, 0).toISOString();
$rootScope.$digest();

expect($rootScope.form.myControl.$error.max).toBeTruthy();
});

it('should parse interpolated Date objects as a valid max date value', function() {
var inputElm = helper.compileInput('<input name="myControl" type="date" max="{{ max }}" ng-model="value">');

$rootScope.value = new Date(2020, 1, 1, 0, 0, 0);
$rootScope.max = new Date(2014, 10, 10, 0, 0, 0);
$rootScope.$digest();
Expand Down Expand Up @@ -1990,6 +2010,44 @@ describe('input', function() {
expect(inputElm).toBeValid();
});


it('should allow Date objects as valid ng-max values', function() {
$rootScope.max = new Date(2012, 1, 1, 1, 2, 0);
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" name="alias" ng-max="max" />');

helper.changeInputValueTo('2014-01-01T12:34:00');
expect(inputElm).toBeInvalid();

$rootScope.max = new Date(2013, 1, 1, 1, 2, 0);
$rootScope.$digest();

expect(inputElm).toBeInvalid();

$rootScope.max = new Date(2014, 1, 1, 1, 2, 0);
$rootScope.$digest();

expect(inputElm).toBeValid();
});


it('should allow Date objects as valid ng-min values', function() {
$rootScope.min = new Date(2013, 1, 1, 1, 2, 0);
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" name="alias" ng-min="min" />');

helper.changeInputValueTo('2010-01-01T12:34:00');
expect(inputElm).toBeInvalid();

$rootScope.min = new Date(2014, 1, 1, 1, 2, 0);
$rootScope.$digest();

expect(inputElm).toBeInvalid();

$rootScope.min = new Date(2009, 1, 1, 1, 2, 0);
$rootScope.$digest();

expect(inputElm).toBeValid();
});

describe('ISO_DATE_REGEXP', function() {
var dates = [
// Validate date
Expand Down

0 comments on commit 7ce7e09

Please sign in to comment.