2016-12-19 18:43:47 +01:00
|
|
|
/* global QUnit, DateTimeShortcuts */
|
2015-08-26 06:24:55 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-12-19 18:43:47 +01:00
|
|
|
QUnit.module('admin.DateTimeShortcuts');
|
2015-04-14 16:55:57 +02:00
|
|
|
|
2016-12-19 18:43:47 +01:00
|
|
|
QUnit.test('init', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const $ = django.jQuery;
|
2015-04-14 16:55:57 +02:00
|
|
|
|
2020-04-21 02:39:15 +02:00
|
|
|
const dateField = $('<input type="text" class="vDateField" value="2015-03-16"><br>');
|
2015-04-14 16:55:57 +02:00
|
|
|
$('#qunit-fixture').append(dateField);
|
|
|
|
|
|
|
|
DateTimeShortcuts.init();
|
|
|
|
|
2020-04-21 02:39:15 +02:00
|
|
|
const shortcuts = $('.datetimeshortcuts');
|
2015-04-14 16:55:57 +02:00
|
|
|
assert.equal(shortcuts.length, 1);
|
|
|
|
assert.equal(shortcuts.find('a:first').text(), 'Today');
|
|
|
|
assert.equal(shortcuts.find('a:last .date-icon').length, 1);
|
2015-12-16 15:11:00 +01:00
|
|
|
|
|
|
|
// To prevent incorrect timezone warnings on date/time widgets, timezoneOffset
|
|
|
|
// should be 0 when a timezone offset isn't set in the HTML body attribute.
|
|
|
|
assert.equal(DateTimeShortcuts.timezoneOffset, 0);
|
2015-04-14 16:55:57 +02:00
|
|
|
});
|
2017-01-05 23:21:40 +01:00
|
|
|
|
|
|
|
QUnit.test('custom time shortcuts', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const $ = django.jQuery;
|
|
|
|
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
|
2017-01-05 23:21:40 +01:00
|
|
|
$('#qunit-fixture').append(timeField);
|
|
|
|
DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
|
|
|
|
DateTimeShortcuts.init();
|
|
|
|
assert.equal($('.clockbox').find('a').first().text(), '3 a.m.');
|
|
|
|
});
|
2018-07-20 17:13:12 +02:00
|
|
|
|
|
|
|
QUnit.test('time zone offset warning', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const $ = django.jQuery;
|
|
|
|
const savedOffset = $('body').attr('data-admin-utc-offset');
|
|
|
|
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
|
2018-07-20 17:13:12 +02:00
|
|
|
$('#qunit-fixture').append(timeField);
|
|
|
|
$('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600);
|
|
|
|
DateTimeShortcuts.init();
|
|
|
|
$('body').attr('data-admin-utc-offset', savedOffset);
|
|
|
|
assert.equal($('.timezonewarning').text(), 'Note: You are 1 hour behind server time.');
|
|
|
|
});
|