2
0

DateTimeShortcuts.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* global QUnit, DateTimeShortcuts */
  2. 'use strict';
  3. QUnit.module('admin.DateTimeShortcuts');
  4. QUnit.test('init', function(assert) {
  5. const $ = django.jQuery;
  6. const dateField = $('<input type="text" class="vDateField" value="2015-03-16"><br>');
  7. $('#qunit-fixture').append(dateField);
  8. DateTimeShortcuts.init();
  9. const shortcuts = $('.datetimeshortcuts');
  10. assert.equal(shortcuts.length, 1);
  11. assert.equal(shortcuts.find('a:first').text(), 'Today');
  12. assert.equal(shortcuts.find('a:last .date-icon').length, 1);
  13. // To prevent incorrect timezone warnings on date/time widgets, timezoneOffset
  14. // should be 0 when a timezone offset isn't set in the HTML body attribute.
  15. assert.equal(DateTimeShortcuts.timezoneOffset, 0);
  16. });
  17. QUnit.test('custom time shortcuts', function(assert) {
  18. const $ = django.jQuery;
  19. const timeField = $('<input type="text" name="time_test" class="vTimeField">');
  20. $('#qunit-fixture').append(timeField);
  21. DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
  22. DateTimeShortcuts.init();
  23. assert.equal($('.clockbox').find('a').first().text(), '3 a.m.');
  24. });
  25. QUnit.test('time zone offset warning', function(assert) {
  26. const $ = django.jQuery;
  27. const savedOffset = $('body').attr('data-admin-utc-offset');
  28. const timeField = $('<input type="text" name="time_test" class="vTimeField">');
  29. $('#qunit-fixture').append(timeField);
  30. $('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600);
  31. DateTimeShortcuts.init();
  32. $('body').attr('data-admin-utc-offset', savedOffset);
  33. assert.equal($('.timezonewarning').text(), 'Note: You are 1 hour behind server time.');
  34. });