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

Commit 6a52c4f

Browse files
Ed Clementgkalpak
Ed Clement
andcommitted
test(input): fix tests on Firefox v93+
Since version 93, Firefox started more closely following the spec on formatting `datetime-local` input values by removing trailing zeros from the string representation of the value. This causes some of our tests to fail ([example failure][1]). For example, a value is reported by Firefox as `2009-01-06T16:25` while the tests expect `2009-01-06T16:25:00.000`. I.e. Firefox started leaving out seconds/milliseconds if they are zero. According to [MDN][2], this is the correct behavior according to the spec. Indeed the spec says that [if the value of the element is a valid local date and time string, then it must be set to a **valid normalized local date and time string**][3], where **valid normalized local date and time string** is [defined as consisting of][4]: > - A valid date string representing the date. > - A U+0054 LATIN CAPITAL LETTER T character (T). > - A valid time string representing the time, expressed as the > **shortest possible string** for the given time (e.g. **omitting the > seconds component** entirely if the given time is zero seconds past > the minute). This commit fixes the relevant tests by explicitly specifying non-zero values for seconds and milliseconds. [1]: https://circleci.com/gh/angular/angular.js/3527 [2]: https://developer.mozilla.org/en-US/docs/Web/HTML/Date_and_time_formats #local_date_and_time_strings [3]: https://html.spec.whatwg.org/multipage/input.html #local-date-and-time-state-(type=datetime-local) [4]: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html #concept-datetime-local Co-authored-by: George Kalpakas <kalpakas.g@gmail.com>
1 parent ed30c4d commit 6a52c4f

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

test/ng/directive/inputSpec.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1271,10 +1271,10 @@ describe('input', function() {
12711271
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="breakMe"/>');
12721272

12731273
$rootScope.$apply(function() {
1274-
$rootScope.breakMe = new Date(2009, 0, 6, 16, 25, 0);
1274+
$rootScope.breakMe = new Date(2009, 0, 6, 16, 25, 1, 337);
12751275
});
12761276

1277-
expect(inputElm.val()).toBe('2009-01-06T16:25:00.000');
1277+
expect(inputElm.val()).toBe('2009-01-06T16:25:01.337');
12781278

12791279
//set to text for browsers with datetime-local validation.
12801280
inputElm[0].setAttribute('type', 'text');
@@ -1324,32 +1324,32 @@ describe('input', function() {
13241324
it('should use UTC if specified in the options', function() {
13251325
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />');
13261326

1327-
helper.changeInputValueTo('2000-01-01T01:02');
1328-
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 0));
1327+
helper.changeInputValueTo('2000-01-01T01:02:03.456');
1328+
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 3, 456));
13291329

13301330
$rootScope.$apply(function() {
1331-
$rootScope.value = new Date(Date.UTC(2001, 0, 1, 1, 2, 0));
1331+
$rootScope.value = new Date(Date.UTC(2001, 0, 1, 1, 2, 3, 456));
13321332
});
1333-
expect(inputElm.val()).toBe('2001-01-01T01:02:00.000');
1333+
expect(inputElm.val()).toBe('2001-01-01T01:02:03.456');
13341334
});
13351335

13361336

13371337
it('should be possible to override the timezone', function() {
13381338
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />');
13391339

1340-
helper.changeInputValueTo('2000-01-01T01:02');
1341-
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 0));
1340+
helper.changeInputValueTo('2000-01-01T01:02:03.456');
1341+
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 3, 456));
13421342

13431343
inputElm.controller('ngModel').$overrideModelOptions({timezone: '+0500'});
13441344
$rootScope.$apply(function() {
1345-
$rootScope.value = new Date(Date.UTC(2001, 0, 1, 1, 2, 0));
1345+
$rootScope.value = new Date(Date.UTC(2001, 0, 1, 1, 2, 3, 456));
13461346
});
1347-
expect(inputElm.val()).toBe('2001-01-01T06:02:00.000');
1347+
expect(inputElm.val()).toBe('2001-01-01T06:02:03.456');
13481348

13491349
inputElm.controller('ngModel').$overrideModelOptions({timezone: 'UTC'});
13501350

1351-
helper.changeInputValueTo('2000-01-01T01:02');
1352-
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 0));
1351+
helper.changeInputValueTo('2000-01-01T01:02:03.456');
1352+
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 3, 456));
13531353
});
13541354

13551355

@@ -1360,13 +1360,13 @@ describe('input', function() {
13601360
var inputElm = helper.compileInput(
13611361
'<input type="datetime-local" ng-model="value" ng-model-options="' + ngModelOptions + '" />');
13621362

1363-
helper.changeInputValueTo('2000-01-01T06:02');
1364-
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 0));
1363+
helper.changeInputValueTo('2000-01-01T06:02:03.456');
1364+
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 1, 2, 3, 456));
13651365

13661366
$rootScope.$apply(function() {
1367-
$rootScope.value = new Date(Date.UTC(2001, 0, 1, 1, 2, 0));
1367+
$rootScope.value = new Date(Date.UTC(2001, 0, 1, 1, 2, 3, 456));
13681368
});
1369-
expect(inputElm.val()).toBe('2001-01-01T06:02:00.000');
1369+
expect(inputElm.val()).toBe('2001-01-01T06:02:03.456');
13701370
}
13711371
);
13721372

@@ -1401,13 +1401,13 @@ describe('input', function() {
14011401
it('should allow to specify the seconds', function() {
14021402
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value"" />');
14031403

1404-
helper.changeInputValueTo('2000-01-01T01:02:03');
1405-
expect(+$rootScope.value).toBe(+new Date(2000, 0, 1, 1, 2, 3));
1404+
helper.changeInputValueTo('2000-01-01T01:02:03.456');
1405+
expect(+$rootScope.value).toBe(+new Date(2000, 0, 1, 1, 2, 3, 456));
14061406

14071407
$rootScope.$apply(function() {
1408-
$rootScope.value = new Date(2001, 0, 1, 1, 2, 3);
1408+
$rootScope.value = new Date(2001, 0, 1, 1, 2, 3, 456);
14091409
});
1410-
expect(inputElm.val()).toBe('2001-01-01T01:02:03.000');
1410+
expect(inputElm.val()).toBe('2001-01-01T01:02:03.456');
14111411
});
14121412

14131413

@@ -1425,13 +1425,13 @@ describe('input', function() {
14251425
it('should allow four or more digits in year', function() {
14261426
var inputElm = helper.compileInput('<input type="datetime-local" ng-model="value" />');
14271427

1428-
helper.changeInputValueTo('10123-01-01T01:02');
1429-
expect(+$rootScope.value).toBe(+new Date(10123, 0, 1, 1, 2, 0));
1428+
helper.changeInputValueTo('10123-01-01T01:02:03.456');
1429+
expect(+$rootScope.value).toBe(+new Date(10123, 0, 1, 1, 2, 3, 456));
14301430

14311431
$rootScope.$apply(function() {
1432-
$rootScope.value = new Date(20456, 1, 1, 1, 2, 0);
1432+
$rootScope.value = new Date(20456, 1, 1, 1, 2, 3, 456);
14331433
});
1434-
expect(inputElm.val()).toBe('20456-02-01T01:02:00.000');
1434+
expect(inputElm.val()).toBe('20456-02-01T01:02:03.456');
14351435
}
14361436
);
14371437
}

0 commit comments

Comments
 (0)