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/admin/SelectBox.test.js | |
| parent | 47789e3a2b471995ed753c87ce69ffbaa59c0601 (diff) | |
Formatted JavaScript files.
Diffstat (limited to 'js_tests/admin/SelectBox.test.js')
| -rw-r--r-- | js_tests/admin/SelectBox.test.js | 213 |
1 files changed, 108 insertions, 105 deletions
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"); }); |
