diff options
| author | Tom Carrick <tom@carrick.eu> | 2026-04-19 11:54:17 +0300 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-04-19 13:45:56 +0300 |
| commit | fc0a0ebd4fe573299a5f978e77fa3bca8424f661 (patch) | |
| tree | 02df30c20820ddc4a6764969e8dbd9c3a22f437d /js_tests | |
| parent | 47789e3a2b471995ed753c87ce69ffbaa59c0601 (diff) | |
Formatted JavaScript files.
Diffstat (limited to 'js_tests')
| -rw-r--r-- | js_tests/admin/DateTimeShortcuts.test.js | 84 | ||||
| -rw-r--r-- | js_tests/admin/RelatedObjectLookups.test.js | 141 | ||||
| -rw-r--r-- | js_tests/admin/SelectBox.test.js | 213 | ||||
| -rw-r--r-- | js_tests/admin/SelectFilter2.test.js | 311 | ||||
| -rw-r--r-- | js_tests/admin/URLify.test.js | 28 | ||||
| -rw-r--r-- | js_tests/admin/actions.test.js | 22 | ||||
| -rw-r--r-- | js_tests/admin/core.test.js | 165 | ||||
| -rw-r--r-- | js_tests/admin/inlines.test.js | 251 | ||||
| -rw-r--r-- | js_tests/admin/jsi18n-mocks.test.js | 95 | ||||
| -rw-r--r-- | js_tests/admin/navigation.test.js | 26 | ||||
| -rw-r--r-- | js_tests/gis/mapwidget.test.js | 266 |
11 files changed, 940 insertions, 662 deletions
diff --git a/js_tests/admin/DateTimeShortcuts.test.js b/js_tests/admin/DateTimeShortcuts.test.js index 6cb534610c..5c850ce7d2 100644 --- a/js_tests/admin/DateTimeShortcuts.test.js +++ b/js_tests/admin/DateTimeShortcuts.test.js @@ -1,59 +1,81 @@ /* global QUnit, DateTimeShortcuts */ -'use strict'; +"use strict"; -QUnit.module('admin.DateTimeShortcuts'); +QUnit.module("admin.DateTimeShortcuts"); -QUnit.test('init', function(assert) { +QUnit.test("init", function (assert) { const $ = django.jQuery; - const dateField = $('<input type="text" class="vDateField" value="2015-03-16"><br>'); - $('#qunit-fixture').append(dateField); + const dateField = $( + '<input type="text" class="vDateField" value="2015-03-16"><br>', + ); + $("#qunit-fixture").append(dateField); DateTimeShortcuts.init(); - const shortcuts = $('.datetimeshortcuts'); + 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); + 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) { +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]]; + 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.'); + assert.equal($(".clockbox").find("a").first().text(), "3 a.m."); }); -QUnit.test('time zone offset warning - single field', function(assert) { +QUnit.test("time zone offset warning - single field", function (assert) { const $ = django.jQuery; - const savedOffset = $('body').attr('data-admin-utc-offset'); + const savedOffset = $("body").attr("data-admin-utc-offset"); // Single date or time field. - const timeField = $('<input id="id_updated_at" type="text" name="updated_at" class="vTimeField">'); - $('#qunit-fixture').append(timeField); - $('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600); + const timeField = $( + '<input id="id_updated_at" type="text" name="updated_at" 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.'); - assert.equal($('.timezonewarning').attr("id"), "id_updated_at_timezone_warning_helptext"); + $("body").attr("data-admin-utc-offset", savedOffset); + assert.equal( + $(".timezonewarning").text(), + "Note: You are 1 hour behind server time.", + ); + assert.equal( + $(".timezonewarning").attr("id"), + "id_updated_at_timezone_warning_helptext", + ); }); -QUnit.test('time zone offset warning - date and time field', function(assert) { +QUnit.test("time zone offset warning - date and time field", function (assert) { const $ = django.jQuery; - const savedOffset = $('body').attr('data-admin-utc-offset'); + const savedOffset = $("body").attr("data-admin-utc-offset"); // DateTimeField with fieldset containing date and time inputs. - const dateTimeField = '<p class="datetime">' + - '<input id="id_updated_at_0" type="text" name="updated_at_0" class="vDateField">' + - '<input id="id_updated_at_1" type="text" name="updated_at_1" class="vTimeField">' + - '</p>'; - $('#qunit-fixture').append($(dateTimeField)); - $('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600); + const dateTimeField = + '<p class="datetime">' + + '<input id="id_updated_at_0" type="text" name="updated_at_0" class="vDateField">' + + '<input id="id_updated_at_1" type="text" name="updated_at_1" class="vTimeField">' + + "</p>"; + $("#qunit-fixture").append($(dateTimeField)); + $("body").attr( + "data-admin-utc-offset", + new Date().getTimezoneOffset() * -60 + 3600, + ); DateTimeShortcuts.init(); - $('body').attr('data-admin-utc-offset', savedOffset); - assert.equal($('.timezonewarning').attr("id"), "id_updated_at_timezone_warning_helptext"); + $("body").attr("data-admin-utc-offset", savedOffset); + assert.equal( + $(".timezonewarning").attr("id"), + "id_updated_at_timezone_warning_helptext", + ); }); diff --git a/js_tests/admin/RelatedObjectLookups.test.js b/js_tests/admin/RelatedObjectLookups.test.js index 0d71d88f2a..b7df8f181f 100644 --- a/js_tests/admin/RelatedObjectLookups.test.js +++ b/js_tests/admin/RelatedObjectLookups.test.js @@ -1,77 +1,98 @@ /* global QUnit, RelatedObjectLookups */ -'use strict'; +"use strict"; -QUnit.module('admin.RelatedObjectLookups', { - beforeEach: function() { +QUnit.module("admin.RelatedObjectLookups", { + beforeEach: function () { const $ = django.jQuery; - $('#qunit-fixture').append(` + $("#qunit-fixture").append(` <input type="text" id="test_id" name="test" /> <input type="text" id="many_test_id" name="many_test" class="vManyToManyRawIdAdminField" /> `); - } + }, }); -QUnit.test('dismissRelatedLookupPopup closes popup window', function(assert) { - const testId = 'test_id'; +QUnit.test("dismissRelatedLookupPopup closes popup window", function (assert) { + const testId = "test_id"; let windowClosed = false; const mockWin = { name: testId, - close: function() { + close: function () { windowClosed = true; - } + }, }; - window.dismissRelatedLookupPopup(mockWin, '123'); - assert.true(windowClosed, 'Popup window should be closed'); + window.dismissRelatedLookupPopup(mockWin, "123"); + assert.true(windowClosed, "Popup window should be closed"); }); -QUnit.test('dismissRelatedLookupPopup removes window from relatedWindows array', function(assert) { - const testId = 'test_id'; - const mockWin = { - name: testId, - close: function() {} - }; - window.relatedWindows.push(mockWin); - assert.equal(window.relatedWindows.indexOf(mockWin), 0, 'Window should be in relatedWindows array'); - window.dismissRelatedLookupPopup(mockWin, '123'); - assert.equal(window.relatedWindows.indexOf(mockWin), -1, 'Window should be removed from relatedWindows array'); -}); +QUnit.test( + "dismissRelatedLookupPopup removes window from relatedWindows array", + function (assert) { + const testId = "test_id"; + const mockWin = { + name: testId, + close: function () {}, + }; + window.relatedWindows.push(mockWin); + assert.equal( + window.relatedWindows.indexOf(mockWin), + 0, + "Window should be in relatedWindows array", + ); + window.dismissRelatedLookupPopup(mockWin, "123"); + assert.equal( + window.relatedWindows.indexOf(mockWin), + -1, + "Window should be removed from relatedWindows array", + ); + }, +); -QUnit.test('dismissRelatedLookupPopup triggers change event for single value field', function(assert) { - assert.timeout(1000); - const done = assert.async(); - const $ = django.jQuery; - const testId = 'test_id'; - const newValue = '123'; - const mockWin = { - name: testId, - close: function() {} - }; - let changeTriggered = false; - $('#test_id').on('change', function() { - changeTriggered = true; - assert.equal(this.value, newValue, 'Value should be updated'); - done(); - }); - window.dismissRelatedLookupPopup(mockWin, newValue); - assert.true(changeTriggered, 'Change event should be triggered'); -}); +QUnit.test( + "dismissRelatedLookupPopup triggers change event for single value field", + function (assert) { + assert.timeout(1000); + const done = assert.async(); + const $ = django.jQuery; + const testId = "test_id"; + const newValue = "123"; + const mockWin = { + name: testId, + close: function () {}, + }; + let changeTriggered = false; + $("#test_id").on("change", function () { + changeTriggered = true; + assert.equal(this.value, newValue, "Value should be updated"); + done(); + }); + window.dismissRelatedLookupPopup(mockWin, newValue); + assert.true(changeTriggered, "Change event should be triggered"); + }, +); -QUnit.test('dismissRelatedLookupPopup triggers change event for many-to-many field', function(assert) { - assert.timeout(1000); - const $ = django.jQuery; - const testId = 'many_test_id'; - const existingValue = '1,2'; - const newValue = '3'; - $('#many_test_id').val(existingValue); - const mockWin = { - name: testId, - close: function() {} - }; - let changeTriggered = false; - $('#many_test_id').on('change', function() { - changeTriggered = true; - assert.equal(this.value, existingValue + ',' + newValue, 'Value should be appended for many-to-many fields'); - }); - window.dismissRelatedLookupPopup(mockWin, newValue); - assert.true(changeTriggered, 'Change event should be triggered'); -}); +QUnit.test( + "dismissRelatedLookupPopup triggers change event for many-to-many field", + function (assert) { + assert.timeout(1000); + const $ = django.jQuery; + const testId = "many_test_id"; + const existingValue = "1,2"; + const newValue = "3"; + $("#many_test_id").val(existingValue); + const mockWin = { + name: testId, + close: function () {}, + }; + let changeTriggered = false; + $("#many_test_id").on("change", function () { + changeTriggered = true; + assert.equal( + this.value, + existingValue + "," + newValue, + "Value should be appended for many-to-many fields", + ); + }); + window.dismissRelatedLookupPopup(mockWin, newValue); + assert.true(changeTriggered, "Change event should be triggered"); + }, +); diff --git a/js_tests/admin/SelectBox.test.js b/js_tests/admin/SelectBox.test.js index 4915ba6b9b..e32fa4c353 100644 --- a/js_tests/admin/SelectBox.test.js +++ b/js_tests/admin/SelectBox.test.js @@ -1,207 +1,210 @@ /* global QUnit, SelectBox */ -'use strict'; +"use strict"; -QUnit.module('admin.SelectBox'); +QUnit.module("admin.SelectBox"); -QUnit.test('init: no options', function(assert) { +QUnit.test("init: no options", function (assert) { const $ = django.jQuery; - $('<select id="id"></select>').appendTo('#qunit-fixture'); - SelectBox.init('id'); + $('<select id="id"></select>').appendTo("#qunit-fixture"); + SelectBox.init("id"); assert.equal(SelectBox.cache.id.length, 0); }); -QUnit.test('filter', function(assert) { +QUnit.test("filter", function (assert) { const $ = django.jQuery; - $('<select id="id"></select>').appendTo('#qunit-fixture'); - $('<option value="0">A</option>').appendTo('#id'); - $('<option value="1">B</option>').appendTo('#id'); - SelectBox.init('id'); - assert.equal($('#id option').length, 2); - SelectBox.filter('id', "A"); - assert.equal($('#id option').length, 1); - assert.equal($('#id option').text(), "A"); + $('<select id="id"></select>').appendTo("#qunit-fixture"); + $('<option value="0">A</option>').appendTo("#id"); + $('<option value="1">B</option>').appendTo("#id"); + SelectBox.init("id"); + assert.equal($("#id option").length, 2); + SelectBox.filter("id", "A"); + assert.equal($("#id option").length, 1); + assert.equal($("#id option").text(), "A"); }); -QUnit.test('preserve scroll position', function(assert) { +QUnit.test("preserve scroll position", function (assert) { const $ = django.jQuery; const optionsCount = 100; - $('<select id="from_id" multiple></select>').appendTo('#qunit-fixture'); - $('<select id="to_id" multiple></select>').appendTo('#qunit-fixture'); - const fromSelectBox = document.getElementById('from_id'); - const toSelectBox = document.getElementById('to_id'); + $('<select id="from_id" multiple></select>').appendTo("#qunit-fixture"); + $('<select id="to_id" multiple></select>').appendTo("#qunit-fixture"); + const fromSelectBox = document.getElementById("from_id"); + const toSelectBox = document.getElementById("to_id"); for (let i = 0; i < optionsCount; i++) { fromSelectBox.appendChild(new Option()); } - SelectBox.init('from_id'); - SelectBox.init('to_id'); + SelectBox.init("from_id"); + SelectBox.init("to_id"); const selectedOptions = [97, 98, 99]; for (const index of selectedOptions) { fromSelectBox.options[index].selected = true; fromSelectBox.options[index].scrollIntoView(); } assert.equal(fromSelectBox.options.length, optionsCount); - SelectBox.move('from_id', 'to_id'); - assert.equal(fromSelectBox.options.length, optionsCount - selectedOptions.length); + SelectBox.move("from_id", "to_id"); + assert.equal( + fromSelectBox.options.length, + optionsCount - selectedOptions.length, + ); assert.equal(toSelectBox.options.length, selectedOptions.length); assert.notEqual(fromSelectBox.scrollTop, 0); }); -QUnit.test('retain optgroups', function(assert) { +QUnit.test("retain optgroups", function (assert) { const $ = django.jQuery; - $('<select id="id"></select>').appendTo('#qunit-fixture'); - const grp = $('<optgroup label="group one">').appendTo('#id'); + $('<select id="id"></select>').appendTo("#qunit-fixture"); + const grp = $('<optgroup label="group one">').appendTo("#id"); $('<option value="0">A</option>').appendTo(grp); - $('</optgroup>').appendTo('#id'); - $('<option value="1">B</option>').appendTo('#id'); - SelectBox.init('id'); - SelectBox.redisplay('id'); - assert.equal($('#id option').length, 2); - assert.equal($('#id optgroup').length, 1); + $("</optgroup>").appendTo("#id"); + $('<option value="1">B</option>').appendTo("#id"); + SelectBox.init("id"); + SelectBox.redisplay("id"); + assert.equal($("#id option").length, 2); + assert.equal($("#id optgroup").length, 1); }); -QUnit.test('sort optgroups', function(assert) { +QUnit.test("sort optgroups", function (assert) { const $ = django.jQuery; - $('<select id="id"></select>').appendTo('#qunit-fixture'); + $('<select id="id"></select>').appendTo("#qunit-fixture"); // Add optgroups in non-alphabetical order - const grp2 = $('<optgroup label="Group B">').appendTo('#id'); + const grp2 = $('<optgroup label="Group B">').appendTo("#id"); $('<option value="3">Item 3</option>').appendTo(grp2); $('<option value="4">Item 4</option>').appendTo(grp2); - const grp1 = $('<optgroup label="Group A">').appendTo('#id'); + const grp1 = $('<optgroup label="Group A">').appendTo("#id"); $('<option value="1">Item 1</option>').appendTo(grp1); $('<option value="2">Item 2</option>').appendTo(grp1); - SelectBox.init('id'); + SelectBox.init("id"); // Verify cache is sorted by group then by item assert.equal(SelectBox.cache.id.length, 4); - assert.equal(SelectBox.cache.id[0].group, 'Group A'); - assert.equal(SelectBox.cache.id[0].text, 'Item 1'); - assert.equal(SelectBox.cache.id[1].group, 'Group A'); - assert.equal(SelectBox.cache.id[1].text, 'Item 2'); - assert.equal(SelectBox.cache.id[2].group, 'Group B'); - assert.equal(SelectBox.cache.id[2].text, 'Item 3'); - assert.equal(SelectBox.cache.id[3].group, 'Group B'); - assert.equal(SelectBox.cache.id[3].text, 'Item 4'); + assert.equal(SelectBox.cache.id[0].group, "Group A"); + assert.equal(SelectBox.cache.id[0].text, "Item 1"); + assert.equal(SelectBox.cache.id[1].group, "Group A"); + assert.equal(SelectBox.cache.id[1].text, "Item 2"); + assert.equal(SelectBox.cache.id[2].group, "Group B"); + assert.equal(SelectBox.cache.id[2].text, "Item 3"); + assert.equal(SelectBox.cache.id[3].group, "Group B"); + assert.equal(SelectBox.cache.id[3].text, "Item 4"); }); -QUnit.test('do not sort when no optgroups', function(assert) { +QUnit.test("do not sort when no optgroups", function (assert) { const $ = django.jQuery; - $('<select id="id"></select>').appendTo('#qunit-fixture'); + $('<select id="id"></select>').appendTo("#qunit-fixture"); // Add options in non-alphabetical order - $('<option value="3">Zebra</option>').appendTo('#id'); - $('<option value="1">Apple</option>').appendTo('#id'); - $('<option value="2">Banana</option>').appendTo('#id'); + $('<option value="3">Zebra</option>').appendTo("#id"); + $('<option value="1">Apple</option>').appendTo("#id"); + $('<option value="2">Banana</option>').appendTo("#id"); - SelectBox.init('id'); + SelectBox.init("id"); // Verify cache preserves original order (not sorted) assert.equal(SelectBox.cache.id.length, 3); - assert.equal(SelectBox.cache.id[0].text, 'Zebra'); - assert.equal(SelectBox.cache.id[1].text, 'Apple'); - assert.equal(SelectBox.cache.id[2].text, 'Banana'); + assert.equal(SelectBox.cache.id[0].text, "Zebra"); + assert.equal(SelectBox.cache.id[1].text, "Apple"); + assert.equal(SelectBox.cache.id[2].text, "Banana"); }); -QUnit.test('move with optgroups sorts', function(assert) { +QUnit.test("move with optgroups sorts", function (assert) { const $ = django.jQuery; - $('<select id="from_id"></select>').appendTo('#qunit-fixture'); - $('<select id="to_id"></select>').appendTo('#qunit-fixture'); + $('<select id="from_id"></select>').appendTo("#qunit-fixture"); + $('<select id="to_id"></select>').appendTo("#qunit-fixture"); // Add options with optgroups to from_id in non-alphabetical order - const grp2 = $('<optgroup label="Group B">').appendTo('#from_id'); + const grp2 = $('<optgroup label="Group B">').appendTo("#from_id"); $('<option value="2">Item 2</option>').appendTo(grp2); - const grp1 = $('<optgroup label="Group A">').appendTo('#from_id'); + const grp1 = $('<optgroup label="Group A">').appendTo("#from_id"); $('<option value="1">Item 1</option>').appendTo(grp1); - SelectBox.init('from_id'); - SelectBox.init('to_id'); + SelectBox.init("from_id"); + SelectBox.init("to_id"); // Select and move item - document.getElementById('from_id').options[0].selected = true; - SelectBox.move('from_id', 'to_id'); + document.getElementById("from_id").options[0].selected = true; + SelectBox.move("from_id", "to_id"); // Verify to_id cache is sorted (even though we only added one item) assert.equal(SelectBox.cache.to_id.length, 1); - assert.equal(SelectBox.cache.to_id[0].group, 'Group B'); - assert.equal(SelectBox.cache.to_id[0].text, 'Item 2'); + assert.equal(SelectBox.cache.to_id[0].group, "Group B"); + assert.equal(SelectBox.cache.to_id[0].text, "Item 2"); }); -QUnit.test('move without optgroups does not sort', function(assert) { +QUnit.test("move without optgroups does not sort", function (assert) { const $ = django.jQuery; - $('<select id="from_id"></select>').appendTo('#qunit-fixture'); - $('<select id="to_id"></select>').appendTo('#qunit-fixture'); + $('<select id="from_id"></select>').appendTo("#qunit-fixture"); + $('<select id="to_id"></select>').appendTo("#qunit-fixture"); // Add options without optgroups in non-alphabetical order - $('<option value="3">Zebra</option>').appendTo('#from_id'); - $('<option value="1">Apple</option>').appendTo('#from_id'); + $('<option value="3">Zebra</option>').appendTo("#from_id"); + $('<option value="1">Apple</option>').appendTo("#from_id"); - SelectBox.init('from_id'); - SelectBox.init('to_id'); + SelectBox.init("from_id"); + SelectBox.init("to_id"); // Select and move first item (Zebra) - document.getElementById('from_id').options[0].selected = true; - SelectBox.move('from_id', 'to_id'); + document.getElementById("from_id").options[0].selected = true; + SelectBox.move("from_id", "to_id"); // Verify to_id cache preserves order (not sorted) assert.equal(SelectBox.cache.to_id.length, 1); - assert.equal(SelectBox.cache.to_id[0].text, 'Zebra'); + assert.equal(SelectBox.cache.to_id[0].text, "Zebra"); // Move second item (Apple) - document.getElementById('from_id').options[0].selected = true; - SelectBox.move('from_id', 'to_id'); + document.getElementById("from_id").options[0].selected = true; + SelectBox.move("from_id", "to_id"); // Verify items are in order they were added, not alphabetical assert.equal(SelectBox.cache.to_id.length, 2); - assert.equal(SelectBox.cache.to_id[0].text, 'Zebra'); - assert.equal(SelectBox.cache.to_id[1].text, 'Apple'); + assert.equal(SelectBox.cache.to_id[0].text, "Zebra"); + assert.equal(SelectBox.cache.to_id[1].text, "Apple"); }); -QUnit.test('move_all with optgroups sorts', function(assert) { +QUnit.test("move_all with optgroups sorts", function (assert) { const $ = django.jQuery; - $('<select id="from_id"></select>').appendTo('#qunit-fixture'); - $('<select id="to_id"></select>').appendTo('#qunit-fixture'); + $('<select id="from_id"></select>').appendTo("#qunit-fixture"); + $('<select id="to_id"></select>').appendTo("#qunit-fixture"); // Add options with optgroups in non-alphabetical order - const grp2 = $('<optgroup label="Group B">').appendTo('#from_id'); + const grp2 = $('<optgroup label="Group B">').appendTo("#from_id"); $('<option value="3">Zebra</option>').appendTo(grp2); - const grp1 = $('<optgroup label="Group A">').appendTo('#from_id'); + const grp1 = $('<optgroup label="Group A">').appendTo("#from_id"); $('<option value="1">Apple</option>').appendTo(grp1); $('<option value="2">Banana</option>').appendTo(grp1); - SelectBox.init('from_id'); - SelectBox.init('to_id'); + SelectBox.init("from_id"); + SelectBox.init("to_id"); // Move all items - SelectBox.move_all('from_id', 'to_id'); + SelectBox.move_all("from_id", "to_id"); // Verify to_id cache is sorted by group assert.equal(SelectBox.cache.to_id.length, 3); - assert.equal(SelectBox.cache.to_id[0].group, 'Group A'); - assert.equal(SelectBox.cache.to_id[0].text, 'Apple'); - assert.equal(SelectBox.cache.to_id[1].group, 'Group A'); - assert.equal(SelectBox.cache.to_id[1].text, 'Banana'); - assert.equal(SelectBox.cache.to_id[2].group, 'Group B'); - assert.equal(SelectBox.cache.to_id[2].text, 'Zebra'); + assert.equal(SelectBox.cache.to_id[0].group, "Group A"); + assert.equal(SelectBox.cache.to_id[0].text, "Apple"); + assert.equal(SelectBox.cache.to_id[1].group, "Group A"); + assert.equal(SelectBox.cache.to_id[1].text, "Banana"); + assert.equal(SelectBox.cache.to_id[2].group, "Group B"); + assert.equal(SelectBox.cache.to_id[2].text, "Zebra"); }); -QUnit.test('move_all without optgroups does not sort', function(assert) { +QUnit.test("move_all without optgroups does not sort", function (assert) { const $ = django.jQuery; - $('<select id="from_id"></select>').appendTo('#qunit-fixture'); - $('<select id="to_id"></select>').appendTo('#qunit-fixture'); + $('<select id="from_id"></select>').appendTo("#qunit-fixture"); + $('<select id="to_id"></select>').appendTo("#qunit-fixture"); // Add options without optgroups in non-alphabetical order - $('<option value="3">Zebra</option>').appendTo('#from_id'); - $('<option value="1">Apple</option>').appendTo('#from_id'); - $('<option value="2">Banana</option>').appendTo('#from_id'); + $('<option value="3">Zebra</option>').appendTo("#from_id"); + $('<option value="1">Apple</option>').appendTo("#from_id"); + $('<option value="2">Banana</option>').appendTo("#from_id"); - SelectBox.init('from_id'); - SelectBox.init('to_id'); + SelectBox.init("from_id"); + SelectBox.init("to_id"); // Move all items - SelectBox.move_all('from_id', 'to_id'); + SelectBox.move_all("from_id", "to_id"); // Verify to_id cache preserves original order (not sorted) assert.equal(SelectBox.cache.to_id.length, 3); - assert.equal(SelectBox.cache.to_id[0].text, 'Zebra'); - assert.equal(SelectBox.cache.to_id[1].text, 'Apple'); - assert.equal(SelectBox.cache.to_id[2].text, 'Banana'); + assert.equal(SelectBox.cache.to_id[0].text, "Zebra"); + assert.equal(SelectBox.cache.to_id[1].text, "Apple"); + assert.equal(SelectBox.cache.to_id[2].text, "Banana"); }); diff --git a/js_tests/admin/SelectFilter2.test.js b/js_tests/admin/SelectFilter2.test.js index 9a020d2c53..0d0283f9b6 100644 --- a/js_tests/admin/SelectFilter2.test.js +++ b/js_tests/admin/SelectFilter2.test.js @@ -1,174 +1,241 @@ /* global QUnit, SelectFilter */ -'use strict'; +"use strict"; -QUnit.module('admin.SelectFilter2'); +QUnit.module("admin.SelectFilter2"); -QUnit.test('init', function(assert) { +QUnit.test("init", function (assert) { const $ = django.jQuery; - $('<form id="test"></form>').appendTo('#qunit-fixture'); - $('<label for="id_id">Test</label>').appendTo('#test'); - $('<div class="helptext">This is helpful.</div>').appendTo('#test'); - $('<select id="id"><option value="0">A</option></select>').appendTo('#test'); - SelectFilter.init('id', 'things', 0); + $('<form id="test"></form>').appendTo("#qunit-fixture"); + $('<label for="id_id">Test</label>').appendTo("#test"); + $('<div class="helptext">This is helpful.</div>').appendTo("#test"); + $('<select id="id"><option value="0">A</option></select>').appendTo( + "#test", + ); + SelectFilter.init("id", "things", 0); assert.deepEqual( - Array.from($('#test')[0].children).map(child => child.tagName), - ["LABEL", "DIV", "DIV"] + Array.from($("#test")[0].children).map((child) => child.tagName), + ["LABEL", "DIV", "DIV"], + ); + assert.equal( + $(".helptext")[0].nextSibling.getAttribute("class"), + "selector", + ); + assert.equal( + $(".selector-available label").text().trim(), + "Available things", + ); + assert.equal($(".selector-available label").attr("id"), "id_from_label"); + assert.equal($(".selector-chosen label").text().trim(), "Chosen things"); + assert.equal($(".selector-chosen label").attr("id"), "id_to_label"); + assert.equal($(".selector-chosen select")[0].getAttribute("multiple"), ""); + assert.equal($(".selector-chooseall").text(), "Choose all things"); + assert.equal($(".selector-chooseall").prop("tagName"), "BUTTON"); + assert.equal($(".selector-add").text(), "Choose selected things"); + assert.equal($(".selector-add").prop("tagName"), "BUTTON"); + assert.equal($(".selector-remove").text(), "Remove selected things"); + assert.equal($(".selector-remove").prop("tagName"), "BUTTON"); + assert.equal($(".selector-clearall").text(), "Remove all things"); + assert.equal($(".selector-clearall").prop("tagName"), "BUTTON"); + assert.equal( + $(".selector-available .filtered").attr("aria-labelledby"), + "id_from_label", + ); + assert.equal( + $(".selector-available .filtered").attr("aria-describedby"), + "id_helptext id_choose_helptext", + ); + assert.equal( + $(".selector-available .selector-available-title label").text(), + "Available things ", + ); + assert.equal( + $(".selector-available .selector-available-title .helptext").text(), + 'Choose things by selecting them and then select the "Choose" arrow button.', + ); + assert.equal( + $(".selector-chosen .filtered").attr("aria-labelledby"), + "id_to_label", + ); + assert.equal( + $(".selector-chosen .filtered").attr("aria-describedby"), + "id_helptext id_remove_helptext", + ); + assert.equal( + $(".selector-chosen .selector-chosen-title label").text(), + "Chosen things ", + ); + assert.equal( + $(".selector-chosen .selector-chosen-title .helptext").text(), + 'Remove things by selecting them and then select the "Remove" arrow button.', + ); + assert.equal( + $(".selector-filter label .help-tooltip")[0].getAttribute("aria-label"), + "Type into this box to filter down the list of available things.", + ); + assert.equal( + $(".selector-filter label .help-tooltip")[1].getAttribute("aria-label"), + "Type into this box to filter down the list of selected things.", ); - assert.equal($('.helptext')[0].nextSibling.getAttribute("class"), "selector"); - assert.equal($('.selector-available label').text().trim(), "Available things"); - assert.equal($('.selector-available label').attr("id"), "id_from_label"); - assert.equal($('.selector-chosen label').text().trim(), "Chosen things"); - assert.equal($('.selector-chosen label').attr("id"), "id_to_label"); - assert.equal($('.selector-chosen select')[0].getAttribute('multiple'), ''); - assert.equal($('.selector-chooseall').text(), "Choose all things"); - assert.equal($('.selector-chooseall').prop("tagName"), "BUTTON"); - assert.equal($('.selector-add').text(), "Choose selected things"); - assert.equal($('.selector-add').prop("tagName"), "BUTTON"); - assert.equal($('.selector-remove').text(), "Remove selected things"); - assert.equal($('.selector-remove').prop("tagName"), "BUTTON"); - assert.equal($('.selector-clearall').text(), "Remove all things"); - assert.equal($('.selector-clearall').prop("tagName"), "BUTTON"); - assert.equal($('.selector-available .filtered').attr("aria-labelledby"), "id_from_label"); - assert.equal($('.selector-available .filtered').attr("aria-describedby"), "id_helptext id_choose_helptext"); - assert.equal($('.selector-available .selector-available-title label').text(), "Available things "); - assert.equal($('.selector-available .selector-available-title .helptext').text(), 'Choose things by selecting them and then select the "Choose" arrow button.'); - assert.equal($('.selector-chosen .filtered').attr("aria-labelledby"), "id_to_label"); - assert.equal($('.selector-chosen .filtered').attr("aria-describedby"), "id_helptext id_remove_helptext"); - assert.equal($('.selector-chosen .selector-chosen-title label').text(), "Chosen things "); - assert.equal($('.selector-chosen .selector-chosen-title .helptext').text(), 'Remove things by selecting them and then select the "Remove" arrow button.'); - assert.equal($('.selector-filter label .help-tooltip')[0].getAttribute("aria-label"), "Type into this box to filter down the list of available things."); - assert.equal($('.selector-filter label .help-tooltip')[1].getAttribute("aria-label"), "Type into this box to filter down the list of selected things."); assert.equal($('#test button:not([type="button"])').length, 0); }); -QUnit.test('filtering available options', function(assert) { +QUnit.test("filtering available options", function (assert) { const $ = django.jQuery; - $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); - $('<option value="1" title="Red">Red</option>').appendTo('#select'); - $('<option value="2" title="Blue">Blue</option>').appendTo('#select'); - $('<option value="3" title="Green">Green</option>').appendTo('#select'); - SelectFilter.init('select', 'items', 0); - assert.equal($('#select_from option').length, 3); - assert.equal($('#select_to option').length, 0); + $('<form><select multiple id="select"></select></form>').appendTo( + "#qunit-fixture", + ); + $('<option value="1" title="Red">Red</option>').appendTo("#select"); + $('<option value="2" title="Blue">Blue</option>').appendTo("#select"); + $('<option value="3" title="Green">Green</option>').appendTo("#select"); + SelectFilter.init("select", "items", 0); + assert.equal($("#select_from option").length, 3); + assert.equal($("#select_to option").length, 0); const done = assert.async(); - const search_term = 'r'; - const event = new KeyboardEvent('keyup', {'key': search_term}); - $('#select_input').val(search_term); - SelectFilter.filter_key_up(event, 'select', '_from'); + const search_term = "r"; + const event = new KeyboardEvent("keyup", { key: search_term }); + $("#select_input").val(search_term); + SelectFilter.filter_key_up(event, "select", "_from"); setTimeout(() => { - assert.equal($('#select_from option').length, 2); - assert.equal($('#select_to option').length, 0); - assert.equal($('#select_from option')[0].value, '1'); - assert.equal($('#select_from option')[1].value, '3'); + assert.equal($("#select_from option").length, 2); + assert.equal($("#select_to option").length, 0); + assert.equal($("#select_from option")[0].value, "1"); + assert.equal($("#select_from option")[1].value, "3"); done(); }); }); -QUnit.test('filtering selected options', function(assert) { +QUnit.test("filtering selected options", function (assert) { const $ = django.jQuery; - $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); - $('<option selected value="1" title="Red">Red</option>').appendTo('#select'); - $('<option selected value="2" title="Blue">Blue</option>').appendTo('#select'); - $('<option selected value="3" title="Green">Green</option>').appendTo('#select'); - SelectFilter.init('select', 'items', 0); - assert.equal($('#select_from option').length, 0); - assert.equal($('#select_to option').length, 3); + $('<form><select multiple id="select"></select></form>').appendTo( + "#qunit-fixture", + ); + $('<option selected value="1" title="Red">Red</option>').appendTo( + "#select", + ); + $('<option selected value="2" title="Blue">Blue</option>').appendTo( + "#select", + ); + $('<option selected value="3" title="Green">Green</option>').appendTo( + "#select", + ); + SelectFilter.init("select", "items", 0); + assert.equal($("#select_from option").length, 0); + assert.equal($("#select_to option").length, 3); const done = assert.async(); - const search_term = 'r'; - const event = new KeyboardEvent('keyup', {'key': search_term}); - $('#select_selected_input').val(search_term); - SelectFilter.filter_key_up(event, 'select', '_to', '_selected_input'); + const search_term = "r"; + const event = new KeyboardEvent("keyup", { key: search_term }); + $("#select_selected_input").val(search_term); + SelectFilter.filter_key_up(event, "select", "_to", "_selected_input"); setTimeout(() => { - assert.equal($('#select_from option').length, 0); - assert.equal($('#select_to option').length, 2); - assert.equal($('#select_to option')[0].value, '1'); - assert.equal($('#select_to option')[1].value, '3'); + assert.equal($("#select_from option").length, 0); + assert.equal($("#select_to option").length, 2); + assert.equal($("#select_to option")[0].value, "1"); + assert.equal($("#select_to option")[1].value, "3"); done(); }); }); -QUnit.test('filtering available options to nothing', function(assert) { +QUnit.test("filtering available options to nothing", function (assert) { const $ = django.jQuery; - $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); - $('<option value="1" title="Red">Red</option>').appendTo('#select'); - $('<option value="2" title="Blue">Blue</option>').appendTo('#select'); - $('<option value="3" title="Green">Green</option>').appendTo('#select'); - SelectFilter.init('select', 'items', 0); - assert.equal($('#select_from option').length, 3); - assert.equal($('#select_to option').length, 0); + $('<form><select multiple id="select"></select></form>').appendTo( + "#qunit-fixture", + ); + $('<option value="1" title="Red">Red</option>').appendTo("#select"); + $('<option value="2" title="Blue">Blue</option>').appendTo("#select"); + $('<option value="3" title="Green">Green</option>').appendTo("#select"); + SelectFilter.init("select", "items", 0); + assert.equal($("#select_from option").length, 3); + assert.equal($("#select_to option").length, 0); const done = assert.async(); - const search_term = 'x'; - const event = new KeyboardEvent('keyup', {'key': search_term}); - $('#select_input').val(search_term); - SelectFilter.filter_key_up(event, 'select', '_from'); + const search_term = "x"; + const event = new KeyboardEvent("keyup", { key: search_term }); + $("#select_input").val(search_term); + SelectFilter.filter_key_up(event, "select", "_from"); setTimeout(() => { - assert.equal($('#select_from option').length, 0); - assert.equal($('#select_to option').length, 0); + assert.equal($("#select_from option").length, 0); + assert.equal($("#select_to option").length, 0); done(); }); }); -QUnit.test('filtering selected options to nothing', function(assert) { +QUnit.test("filtering selected options to nothing", function (assert) { const $ = django.jQuery; - $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); - $('<option selected value="1" title="Red">Red</option>').appendTo('#select'); - $('<option selected value="2" title="Blue">Blue</option>').appendTo('#select'); - $('<option selected value="3" title="Green">Green</option>').appendTo('#select'); - SelectFilter.init('select', 'items', 0); - assert.equal($('#select_from option').length, 0); - assert.equal($('#select_to option').length, 3); + $('<form><select multiple id="select"></select></form>').appendTo( + "#qunit-fixture", + ); + $('<option selected value="1" title="Red">Red</option>').appendTo( + "#select", + ); + $('<option selected value="2" title="Blue">Blue</option>').appendTo( + "#select", + ); + $('<option selected value="3" title="Green">Green</option>').appendTo( + "#select", + ); + SelectFilter.init("select", "items", 0); + assert.equal($("#select_from option").length, 0); + assert.equal($("#select_to option").length, 3); const done = assert.async(); - const search_term = 'x'; - const event = new KeyboardEvent('keyup', {'key': search_term}); - $('#select_selected_input').val(search_term); - SelectFilter.filter_key_up(event, 'select', '_to', '_selected_input'); + const search_term = "x"; + const event = new KeyboardEvent("keyup", { key: search_term }); + $("#select_selected_input").val(search_term); + SelectFilter.filter_key_up(event, "select", "_to", "_selected_input"); setTimeout(() => { - assert.equal($('#select_from option').length, 0); - assert.equal($('#select_to option').length, 0); + assert.equal($("#select_from option").length, 0); + assert.equal($("#select_to option").length, 0); done(); }); }); -QUnit.test('selecting option', function(assert) { +QUnit.test("selecting option", function (assert) { const $ = django.jQuery; - $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); - $('<option value="1" title="Red">Red</option>').appendTo('#select'); - $('<option value="2" title="Blue">Blue</option>').appendTo('#select'); - $('<option value="3" title="Green">Green</option>').appendTo('#select'); - SelectFilter.init('select', 'items', 0); - assert.equal($('#select_from option').length, 3); - assert.equal($('#select_to option').length, 0); + $('<form><select multiple id="select"></select></form>').appendTo( + "#qunit-fixture", + ); + $('<option value="1" title="Red">Red</option>').appendTo("#select"); + $('<option value="2" title="Blue">Blue</option>').appendTo("#select"); + $('<option value="3" title="Green">Green</option>').appendTo("#select"); + SelectFilter.init("select", "items", 0); + assert.equal($("#select_from option").length, 3); + assert.equal($("#select_to option").length, 0); // move to the right const done = assert.async(); - $('#select_from')[0].selectedIndex = 0; - const event = new KeyboardEvent('keydown', {'keyCode': 39, 'charCode': 39}); - SelectFilter.filter_key_down(event, 'select', '_from', '_to'); + $("#select_from")[0].selectedIndex = 0; + const event = new KeyboardEvent("keydown", { keyCode: 39, charCode: 39 }); + SelectFilter.filter_key_down(event, "select", "_from", "_to"); setTimeout(() => { - assert.equal($('#select_from option').length, 2); - assert.equal($('#select_to option').length, 1); - assert.equal($('#select_to option')[0].value, '1'); + assert.equal($("#select_from option").length, 2); + assert.equal($("#select_to option").length, 1); + assert.equal($("#select_to option")[0].value, "1"); done(); }); }); -QUnit.test('deselecting option', function(assert) { +QUnit.test("deselecting option", function (assert) { const $ = django.jQuery; - $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); - $('<option selected value="1" title="Red">Red</option>').appendTo('#select'); - $('<option value="2" title="Blue">Blue</option>').appendTo('#select'); - $('<option value="3" title="Green">Green</option>').appendTo('#select'); - SelectFilter.init('select', 'items', 0); - assert.equal($('#select_from option').length, 2); - assert.equal($('#select_to option').length, 1); - assert.equal($('#select_to option')[0].value, '1'); + $('<form><select multiple id="select"></select></form>').appendTo( + "#qunit-fixture", + ); + $('<option selected value="1" title="Red">Red</option>').appendTo( + "#select", + ); + $('<option value="2" title="Blue">Blue</option>').appendTo("#select"); + $('<option value="3" title="Green">Green</option>').appendTo("#select"); + SelectFilter.init("select", "items", 0); + assert.equal($("#select_from option").length, 2); + assert.equal($("#select_to option").length, 1); + assert.equal($("#select_to option")[0].value, "1"); // move back to the left const done_left = assert.async(); - $('#select_to')[0].selectedIndex = 0; - const event_left = new KeyboardEvent('keydown', {'keyCode': 37, 'charCode': 37}); - SelectFilter.filter_key_down(event_left, 'select', '_to', '_from'); + $("#select_to")[0].selectedIndex = 0; + const event_left = new KeyboardEvent("keydown", { + keyCode: 37, + charCode: 37, + }); + SelectFilter.filter_key_down(event_left, "select", "_to", "_from"); setTimeout(() => { - assert.equal($('#select_from option').length, 3); - assert.equal($('#select_to option').length, 0); + assert.equal($("#select_from option").length, 3); + assert.equal($("#select_to option").length, 0); done_left(); }); }); diff --git a/js_tests/admin/URLify.test.js b/js_tests/admin/URLify.test.js index 471f2fbf05..36afd676c9 100644 --- a/js_tests/admin/URLify.test.js +++ b/js_tests/admin/URLify.test.js @@ -1,28 +1,28 @@ /* global QUnit, URLify */ -'use strict'; +"use strict"; -QUnit.module('admin.URLify'); +QUnit.module("admin.URLify"); -QUnit.test('empty string', function(assert) { - assert.strictEqual(URLify('', 8, true), ''); +QUnit.test("empty string", function (assert) { + assert.strictEqual(URLify("", 8, true), ""); }); -QUnit.test('preserve nonessential words', function(assert) { - assert.strictEqual(URLify('the D is silent', 15, true), 'the-d-is-silent'); +QUnit.test("preserve nonessential words", function (assert) { + assert.strictEqual(URLify("the D is silent", 15, true), "the-d-is-silent"); }); -QUnit.test('strip non-URL characters', function(assert) { - assert.strictEqual(URLify('D#silent@', 7, true), 'dsilent'); +QUnit.test("strip non-URL characters", function (assert) { + assert.strictEqual(URLify("D#silent@", 7, true), "dsilent"); }); -QUnit.test('merge adjacent whitespace', function(assert) { - assert.strictEqual(URLify('D silent', 8, true), 'd-silent'); +QUnit.test("merge adjacent whitespace", function (assert) { + assert.strictEqual(URLify("D silent", 8, true), "d-silent"); }); -QUnit.test('trim trailing hyphens', function(assert) { - assert.strictEqual(URLify('D silent always', 9, true), 'd-silent'); +QUnit.test("trim trailing hyphens", function (assert) { + assert.strictEqual(URLify("D silent always", 9, true), "d-silent"); }); -QUnit.test('non-ASCII string', function(assert) { - assert.strictEqual(URLify('Kaupa-miða', 255, true), 'kaupa-miða'); +QUnit.test("non-ASCII string", function (assert) { + assert.strictEqual(URLify("Kaupa-miða", 255, true), "kaupa-miða"); }); diff --git a/js_tests/admin/actions.test.js b/js_tests/admin/actions.test.js index 81364da681..cfe1b6a20a 100644 --- a/js_tests/admin/actions.test.js +++ b/js_tests/admin/actions.test.js @@ -1,21 +1,21 @@ /* global QUnit, Actions */ -'use strict'; +"use strict"; -QUnit.module('admin.actions', { - beforeEach: function() { +QUnit.module("admin.actions", { + beforeEach: function () { // Number of results shown on page - window._actions_icnt = '100'; + window._actions_icnt = "100"; const $ = django.jQuery; - $('#qunit-fixture').append($('#result-table').text()); + $("#qunit-fixture").append($("#result-table").text()); - Actions(document.querySelectorAll('tr input.action-select')); - } + Actions(document.querySelectorAll("tr input.action-select")); + }, }); -QUnit.test('check', function(assert) { +QUnit.test("check", function (assert) { const $ = django.jQuery; - assert.notOk($('.action-select').is(':checked')); - $('#action-toggle').click(); - assert.ok($('.action-select').is(':checked')); + assert.notOk($(".action-select").is(":checked")); + $("#action-toggle").click(); + assert.ok($(".action-select").is(":checked")); }); diff --git a/js_tests/admin/core.test.js b/js_tests/admin/core.test.js index c549ad99c9..8f59d120d6 100644 --- a/js_tests/admin/core.test.js +++ b/js_tests/admin/core.test.js @@ -1,97 +1,152 @@ /* global QUnit */ -'use strict'; +"use strict"; -QUnit.module('admin.core'); +QUnit.module("admin.core"); -QUnit.test('Date.getTwelveHours', function(assert) { - assert.equal(new Date(2011, 0, 1, 0, 0).getTwelveHours(), 12, '0:00'); - assert.equal(new Date(2011, 0, 1, 11, 0).getTwelveHours(), 11, '11:00'); - assert.equal(new Date(2011, 0, 1, 16, 0).getTwelveHours(), 4, '16:00'); +QUnit.test("Date.getTwelveHours", function (assert) { + assert.equal(new Date(2011, 0, 1, 0, 0).getTwelveHours(), 12, "0:00"); + assert.equal(new Date(2011, 0, 1, 11, 0).getTwelveHours(), 11, "11:00"); + assert.equal(new Date(2011, 0, 1, 16, 0).getTwelveHours(), 4, "16:00"); }); -QUnit.test('Date.getTwoDigitMonth', function(assert) { - assert.equal(new Date(2011, 0, 1).getTwoDigitMonth(), '01', 'jan 1'); - assert.equal(new Date(2011, 9, 1).getTwoDigitMonth(), '10', 'oct 1'); +QUnit.test("Date.getTwoDigitMonth", function (assert) { + assert.equal(new Date(2011, 0, 1).getTwoDigitMonth(), "01", "jan 1"); + assert.equal(new Date(2011, 9, 1).getTwoDigitMonth(), "10", "oct 1"); }); -QUnit.test('Date.getTwoDigitDate', function(assert) { - assert.equal(new Date(2011, 0, 1).getTwoDigitDate(), '01', 'jan 1'); - assert.equal(new Date(2011, 0, 15).getTwoDigitDate(), '15', 'jan 15'); +QUnit.test("Date.getTwoDigitDate", function (assert) { + assert.equal(new Date(2011, 0, 1).getTwoDigitDate(), "01", "jan 1"); + assert.equal(new Date(2011, 0, 15).getTwoDigitDate(), "15", "jan 15"); }); -QUnit.test('Date.getTwoDigitTwelveHour', function(assert) { - assert.equal(new Date(2011, 0, 1, 0, 0).getTwoDigitTwelveHour(), '12', '0:00'); - assert.equal(new Date(2011, 0, 1, 4, 0).getTwoDigitTwelveHour(), '04', '4:00'); - assert.equal(new Date(2011, 0, 1, 22, 0).getTwoDigitTwelveHour(), '10', '22:00'); +QUnit.test("Date.getTwoDigitTwelveHour", function (assert) { + assert.equal( + new Date(2011, 0, 1, 0, 0).getTwoDigitTwelveHour(), + "12", + "0:00", + ); + assert.equal( + new Date(2011, 0, 1, 4, 0).getTwoDigitTwelveHour(), + "04", + "4:00", + ); + assert.equal( + new Date(2011, 0, 1, 22, 0).getTwoDigitTwelveHour(), + "10", + "22:00", + ); }); -QUnit.test('Date.getTwoDigitHour', function(assert) { - assert.equal(new Date(2014, 6, 1, 9, 0).getTwoDigitHour(), '09', '9:00 am is 09'); - assert.equal(new Date(2014, 6, 1, 11, 0).getTwoDigitHour(), '11', '11:00 am is 11'); +QUnit.test("Date.getTwoDigitHour", function (assert) { + assert.equal( + new Date(2014, 6, 1, 9, 0).getTwoDigitHour(), + "09", + "9:00 am is 09", + ); + assert.equal( + new Date(2014, 6, 1, 11, 0).getTwoDigitHour(), + "11", + "11:00 am is 11", + ); }); -QUnit.test('Date.getTwoDigitMinute', function(assert) { - assert.equal(new Date(2014, 6, 1, 0, 5).getTwoDigitMinute(), '05', '12:05 am is 05'); - assert.equal(new Date(2014, 6, 1, 0, 15).getTwoDigitMinute(), '15', '12:15 am is 15'); +QUnit.test("Date.getTwoDigitMinute", function (assert) { + assert.equal( + new Date(2014, 6, 1, 0, 5).getTwoDigitMinute(), + "05", + "12:05 am is 05", + ); + assert.equal( + new Date(2014, 6, 1, 0, 15).getTwoDigitMinute(), + "15", + "12:15 am is 15", + ); }); -QUnit.test('Date.getTwoDigitSecond', function(assert) { - assert.equal(new Date(2014, 6, 1, 0, 0, 2).getTwoDigitSecond(), '02', '12:00:02 am is 02'); - assert.equal(new Date(2014, 6, 1, 0, 0, 20).getTwoDigitSecond(), '20', '12:00:20 am is 20'); +QUnit.test("Date.getTwoDigitSecond", function (assert) { + assert.equal( + new Date(2014, 6, 1, 0, 0, 2).getTwoDigitSecond(), + "02", + "12:00:02 am is 02", + ); + assert.equal( + new Date(2014, 6, 1, 0, 0, 20).getTwoDigitSecond(), + "20", + "12:00:20 am is 20", + ); }); -QUnit.test('Date.getAbbrevMonthName', function(assert) { - assert.equal(new Date(2020, 0, 26).getAbbrevMonthName(), 'Jan', 'jan 26'); - assert.equal(new Date(2020, 9, 26).getAbbrevMonthName(), 'Oct', 'oct 26'); +QUnit.test("Date.getAbbrevMonthName", function (assert) { + assert.equal(new Date(2020, 0, 26).getAbbrevMonthName(), "Jan", "jan 26"); + assert.equal(new Date(2020, 9, 26).getAbbrevMonthName(), "Oct", "oct 26"); }); -QUnit.test('Date.getFullMonthName', function(assert) { - assert.equal(new Date(2020, 0, 26).getFullMonthName(), 'January', 'jan 26'); - assert.equal(new Date(2020, 9, 26).getFullMonthName(), 'October', 'oct 26'); +QUnit.test("Date.getFullMonthName", function (assert) { + assert.equal(new Date(2020, 0, 26).getFullMonthName(), "January", "jan 26"); + assert.equal(new Date(2020, 9, 26).getFullMonthName(), "October", "oct 26"); }); -QUnit.test('Date.getAbbrevDayName', function(assert) { - assert.equal(new Date(2020, 0, 26).getAbbrevDayName(), 'Sun', 'jan 26 2020 is a Sunday'); - assert.equal(new Date(2020, 9, 26).getAbbrevDayName(), 'Mon', 'oct 26 2020 is a Monday'); +QUnit.test("Date.getAbbrevDayName", function (assert) { + assert.equal( + new Date(2020, 0, 26).getAbbrevDayName(), + "Sun", + "jan 26 2020 is a Sunday", + ); + assert.equal( + new Date(2020, 9, 26).getAbbrevDayName(), + "Mon", + "oct 26 2020 is a Monday", + ); }); -QUnit.test('Date.getFullDayName', function(assert) { - assert.equal(new Date(2020, 0, 26).getFullDayName(), 'Sunday', 'jan 26 2020 is a Sunday'); - assert.equal(new Date(2020, 9, 26).getFullDayName(), 'Monday', 'oct 26 2020 is a Monday'); +QUnit.test("Date.getFullDayName", function (assert) { + assert.equal( + new Date(2020, 0, 26).getFullDayName(), + "Sunday", + "jan 26 2020 is a Sunday", + ); + assert.equal( + new Date(2020, 9, 26).getFullDayName(), + "Monday", + "oct 26 2020 is a Monday", + ); }); -QUnit.test('Date.strftime', function(assert) { +QUnit.test("Date.strftime", function (assert) { const date = new Date(2014, 6, 1, 11, 0, 5); - assert.equal(date.strftime('%Y-%m-%d %H:%M:%S'), '2014-07-01 11:00:05'); - assert.equal(date.strftime('%B %d, %Y'), 'July 01, 2014'); - assert.equal(date.strftime('%b %d, %Y'), 'Jul 01, 2014'); - assert.equal(date.strftime('%a %d %m %y'), 'Tue 01 07 14'); - assert.equal(date.strftime('%A (day %w of week) %I %p'), 'Tuesday (day 02 of week) 11 AM'); + assert.equal(date.strftime("%Y-%m-%d %H:%M:%S"), "2014-07-01 11:00:05"); + assert.equal(date.strftime("%B %d, %Y"), "July 01, 2014"); + assert.equal(date.strftime("%b %d, %Y"), "Jul 01, 2014"); + assert.equal(date.strftime("%a %d %m %y"), "Tue 01 07 14"); + assert.equal( + date.strftime("%A (day %w of week) %I %p"), + "Tuesday (day 02 of week) 11 AM", + ); }); -QUnit.test('String.strptime', function(assert) { +QUnit.test("String.strptime", function (assert) { // Use UTC functions for extracting dates since the calendar uses them as // well. Month numbering starts with 0 (January). - const firstParsedDate = '1988-02-26'.strptime('%Y-%m-%d'); + const firstParsedDate = "1988-02-26".strptime("%Y-%m-%d"); assert.equal(firstParsedDate.getUTCDate(), 26); assert.equal(firstParsedDate.getUTCMonth(), 1); assert.equal(firstParsedDate.getUTCFullYear(), 1988); // A %y value in the range of [69, 99] is in the previous century. - const secondParsedDate = '26/02/88'.strptime('%d/%m/%y'); + const secondParsedDate = "26/02/88".strptime("%d/%m/%y"); assert.equal(secondParsedDate.getUTCDate(), 26); assert.equal(secondParsedDate.getUTCMonth(), 1); assert.equal(secondParsedDate.getUTCFullYear(), 1988); - const format = django.get_format('DATE_INPUT_FORMATS')[0]; - const thirdParsedDate = '1983-11-20'.strptime(format); + const format = django.get_format("DATE_INPUT_FORMATS")[0]; + const thirdParsedDate = "1983-11-20".strptime(format); assert.equal(thirdParsedDate.getUTCDate(), 20); assert.equal(thirdParsedDate.getUTCMonth(), 10); assert.equal(thirdParsedDate.getUTCFullYear(), 1983); // A %y value in the range of [00, 68] is in the current century. - const fourthParsedDate = '27/09/68'.strptime('%d/%m/%y'); + const fourthParsedDate = "27/09/68".strptime("%d/%m/%y"); assert.equal(fourthParsedDate.getUTCDate(), 27); assert.equal(fourthParsedDate.getUTCMonth(), 8); assert.equal(fourthParsedDate.getUTCFullYear(), 2068); @@ -103,8 +158,10 @@ QUnit.test('String.strptime', function(assert) { // Checking timezones from GMT+0100 to GMT+1200 for (let i = 1; i <= 12; i++) { - const tz = i > 9 ? '' + i : '0' + i; - const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00')); + const tz = i > 9 ? "" + i : "0" + i; + const date = new Date( + Date.parse("Feb 26, 1988 00:00:00 GMT+" + tz + "00"), + ); assert.notEqual(date.getUTCDate(), 26); assert.equal(date.getUTCDate(), 25); assert.equal(date.getUTCMonth(), 1); @@ -113,8 +170,10 @@ QUnit.test('String.strptime', function(assert) { // Checking timezones from GMT+0000 to GMT-1100 for (let i = 0; i <= 11; i++) { - const tz = i > 9 ? '' + i : '0' + i; - const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00')); + const tz = i > 9 ? "" + i : "0" + i; + const date = new Date( + Date.parse("Feb 26, 1988 00:00:00 GMT-" + tz + "00"), + ); assert.equal(date.getUTCDate(), 26); assert.equal(date.getUTCMonth(), 1); assert.equal(date.getUTCFullYear(), 1988); diff --git a/js_tests/admin/inlines.test.js b/js_tests/admin/inlines.test.js index ee8567dbf4..28de67cf65 100644 --- a/js_tests/admin/inlines.test.js +++ b/js_tests/admin/inlines.test.js @@ -1,174 +1,197 @@ /* global QUnit */ -'use strict'; +"use strict"; -QUnit.module('admin.inlines: tabular formsets', { - beforeEach: function() { +QUnit.module("admin.inlines: tabular formsets", { + beforeEach: function () { const $ = django.jQuery; - const that = this; - this.addText = 'Add another'; - $('#qunit-fixture').append($('#tabular-formset').text()); - this.table = $('table.inline'); - this.inlineRow = this.table.find('tr'); - this.inlineRow.tabularFormset('table.inline tr.form-row', { - prefix: 'first', - addText: that.addText, - deleteText: 'Remove' + this.addText = "Add another"; + + $("#qunit-fixture").append($("#tabular-formset").text()); + this.table = $("table.inline"); + this.inlineRow = this.table.find("tr"); + this.inlineRow.tabularFormset("table.inline tr.form-row", { + prefix: "first", + addText: this.addText, + deleteText: "Remove", }); - } + }, }); -QUnit.test('no forms', function(assert) { - assert.ok(this.inlineRow.hasClass('dynamic-first')); - assert.equal(this.table.find('.add-row a').text(), this.addText); +QUnit.test("no forms", function (assert) { + assert.ok(this.inlineRow.hasClass("dynamic-first")); + assert.equal(this.table.find(".add-row a").text(), this.addText); }); -QUnit.test('add form', function(assert) { - const addButton = this.table.find('.add-row a'); +QUnit.test("add form", function (assert) { + const addButton = this.table.find(".add-row a"); assert.equal(addButton.text(), this.addText); addButton.click(); - assert.ok(this.table.find('#first-1')); + assert.ok(this.table.find("#first-1")); }); -QUnit.test('added form has remove button', function(assert) { - const addButton = this.table.find('.add-row a'); +QUnit.test("added form has remove button", function (assert) { + const addButton = this.table.find(".add-row a"); assert.equal(addButton.text(), this.addText); addButton.click(); - assert.equal(this.table.find('#first-1 .inline-deletelink').length, 1); + assert.equal(this.table.find("#first-1 .inline-deletelink").length, 1); }); -QUnit.test('add/remove form events', function(assert) { +QUnit.test("add/remove form events", function (assert) { assert.expect(5); - const addButton = this.table.find('.add-row a'); - document.addEventListener('formset:added', (event) => { - assert.ok(true, 'event `formset:added` triggered'); - assert.equal(true, event.target.matches('#first-1')); - assert.equal(event.detail.formsetName, 'first'); - }, {once: true}); + const addButton = this.table.find(".add-row a"); + document.addEventListener( + "formset:added", + (event) => { + assert.ok(true, "event `formset:added` triggered"); + assert.equal(true, event.target.matches("#first-1")); + assert.equal(event.detail.formsetName, "first"); + }, + { once: true }, + ); addButton.click(); - const deleteLink = this.table.find('.inline-deletelink'); - document.addEventListener('formset:removed', (event) => { - assert.ok(true, 'event `formset:removed` triggered'); - assert.equal(event.detail.formsetName, 'first'); - }, {once: true}); + const deleteLink = this.table.find(".inline-deletelink"); + document.addEventListener( + "formset:removed", + (event) => { + assert.ok(true, "event `formset:removed` triggered"); + assert.equal(event.detail.formsetName, "first"); + }, + { once: true }, + ); deleteLink.click(); }); -QUnit.test('existing add button', function(assert) { +QUnit.test("existing add button", function (assert) { const $ = django.jQuery; - $('#qunit-fixture').empty(); // Clear the table added in beforeEach - $('#qunit-fixture').append($('#tabular-formset').text()); - this.table = $('table.inline'); - this.inlineRow = this.table.find('tr'); + $("#qunit-fixture").empty(); // Clear the table added in beforeEach + $("#qunit-fixture").append($("#tabular-formset").text()); + this.table = $("table.inline"); + this.inlineRow = this.table.find("tr"); this.table.append('<i class="add-button"></i>'); - const addButton = this.table.find('.add-button'); - this.inlineRow.tabularFormset('table.inline tr', { - prefix: 'first', - deleteText: 'Remove', - addButton: addButton + const addButton = this.table.find(".add-button"); + this.inlineRow.tabularFormset("table.inline tr", { + prefix: "first", + deleteText: "Remove", + addButton: addButton, }); - assert.equal(this.table.find('.add-row a').length, 0); + assert.equal(this.table.find(".add-row a").length, 0); addButton.click(); - assert.ok(this.table.find('#first-1')); + assert.ok(this.table.find("#first-1")); }); - -QUnit.module('admin.inlines: tabular formsets with validation errors', { - beforeEach: function() { +QUnit.module("admin.inlines: tabular formsets with validation errors", { + beforeEach: function () { const $ = django.jQuery; - $('#qunit-fixture').append($('#tabular-formset-with-validation-error').text()); - this.table = $('table.inline'); - this.inlineRows = this.table.find('tr.form-row'); - this.inlineRows.tabularFormset('table.inline tr.form-row', { - prefix: 'second' + $("#qunit-fixture").append( + $("#tabular-formset-with-validation-error").text(), + ); + this.table = $("table.inline"); + this.inlineRows = this.table.find("tr.form-row"); + this.inlineRows.tabularFormset("table.inline tr.form-row", { + prefix: "second", }); - } + }, }); -QUnit.test('first form has delete checkbox and no button', function(assert) { +QUnit.test("first form has delete checkbox and no button", function (assert) { const tr = this.inlineRows.slice(0, 1); - assert.ok(tr.hasClass('dynamic-second')); - assert.ok(tr.hasClass('has_original')); - assert.equal(tr.find('td.delete input').length, 1); - assert.equal(tr.find('td.delete .inline-deletelink').length, 0); + assert.ok(tr.hasClass("dynamic-second")); + assert.ok(tr.hasClass("has_original")); + assert.equal(tr.find("td.delete input").length, 1); + assert.equal(tr.find("td.delete .inline-deletelink").length, 0); }); -QUnit.test('dynamic form has remove button', function(assert) { +QUnit.test("dynamic form has remove button", function (assert) { const tr = this.inlineRows.slice(1, 2); - assert.ok(tr.hasClass('dynamic-second')); - assert.notOk(tr.hasClass('has_original')); - assert.equal(tr.find('.inline-deletelink').length, 1); + assert.ok(tr.hasClass("dynamic-second")); + assert.notOk(tr.hasClass("has_original")); + assert.equal(tr.find(".inline-deletelink").length, 1); }); -QUnit.test('dynamic template has nothing', function(assert) { +QUnit.test("dynamic template has nothing", function (assert) { const tr = this.inlineRows.slice(2, 3); - assert.ok(tr.hasClass('empty-form')); - assert.notOk(tr.hasClass('dynamic-second')); - assert.notOk(tr.hasClass('has_original')); - assert.equal(tr.find('td.delete')[0].innerHTML, ''); + assert.ok(tr.hasClass("empty-form")); + assert.notOk(tr.hasClass("dynamic-second")); + assert.notOk(tr.hasClass("has_original")); + assert.equal(tr.find("td.delete")[0].innerHTML, ""); }); -QUnit.test('removing a form-row also removed related row with non-field errors', function(assert) { - const $ = django.jQuery; - assert.ok(this.table.find('.row-form-errors').length); - const tr = this.inlineRows.slice(1, 2); - const trWithErrors = tr.prev(); - assert.ok(trWithErrors.hasClass('row-form-errors')); - const deleteLink = tr.find('a.inline-deletelink'); - deleteLink.trigger($.Event('click', {target: deleteLink})); - assert.notOk(this.table.find('.row-form-errors').length); -}); +QUnit.test( + "removing a form-row also removed related row with non-field errors", + function (assert) { + const $ = django.jQuery; + assert.ok(this.table.find(".row-form-errors").length); + const tr = this.inlineRows.slice(1, 2); + const trWithErrors = tr.prev(); + assert.ok(trWithErrors.hasClass("row-form-errors")); + const deleteLink = tr.find("a.inline-deletelink"); + deleteLink.trigger($.Event("click", { target: deleteLink })); + assert.notOk(this.table.find(".row-form-errors").length); + }, +); -QUnit.module('admin.inlines: tabular formsets with max_num', { - beforeEach: function() { +QUnit.module("admin.inlines: tabular formsets with max_num", { + beforeEach: function () { const $ = django.jQuery; - $('#qunit-fixture').append($('#tabular-formset-with-validation-error').text()); - this.table = $('table.inline'); - this.maxNum = $('input.id_second-MAX_NUM_FORMS'); + $("#qunit-fixture").append( + $("#tabular-formset-with-validation-error").text(), + ); + this.table = $("table.inline"); + this.maxNum = $("input.id_second-MAX_NUM_FORMS"); this.maxNum.val(2); - this.inlineRows = this.table.find('tr.form-row'); - this.inlineRows.tabularFormset('table.inline tr.form-row', { - prefix: 'second' + this.inlineRows = this.table.find("tr.form-row"); + this.inlineRows.tabularFormset("table.inline tr.form-row", { + prefix: "second", }); - } + }, }); -QUnit.test('does not show the add button if already at max_num', function(assert) { - const addButton = this.table.find('tr.add_row > td > a'); - assert.notOk(addButton.is(':visible')); -}); +QUnit.test( + "does not show the add button if already at max_num", + function (assert) { + const addButton = this.table.find("tr.add_row > td > a"); + assert.notOk(addButton.is(":visible")); + }, +); -QUnit.test('make addButton visible again', function(assert) { +QUnit.test("make addButton visible again", function (assert) { const $ = django.jQuery; - const addButton = this.table.find('tr.add_row > td > a'); - const removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink'); - removeButton.trigger($.Event( "click", { target: removeButton } )); - assert.notOk(addButton.is(':visible')); + const addButton = this.table.find("tr.add_row > td > a"); + const removeButton = this.table + .find("tr.form-row:first") + .find("a.inline-deletelink"); + removeButton.trigger($.Event("click", { target: removeButton })); + assert.notOk(addButton.is(":visible")); }); - -QUnit.module('admin.inlines: tabular formsets with min_num', { - beforeEach: function() { +QUnit.module("admin.inlines: tabular formsets with min_num", { + beforeEach: function () { const $ = django.jQuery; - $('#qunit-fixture').append($('#tabular-formset-with-validation-error').text()); - this.table = $('table.inline'); - this.minNum = $('input#id_second-MIN_NUM_FORMS'); + $("#qunit-fixture").append( + $("#tabular-formset-with-validation-error").text(), + ); + this.table = $("table.inline"); + this.minNum = $("input#id_second-MIN_NUM_FORMS"); this.minNum.val(2); - this.inlineRows = this.table.find('tr.form-row'); - this.inlineRows.tabularFormset('table.inline tr.form-row', { - prefix: 'second' + this.inlineRows = this.table.find("tr.form-row"); + this.inlineRows.tabularFormset("table.inline tr.form-row", { + prefix: "second", }); - } + }, }); -QUnit.test('does not show the remove buttons if already at min_num', function(assert) { - assert.notOk(this.table.find('.inline-deletelink:visible').length); -}); +QUnit.test( + "does not show the remove buttons if already at min_num", + function (assert) { + assert.notOk(this.table.find(".inline-deletelink:visible").length); + }, +); -QUnit.test('make removeButtons visible again', function(assert) { +QUnit.test("make removeButtons visible again", function (assert) { const $ = django.jQuery; - const addButton = this.table.find('tr.add-row > td > a'); - addButton.trigger($.Event( "click", { target: addButton } )); - assert.equal(this.table.find('.inline-deletelink:visible').length, 2); + const addButton = this.table.find("tr.add-row > td > a"); + addButton.trigger($.Event("click", { target: addButton })); + assert.equal(this.table.find(".inline-deletelink:visible").length, 2); }); diff --git a/js_tests/admin/jsi18n-mocks.test.js b/js_tests/admin/jsi18n-mocks.test.js index 6609c28e43..058bb3df25 100644 --- a/js_tests/admin/jsi18n-mocks.test.js +++ b/js_tests/admin/jsi18n-mocks.test.js @@ -1,29 +1,36 @@ -'use strict'; +"use strict"; { - const globals = this; - const django = globals.django; + const django = this.django; - django.pluralidx = function(count) { return (count === 1) ? 0 : 1; }; + django.pluralidx = function (count) { + return count === 1 ? 0 : 1; + }; /* gettext identity library */ - django.gettext = function(msgid) { return msgid; }; - django.ngettext = function(singular, plural, count) { - return (count === 1) ? singular : plural; + django.gettext = function (msgid) { + return msgid; + }; + django.ngettext = function (singular, plural, count) { + return count === 1 ? singular : plural; + }; + django.gettext_noop = function (msgid) { + return msgid; + }; + django.pgettext = function (context, msgid) { + return msgid; }; - django.gettext_noop = function(msgid) { return msgid; }; - django.pgettext = function(context, msgid) { return msgid; }; - django.npgettext = function(context, singular, plural, count) { - return (count === 1) ? singular : plural; + django.npgettext = function (context, singular, plural, count) { + return count === 1 ? singular : plural; }; - django.interpolate = function(fmt, obj, named) { + django.interpolate = function (fmt, obj, named) { if (named) { - return fmt.replace(/%\(\w+\)s/g, function(match) { + return fmt.replace(/%\(\w+\)s/g, function (match) { return String(obj[match.slice(2, -2)]); }); } else { - return fmt.replace(/%s/g, function(match) { + return fmt.replace(/%s/g, function (match) { return String(obj.shift()); }); } @@ -32,8 +39,8 @@ /* formatting library */ django.formats = { - "DATETIME_FORMAT": "N j, Y, P", - "DATETIME_INPUT_FORMATS": [ + DATETIME_FORMAT: "N j, Y, P", + DATETIME_INPUT_FORMATS: [ "%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%d %H:%M", @@ -45,33 +52,25 @@ "%m/%d/%y %H:%M:%S", "%m/%d/%y %H:%M:%S.%f", "%m/%d/%y %H:%M", - "%m/%d/%y" - ], - "DATE_FORMAT": "N j, Y", - "DATE_INPUT_FORMATS": [ - "%Y-%m-%d", - "%m/%d/%Y", - "%m/%d/%y" - ], - "DECIMAL_SEPARATOR": ".", - "FIRST_DAY_OF_WEEK": 0, - "MONTH_DAY_FORMAT": "F j", - "NUMBER_GROUPING": 3, - "SHORT_DATETIME_FORMAT": "m/d/Y P", - "SHORT_DATE_FORMAT": "m/d/Y", - "THOUSAND_SEPARATOR": ",", - "TIME_FORMAT": "P", - "TIME_INPUT_FORMATS": [ - "%H:%M:%S", - "%H:%M:%S.%f", - "%H:%M" + "%m/%d/%y", ], - "YEAR_MONTH_FORMAT": "F Y" + DATE_FORMAT: "N j, Y", + DATE_INPUT_FORMATS: ["%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y"], + DECIMAL_SEPARATOR: ".", + FIRST_DAY_OF_WEEK: 0, + MONTH_DAY_FORMAT: "F j", + NUMBER_GROUPING: 3, + SHORT_DATETIME_FORMAT: "m/d/Y P", + SHORT_DATE_FORMAT: "m/d/Y", + THOUSAND_SEPARATOR: ",", + TIME_FORMAT: "P", + TIME_INPUT_FORMATS: ["%H:%M:%S", "%H:%M:%S.%f", "%H:%M"], + YEAR_MONTH_FORMAT: "F Y", }; - django.get_format = function(format_type) { + django.get_format = function (format_type) { const value = django.formats[format_type]; - if (typeof value === 'undefined') { + if (typeof value === "undefined") { return format_type; } else { return value; @@ -79,12 +78,12 @@ }; /* add to global namespace */ - globals.pluralidx = django.pluralidx; - globals.gettext = django.gettext; - globals.ngettext = django.ngettext; - globals.gettext_noop = django.gettext_noop; - globals.pgettext = django.pgettext; - globals.npgettext = django.npgettext; - globals.interpolate = django.interpolate; - globals.get_format = django.get_format; -}; + this.pluralidx = django.pluralidx; + this.gettext = django.gettext; + this.ngettext = django.ngettext; + this.gettext_noop = django.gettext_noop; + this.pgettext = django.pgettext; + this.npgettext = django.npgettext; + this.interpolate = django.interpolate; + this.get_format = django.get_format; +} diff --git a/js_tests/admin/navigation.test.js b/js_tests/admin/navigation.test.js index 0da50e757c..a53dd79747 100644 --- a/js_tests/admin/navigation.test.js +++ b/js_tests/admin/navigation.test.js @@ -1,24 +1,24 @@ /* global QUnit, initSidebarQuickFilter */ -'use strict'; +"use strict"; -QUnit.module('admin.sidebar: filter', { - beforeEach: function() { +QUnit.module("admin.sidebar: filter", { + beforeEach: function () { const $ = django.jQuery; - $('#qunit-fixture').append($('#nav-sidebar-filter').text()); - this.navSidebar = $('#nav-sidebar'); - this.navFilter = $('#nav-filter'); + $("#qunit-fixture").append($("#nav-sidebar-filter").text()); + this.navSidebar = $("#nav-sidebar"); + this.navFilter = $("#nav-filter"); initSidebarQuickFilter(); - } + }, }); -QUnit.test('filter by a model name', function(assert) { - assert.equal(this.navSidebar.find('th[scope=row] a').length, 2); +QUnit.test("filter by a model name", function (assert) { + assert.equal(this.navSidebar.find("th[scope=row] a").length, 2); - this.navFilter.val('us'); // Matches 'users'. - this.navFilter[0].dispatchEvent(new Event('change')); + this.navFilter.val("us"); // Matches 'users'. + this.navFilter[0].dispatchEvent(new Event("change")); assert.equal(this.navSidebar.find('tr[class^="model-"]:visible').length, 1); - this.navFilter.val('nonexistent'); - this.navFilter[0].dispatchEvent(new Event('change')); + this.navFilter.val("nonexistent"); + this.navFilter[0].dispatchEvent(new Event("change")); assert.equal(this.navSidebar.find('tr[class^="model-"]:visible').length, 0); }); diff --git a/js_tests/gis/mapwidget.test.js b/js_tests/gis/mapwidget.test.js index 4f2f3bb91c..838cf22219 100644 --- a/js_tests/gis/mapwidget.test.js +++ b/js_tests/gis/mapwidget.test.js @@ -1,157 +1,232 @@ /* global QUnit, MapWidget, ol */ -'use strict'; +"use strict"; -QUnit.module('gis.OLMapWidget'); +QUnit.module("gis.OLMapWidget"); -QUnit.test('MapWidget.featureAdded', function(assert) { - const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'}; +QUnit.test("MapWidget.featureAdded", function (assert) { + const options = { + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + }; const widget = new MapWidget(options); assert.equal(widget.featureCollection.getLength(), 1); widget.serializeFeatures(); assert.equal( - document.getElementById('id_point').value, + document.getElementById("id_point").value, '{"type":"Point","coordinates":[7.8177,47.397]}', - 'Point added to vector layer' + "Point added to vector layer", ); }); -QUnit.test('MapWidget.map_srid', function(assert) { - const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'}; +QUnit.test("MapWidget.map_srid", function (assert) { + const options = { + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + }; const widget = new MapWidget(options); - assert.equal(widget.map.getView().getProjection().getCode(), 'EPSG:3857', 'SRID 3857'); + assert.equal( + widget.map.getView().getProjection().getCode(), + "EPSG:3857", + "SRID 3857", + ); }); -QUnit.test('MapWidget.defaultCenter', function(assert) { - const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'}; +QUnit.test("MapWidget.defaultCenter", function (assert) { + const options = { + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + }; let widget = new MapWidget(options); - assert.equal(widget.defaultCenter().toString(), '0,0', 'Default center at 0, 0'); + assert.equal( + widget.defaultCenter().toString(), + "0,0", + "Default center at 0, 0", + ); options.default_lat = 47.08; options.default_lon = 6.81; widget = new MapWidget(options); assert.equal( widget.defaultCenter().toString(), - '6.81,47.08', - 'Default center at 6.81, 47.08' + "6.81,47.08", + "Default center at 6.81, 47.08", ); assert.equal(Math.round(widget.map.getView().getZoom()), 17); }); -QUnit.test('MapWidget.interactions', function(assert) { - const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'}; +QUnit.test("MapWidget.interactions", function (assert) { + const options = { + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + }; const widget = new MapWidget(options); assert.equal(Object.keys(widget.interactions).length, 2); - assert.equal(widget.interactions.draw.getActive(), false, "Draw is inactive with an existing point"); - assert.equal(widget.interactions.modify.getActive(), true, "Modify is active with an existing point"); + assert.equal( + widget.interactions.draw.getActive(), + false, + "Draw is inactive with an existing point", + ); + assert.equal( + widget.interactions.modify.getActive(), + true, + "Modify is active with an existing point", + ); }); -QUnit.test('MapWidget.clearFeatures', function(assert) { - const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'}; +QUnit.test("MapWidget.clearFeatures", function (assert) { + const options = { + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + }; const widget = new MapWidget(options); - const initial_value = document.getElementById('id_point').value; + const initial_value = document.getElementById("id_point").value; widget.clearFeatures(); - assert.equal(document.getElementById('id_point').value, ""); - document.getElementById('id_point').value = initial_value; + assert.equal(document.getElementById("id_point").value, ""); + document.getElementById("id_point").value = initial_value; }); -QUnit.test('MapWidget.multipolygon', function(assert) { - const options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'}; +QUnit.test("MapWidget.multipolygon", function (assert) { + const options = { + id: "id_multipolygon", + map_id: "id_multipolygon_map", + geom_name: "MultiPolygon", + }; const widget = new MapWidget(options); assert.ok(widget.options.is_collection); - assert.equal(widget.interactions.draw.getActive(), true, "Draw is active with no existing content"); + assert.equal( + widget.interactions.draw.getActive(), + true, + "Draw is active with no existing content", + ); }); -QUnit.test('MapWidget.IsCollection', function(assert) { - const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'}; +QUnit.test("MapWidget.IsCollection", function (assert) { + const options = { + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + }; let widget = new MapWidget(options); assert.notOk(widget.options.is_collection); // Empty the default initial Point - document.getElementById('id_point').value = ""; + document.getElementById("id_point").value = ""; - options.geom_name = 'Polygon'; + options.geom_name = "Polygon"; widget = new MapWidget(options); assert.notOk(widget.options.is_collection); - options.geom_name = 'LineString'; + options.geom_name = "LineString"; widget = new MapWidget(options); assert.notOk(widget.options.is_collection); - options.geom_name = 'MultiPoint'; + options.geom_name = "MultiPoint"; widget = new MapWidget(options); assert.ok(widget.options.is_collection); - options.geom_name = 'MultiPolygon'; + options.geom_name = "MultiPolygon"; widget = new MapWidget(options); assert.ok(widget.options.is_collection); - options.geom_name = 'MultiLineString'; + options.geom_name = "MultiLineString"; widget = new MapWidget(options); assert.ok(widget.options.is_collection); - options.geom_name = 'GeometryCollection'; + options.geom_name = "GeometryCollection"; widget = new MapWidget(options); assert.ok(widget.options.is_collection); }); -QUnit.test('MapWidget.layerBuilder.osm returns OSM layer', function(assert) { +QUnit.test("MapWidget.layerBuilder.osm returns OSM layer", function (assert) { const layer = MapWidget.layerBuilder.osm(); - assert.ok(layer instanceof ol.layer.Tile, 'Layer is Tile'); - assert.ok(layer.getSource() instanceof ol.source.OSM, 'Source is OSM'); + assert.ok(layer instanceof ol.layer.Tile, "Layer is Tile"); + assert.ok(layer.getSource() instanceof ol.source.OSM, "Source is OSM"); }); -QUnit.test('MapWidget.layerBuilder.nasaWorldview returns XYZ layer', function(assert) { - const layer = MapWidget.layerBuilder.nasaWorldview(); - assert.ok(layer instanceof ol.layer.Tile, 'Layer is Tile'); - assert.ok(layer.getSource() instanceof ol.source.XYZ, 'Source is XYZ'); - assert.ok(layer.getSource().getUrls()[0].includes('earthdata.nasa.gov'), 'URL is NASA-hosted'); -}); +QUnit.test( + "MapWidget.layerBuilder.nasaWorldview returns XYZ layer", + function (assert) { + const layer = MapWidget.layerBuilder.nasaWorldview(); + assert.ok(layer instanceof ol.layer.Tile, "Layer is Tile"); + assert.ok(layer.getSource() instanceof ol.source.XYZ, "Source is XYZ"); + assert.ok( + layer.getSource().getUrls()[0].includes("earthdata.nasa.gov"), + "URL is NASA-hosted", + ); + }, +); -QUnit.test('MapWidget uses default OSM base layer when none specified', function(assert) { - const widget = new MapWidget({ - id: 'id_point', - map_id: 'id_point_map', - geom_name: 'Point' - }); - assert.ok(widget.baseLayer.getSource() instanceof ol.source.OSM, 'Default base layer is OSM'); -}); +QUnit.test( + "MapWidget uses default OSM base layer when none specified", + function (assert) { + const widget = new MapWidget({ + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + }); + assert.ok( + widget.baseLayer.getSource() instanceof ol.source.OSM, + "Default base layer is OSM", + ); + }, +); -QUnit.test('MapWidget uses named base layer from layerBuilder', function(assert) { - const widget = new MapWidget({ - id: 'id_point', - map_id: 'id_point_map', - geom_name: 'Point', - base_layer: 'nasaWorldview' - }); - assert.ok(widget.baseLayer.getSource() instanceof ol.source.XYZ, 'Uses named base layer from builder'); -}); +QUnit.test( + "MapWidget uses named base layer from layerBuilder", + function (assert) { + const widget = new MapWidget({ + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + base_layer: "nasaWorldview", + }); + assert.ok( + widget.baseLayer.getSource() instanceof ol.source.XYZ, + "Uses named base layer from builder", + ); + }, +); -QUnit.test('MapWidget uses passed-in base layer object directly', function(assert) { - const customLayer = new ol.layer.Tile({source: new ol.source.OSM()}); - const widget = new MapWidget({ - id: 'id_point', - map_id: 'id_point_map', - geom_name: 'Point', - base_layer: customLayer - }); - assert.strictEqual(widget.baseLayer, customLayer, 'Uses provided layer object'); -}); +QUnit.test( + "MapWidget uses passed-in base layer object directly", + function (assert) { + const customLayer = new ol.layer.Tile({ source: new ol.source.OSM() }); + const widget = new MapWidget({ + id: "id_point", + map_id: "id_point_map", + geom_name: "Point", + base_layer: customLayer, + }); + assert.strictEqual( + widget.baseLayer, + customLayer, + "Uses provided layer object", + ); + }, +); -QUnit.test('initMapWidgetInSection initializes widgets and skips __prefix__', function(assert) { - const wrapper1 = document.createElement('div'); - wrapper1.className = 'dj_map_wrapper'; - wrapper1.id = 'id_point_map_wrapper'; - wrapper1.innerHTML = ` +QUnit.test( + "initMapWidgetInSection initializes widgets and skips __prefix__", + function (assert) { + const wrapper1 = document.createElement("div"); + wrapper1.className = "dj_map_wrapper"; + wrapper1.id = "id_point_map_wrapper"; + wrapper1.innerHTML = ` <textarea id="id_point"></textarea> <div class="dj_map" id="id_point_map"></div> <script type="application/json" id="id_point_mapwidget_options"> { "geom_name": "Point" } </script> `; - document.body.appendChild(wrapper1); + document.body.appendChild(wrapper1); - const wrapper2 = document.createElement('div'); - wrapper2.className = 'dj_map_wrapper'; - wrapper2.id = 'form-__prefix__-map_wrapper'; - wrapper2.innerHTML = ` + const wrapper2 = document.createElement("div"); + wrapper2.className = "dj_map_wrapper"; + wrapper2.id = "form-__prefix__-map_wrapper"; + wrapper2.innerHTML = ` <textarea id="id_fake"></textarea> <div class="dj_map" id="id_fake_map"></div> <script type="application/json" id="id_fake_mapwidget_options"> @@ -159,16 +234,25 @@ QUnit.test('initMapWidgetInSection initializes widgets and skips __prefix__', fu </script> `; - document.body.appendChild(wrapper2); + document.body.appendChild(wrapper2); - const maps = window.initMapWidgetInSection(document); + const maps = window.initMapWidgetInSection(document); - assert.equal(maps.length, 1, 'Only one map widget is initialized'); - assert.ok(maps[0] instanceof MapWidget, 'Map is instance of MapWidget'); - assert.equal(maps[0].options.id, 'id_point', 'Correct widget was initialized'); - assert.equal(maps[0].options.map_id, 'id_point_map', 'Map ID is correct'); + assert.equal(maps.length, 1, "Only one map widget is initialized"); + assert.ok(maps[0] instanceof MapWidget, "Map is instance of MapWidget"); + assert.equal( + maps[0].options.id, + "id_point", + "Correct widget was initialized", + ); + assert.equal( + maps[0].options.map_id, + "id_point_map", + "Map ID is correct", + ); - // Clean up - wrapper1.remove(); - wrapper2.remove(); -}); + // Clean up + wrapper1.remove(); + wrapper2.remove(); + }, +); |
