1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00
django/js_tests/admin/DateTimeShortcuts.test.js
Jon Dufresne 5d37cc703b Fixed #31493 -- Replaced var with const and let keywords in JavaScript.
The eslint configuration and the admin script compress.py have been
updated for ES6.

The unused fallback of globals.django in jquery.init.js was removed. It
is always included before jsi18n-mocks.test.js and it always sets the
global value.
2020-04-29 10:22:41 +02:00

44 lines
1.7 KiB
JavaScript

/* global QUnit, DateTimeShortcuts */
/* eslint strict: 0 */
'use strict';
QUnit.module('admin.DateTimeShortcuts');
QUnit.test('init', function(assert) {
const $ = django.jQuery;
const dateField = $('<input type="text" class="vDateField" value="2015-03-16"><br>');
$('#qunit-fixture').append(dateField);
DateTimeShortcuts.init();
const shortcuts = $('.datetimeshortcuts');
assert.equal(shortcuts.length, 1);
assert.equal(shortcuts.find('a:first').text(), 'Today');
assert.equal(shortcuts.find('a:last .date-icon').length, 1);
// 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);
});
QUnit.test('custom time shortcuts', function(assert) {
const $ = django.jQuery;
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
$('#qunit-fixture').append(timeField);
DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
DateTimeShortcuts.init();
assert.equal($('.clockbox').find('a').first().text(), '3 a.m.');
});
QUnit.test('time zone offset warning', function(assert) {
const $ = django.jQuery;
const savedOffset = $('body').attr('data-admin-utc-offset');
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
$('#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.');
});