mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-23 10:56:35 +02:00
add static files
This commit is contained in:
257
static/vendor/select2/tests/integration/dom-changes.js
vendored
Normal file
257
static/vendor/select2/tests/integration/dom-changes.js
vendored
Normal file
@ -0,0 +1,257 @@
|
||||
module('DOM integration');
|
||||
|
||||
test('adding a new unselected option changes nothing', function (assert) {
|
||||
// Any browsers which support mutation observers will not trigger the event
|
||||
var expected = 4;
|
||||
if (window.MutationObserver) {
|
||||
expected = 2;
|
||||
} else if (!window.addEventListener) {
|
||||
expected = 2;
|
||||
}
|
||||
|
||||
assert.expect(expected);
|
||||
|
||||
var asyncDone = null;
|
||||
var syncDone = assert.async();
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone = assert.async();
|
||||
}
|
||||
|
||||
var $ = require('jquery');
|
||||
var Options = require('select2/options');
|
||||
var Select2 = require('select2/core');
|
||||
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'</select>'
|
||||
);
|
||||
|
||||
$('#qunit-fixture').append($select);
|
||||
|
||||
var select = new Select2($select);
|
||||
|
||||
select.on('selection:update', function (args) {
|
||||
assert.equal(
|
||||
args.data.length,
|
||||
1,
|
||||
'There was more than one selection'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
args.data[0].id,
|
||||
'One',
|
||||
'The selection changed to something other than One'
|
||||
);
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone();
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'One'
|
||||
);
|
||||
|
||||
var $option = $('<option>Three</option>');
|
||||
|
||||
$select.append($option);
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'One'
|
||||
);
|
||||
|
||||
syncDone();
|
||||
});
|
||||
|
||||
test('adding a new selected option changes the value', function (assert) {
|
||||
// handle IE 8 not being supported
|
||||
var expected = 4;
|
||||
if (!window.MutationObserver && !window.addEventListener) {
|
||||
expected = 2;
|
||||
}
|
||||
|
||||
assert.expect(expected);
|
||||
|
||||
var asyncDone = null;
|
||||
var syncDone = assert.async();
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone = assert.async();
|
||||
}
|
||||
|
||||
var $ = require('jquery');
|
||||
var Options = require('select2/options');
|
||||
var Select2 = require('select2/core');
|
||||
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'</select>'
|
||||
);
|
||||
|
||||
$('#qunit-fixture').append($select);
|
||||
|
||||
var select = new Select2($select);
|
||||
|
||||
select.on('selection:update', function (args) {
|
||||
assert.equal(
|
||||
args.data.length,
|
||||
1,
|
||||
'There was more than one selection'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
args.data[0].id,
|
||||
'Three',
|
||||
'The selection did not change to Three'
|
||||
);
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone();
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'One'
|
||||
);
|
||||
|
||||
var $option = $('<option selected>Three</option>');
|
||||
|
||||
$select.append($option);
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'Three'
|
||||
);
|
||||
|
||||
syncDone();
|
||||
});
|
||||
|
||||
test('removing an unselected option changes nothing', function (assert) {
|
||||
// Any browsers which support mutation observers will not trigger the event
|
||||
var expected = 4;
|
||||
if (!window.MutationObserver && !window.addEventListener) {
|
||||
expected = 2;
|
||||
}
|
||||
|
||||
assert.expect(expected);
|
||||
|
||||
var asyncDone = null;
|
||||
var syncDone = assert.async();
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone = assert.async();
|
||||
}
|
||||
|
||||
var $ = require('jquery');
|
||||
var Options = require('select2/options');
|
||||
var Select2 = require('select2/core');
|
||||
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'</select>'
|
||||
);
|
||||
|
||||
$('#qunit-fixture').append($select);
|
||||
|
||||
var select = new Select2($select);
|
||||
|
||||
select.on('selection:update', function (args) {
|
||||
assert.equal(
|
||||
args.data.length,
|
||||
1,
|
||||
'There was more than one selection'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
args.data[0].id,
|
||||
'One',
|
||||
'The selection changed to something other than One'
|
||||
);
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone();
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'One'
|
||||
);
|
||||
|
||||
$select.children().eq(1).remove();
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'One'
|
||||
);
|
||||
|
||||
syncDone();
|
||||
});
|
||||
|
||||
test('removing a selected option changes the value', function (assert) {
|
||||
// handle IE 8 not being supported
|
||||
var expected = 3;
|
||||
if (!window.MutationObserver && !window.addEventListener) {
|
||||
expected = 2;
|
||||
}
|
||||
|
||||
assert.expect(expected);
|
||||
|
||||
var asyncDone = null;
|
||||
var syncDone = assert.async();
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone = assert.async();
|
||||
}
|
||||
|
||||
var $ = require('jquery');
|
||||
var Options = require('select2/options');
|
||||
var Select2 = require('select2/core');
|
||||
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'</select>'
|
||||
);
|
||||
|
||||
$('#qunit-fixture').append($select);
|
||||
|
||||
var select = new Select2($select);
|
||||
|
||||
select.on('selection:update', function (args) {
|
||||
assert.equal(
|
||||
args.data.length,
|
||||
1,
|
||||
'There was more than one selection'
|
||||
);
|
||||
|
||||
if (expected != 2) {
|
||||
asyncDone();
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'One'
|
||||
);
|
||||
|
||||
$select.children().eq(0).remove();
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'Two'
|
||||
);
|
||||
|
||||
syncDone();
|
||||
});
|
98
static/vendor/select2/tests/integration/jquery-calls.js
vendored
Normal file
98
static/vendor/select2/tests/integration/jquery-calls.js
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
module('select2(val)');
|
||||
|
||||
var Utils = require('select2/utils');
|
||||
|
||||
test('multiple elements with arguments works', function (assert) {
|
||||
var $ = require('jquery');
|
||||
require('jquery.select2');
|
||||
|
||||
var $first = $(
|
||||
'<select>' +
|
||||
'<option>1</option>' +
|
||||
'<option>2</option>' +
|
||||
'</select>'
|
||||
);
|
||||
var $second = $first.clone();
|
||||
|
||||
var $both = $first.add($second);
|
||||
$both.select2();
|
||||
|
||||
$both.select2('val', '2');
|
||||
|
||||
assert.equal(
|
||||
$first.val(),
|
||||
'2',
|
||||
'The call should change the value on the first element'
|
||||
);
|
||||
assert.equal(
|
||||
$second.val(),
|
||||
'2',
|
||||
'The call should also change the value on the second element'
|
||||
);
|
||||
});
|
||||
|
||||
test('initializes when jQuery $.data contains' +
|
||||
' cyclic reference', function (assert) {
|
||||
var $ = require('jquery');
|
||||
require('jquery.select2');
|
||||
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'<option value="3" selected>Three</option>' +
|
||||
'</select>'
|
||||
);
|
||||
|
||||
// Add a circular reference object using jQuery.
|
||||
var recursiveObject = {};
|
||||
|
||||
recursiveObject.same = recursiveObject;
|
||||
|
||||
$select.data('same', recursiveObject);
|
||||
|
||||
$select.select2();
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'3',
|
||||
'The option value should be pulled correctly'
|
||||
);
|
||||
});
|
||||
|
||||
test('$element.data returns instance and options correctly',
|
||||
function (assert) {
|
||||
var $ = require('jquery');
|
||||
require('jquery.select2');
|
||||
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option value="1">One</option>' +
|
||||
'<option value="2">Two</option>' +
|
||||
'<option value="3" selected>Three</option>' +
|
||||
'</select>'
|
||||
);
|
||||
|
||||
// Initialize.
|
||||
$select.select2({maximumSelectionLength: 2, multiple: true});
|
||||
|
||||
assert.equal(
|
||||
$select.val(),
|
||||
'3',
|
||||
'Only 1 option should be pulled.'
|
||||
);
|
||||
|
||||
// Try to resolve instance via .data('select2').
|
||||
var $instance = $select.data('select2');
|
||||
assert.ok($instance);
|
||||
assert.ok($instance.options);
|
||||
|
||||
// Ensure $select.data('select2') is the same instance
|
||||
// created by .select2()
|
||||
assert.equal($instance, Utils.GetData($instance.$element[0],
|
||||
'select2'));
|
||||
|
||||
// Ensure initialized property matches.
|
||||
assert.equal($instance.options.options.maximumSelectionLength,
|
||||
2);
|
||||
});
|
139
static/vendor/select2/tests/integration/select2-methods.js
vendored
Normal file
139
static/vendor/select2/tests/integration/select2-methods.js
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
module('select2(data)');
|
||||
|
||||
var $ = require('jquery');
|
||||
var Select2 = require('select2/core');
|
||||
var Options = require('select2/options');
|
||||
|
||||
test('single default selection returned', function (assert) {
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'<option value="3" selected>Three</option>' +
|
||||
'</select>'
|
||||
);
|
||||
var options = new Options({});
|
||||
|
||||
var select = new Select2($select, options);
|
||||
|
||||
var items = select.data();
|
||||
|
||||
assert.equal(
|
||||
items.length,
|
||||
1,
|
||||
'The one selected item should be returned'
|
||||
);
|
||||
|
||||
var first = items[0];
|
||||
|
||||
assert.equal(
|
||||
first.id,
|
||||
'3',
|
||||
'The first option was correct'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
first.text,
|
||||
'Three',
|
||||
'The first option was correct'
|
||||
);
|
||||
});
|
||||
|
||||
test('multiple default selections returned', function (assert) {
|
||||
var $select = $(
|
||||
'<select multiple>' +
|
||||
'<option selected>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'<option value="3" selected>Three</option>' +
|
||||
'</select>'
|
||||
);
|
||||
var options = new Options({});
|
||||
|
||||
var select = new Select2($select, options);
|
||||
|
||||
var items = select.data();
|
||||
|
||||
assert.equal(
|
||||
items.length,
|
||||
2,
|
||||
'The two selected items should be returned'
|
||||
);
|
||||
|
||||
var first = items[0];
|
||||
|
||||
assert.equal(
|
||||
first.id,
|
||||
'One',
|
||||
'The first option was correct'
|
||||
);
|
||||
|
||||
var second = items[1];
|
||||
|
||||
assert.equal(
|
||||
second.id,
|
||||
'3',
|
||||
'The option value should be pulled correctly'
|
||||
);
|
||||
});
|
||||
|
||||
module('select2(val)');
|
||||
|
||||
test('single value matches jquery value', function (assert) {
|
||||
var $select = $(
|
||||
'<select>' +
|
||||
'<option>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'<option value="3" selected>Three</option>' +
|
||||
'</select>'
|
||||
);
|
||||
var options = new Options({});
|
||||
|
||||
var select = new Select2($select, options);
|
||||
|
||||
var value = select.val();
|
||||
|
||||
assert.equal(
|
||||
value,
|
||||
'3',
|
||||
'The value should match the option tag attribute'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
value,
|
||||
$select.val(),
|
||||
'The value should match the jquery value'
|
||||
);
|
||||
});
|
||||
|
||||
test('multiple value matches the jquery value', function (assert) {
|
||||
var $select = $(
|
||||
'<select multiple>' +
|
||||
'<option selected>One</option>' +
|
||||
'<option>Two</option>' +
|
||||
'<option value="3" selected>Three</option>' +
|
||||
'</select>'
|
||||
);
|
||||
var options = new Options({});
|
||||
|
||||
var select = new Select2($select, options);
|
||||
|
||||
var value = select.val();
|
||||
|
||||
assert.equal(
|
||||
value.length,
|
||||
2,
|
||||
'Two options should be selected'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
value,
|
||||
['One', '3'],
|
||||
'The values should match the option tag attribute'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
value,
|
||||
$select.val(),
|
||||
'The values should match the jquery values'
|
||||
);
|
||||
});
|
Reference in New Issue
Block a user