mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	add static files
This commit is contained in:
		
							
								
								
									
										330
									
								
								static/vendor/select2/tests/selection/allowClear-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										330
									
								
								static/vendor/select2/tests/selection/allowClear-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,330 @@
 | 
			
		||||
module('Selection containers - Placeholders - Allow clear');
 | 
			
		||||
 | 
			
		||||
var Placeholder = require('select2/selection/placeholder');
 | 
			
		||||
var AllowClear = require('select2/selection/allowClear');
 | 
			
		||||
 | 
			
		||||
var SingleSelection = require('select2/selection/single');
 | 
			
		||||
 | 
			
		||||
var $ = require('jquery');
 | 
			
		||||
var Options = require('select2/options');
 | 
			
		||||
var Utils = require('select2/utils');
 | 
			
		||||
 | 
			
		||||
var AllowClearPlaceholder = Utils.Decorate(
 | 
			
		||||
  Utils.Decorate(SingleSelection, Placeholder),
 | 
			
		||||
  AllowClear
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
var allowClearOptions = new Options({
 | 
			
		||||
  placeholder: {
 | 
			
		||||
    id: 'placeholder',
 | 
			
		||||
    text: 'This is the placeholder'
 | 
			
		||||
  },
 | 
			
		||||
  allowClear: true
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clear is not displayed for single placeholder', function (assert) {
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $('#qunit-fixture .single-with-placeholder'),
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'placeholder'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $selection.find('.select2-selection__clear').length,
 | 
			
		||||
    0,
 | 
			
		||||
    'The clear icon should not be displayed'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clear is not displayed for multiple placeholder', function (assert) {
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $('#qunit-fixture .multiple'),
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.update([]);
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $selection.find('.select2-selection__clear').length,
 | 
			
		||||
    0,
 | 
			
		||||
    'The clear icon should not be displayed'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
test('clear is displayed for placeholder', function (assert) {
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $('#qunit-fixture .single-with-placeholder'),
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'one',
 | 
			
		||||
    test: 'one'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $selection.find('.select2-selection__clear').length,
 | 
			
		||||
    1,
 | 
			
		||||
    'The clear icon should be displayed'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clear icon should have title displayed', function (assert) {
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $('#qunit-fixture .single-with-placeholder'),
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'one',
 | 
			
		||||
    test: 'one'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $selection.find('.select2-selection__clear').attr('title'),
 | 
			
		||||
    'Remove all items',
 | 
			
		||||
    'The clear icon should have title displayed'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clicking clear will set the placeholder value', function (assert) {
 | 
			
		||||
  var $element = $('#qunit-fixture .single-with-placeholder');
 | 
			
		||||
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $element,
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.bind(container, $('<div></div>'));
 | 
			
		||||
 | 
			
		||||
  $element.val('One');
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'One',
 | 
			
		||||
    text: 'One'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  var $remove = $selection.find('.select2-selection__clear');
 | 
			
		||||
  $remove.trigger('mousedown');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $element.val(),
 | 
			
		||||
    'placeholder',
 | 
			
		||||
    'The value should have been reset to the placeholder'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clicking clear will trigger the unselect event', function (assert) {
 | 
			
		||||
  assert.expect(4);
 | 
			
		||||
 | 
			
		||||
  var $element = $('#qunit-fixture .single-with-placeholder');
 | 
			
		||||
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $element,
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.bind(container, $('<div></div>'));
 | 
			
		||||
 | 
			
		||||
  $element.val('One');
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'One',
 | 
			
		||||
    text: 'One'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  selection.on('unselect', function (ev) {
 | 
			
		||||
    assert.ok(
 | 
			
		||||
      'data' in ev && ev.data,
 | 
			
		||||
      'The event should have been triggered with the data property'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.ok(
 | 
			
		||||
      $.isPlainObject(ev.data),
 | 
			
		||||
      'The data should be an object'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
      ev.data.id,
 | 
			
		||||
      'One',
 | 
			
		||||
      'The data should be the unselected object'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
      $element.val(),
 | 
			
		||||
      'placeholder',
 | 
			
		||||
      'The previous value should be unselected'
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var $remove = $selection.find('.select2-selection__clear');
 | 
			
		||||
  $remove.trigger('mousedown');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('preventing the unselect event cancels the clearing', function (assert) {
 | 
			
		||||
  var $element = $('#qunit-fixture .single-with-placeholder');
 | 
			
		||||
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $element,
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.bind(container, $('<div></div>'));
 | 
			
		||||
 | 
			
		||||
  $element.val('One');
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'One',
 | 
			
		||||
    text: 'One'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  selection.on('unselect', function (ev) {
 | 
			
		||||
    ev.prevented = true;
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var $remove = $selection.find('.select2-selection__clear');
 | 
			
		||||
  $remove.trigger('mousedown');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $element.val(),
 | 
			
		||||
    'One',
 | 
			
		||||
    'The placeholder should not have been set'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clicking clear will trigger the clear event', function (assert) {
 | 
			
		||||
  assert.expect(5);
 | 
			
		||||
 | 
			
		||||
  var $element = $('#qunit-fixture .single-with-placeholder');
 | 
			
		||||
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $element,
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.bind(container, $('<div></div>'));
 | 
			
		||||
 | 
			
		||||
  $element.val('One');
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'One',
 | 
			
		||||
    text: 'One'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  selection.on('clear', function (ev) {
 | 
			
		||||
    assert.ok(
 | 
			
		||||
      'data' in ev && ev.data,
 | 
			
		||||
      'The event should have been triggered with the data property'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.ok(
 | 
			
		||||
      $.isArray(ev.data),
 | 
			
		||||
      'The data should be an array'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
      ev.data.length,
 | 
			
		||||
      1,
 | 
			
		||||
      'The data should contain one item for each value'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
      ev.data[0].id,
 | 
			
		||||
      'One',
 | 
			
		||||
      'The data should contain unselected objects'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
      $element.val(),
 | 
			
		||||
      'placeholder',
 | 
			
		||||
      'The previous value should be unselected'
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var $remove = $selection.find('.select2-selection__clear');
 | 
			
		||||
  $remove.trigger('mousedown');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('preventing the clear event cancels the clearing', function (assert) {
 | 
			
		||||
  var $element = $('#qunit-fixture .single-with-placeholder');
 | 
			
		||||
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $element,
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.bind(container, $('<div></div>'));
 | 
			
		||||
 | 
			
		||||
  $element.val('One');
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'One',
 | 
			
		||||
    text: 'One'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  selection.on('clear', function (ev) {
 | 
			
		||||
    ev.prevented = true;
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var $remove = $selection.find('.select2-selection__clear');
 | 
			
		||||
  $remove.trigger('mousedown');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $element.val(),
 | 
			
		||||
    'One',
 | 
			
		||||
    'The placeholder should not have been set'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clear does not work when disabled', function (assert) {
 | 
			
		||||
  var $element = $('#qunit-fixture .single-with-placeholder');
 | 
			
		||||
 | 
			
		||||
  var selection = new AllowClearPlaceholder(
 | 
			
		||||
    $element,
 | 
			
		||||
    allowClearOptions
 | 
			
		||||
  );
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.bind(container, $('<div></div>'));
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'One',
 | 
			
		||||
    text: 'One'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  $element.val('One');
 | 
			
		||||
  selection.options.set('disabled', true);
 | 
			
		||||
 | 
			
		||||
  var $remove = $selection.find('.select2-selection__clear');
 | 
			
		||||
  $remove.trigger('mousedown');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $element.val(),
 | 
			
		||||
    'One',
 | 
			
		||||
    'The placeholder should not have been set'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										104
									
								
								static/vendor/select2/tests/selection/containerCss-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								static/vendor/select2/tests/selection/containerCss-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,104 @@
 | 
			
		||||
module('Dropdown - containerCssClass compatibility');
 | 
			
		||||
 | 
			
		||||
var $ = require('jquery');
 | 
			
		||||
var Utils = require('select2/utils');
 | 
			
		||||
var Options = require('select2/options');
 | 
			
		||||
 | 
			
		||||
var SingleSelection = require('select2/selection/single');
 | 
			
		||||
var ContainerCSS = Utils.Decorate(
 | 
			
		||||
  SingleSelection,
 | 
			
		||||
  require('select2/compat/containerCss')
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
test('all classes will be copied if :all: is used', function (assert) {
 | 
			
		||||
  var $element = $('<select class="test copy works"></select>');
 | 
			
		||||
  var options = new Options({
 | 
			
		||||
    containerCssClass: ':all:'
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var select = new ContainerCSS($element, options);
 | 
			
		||||
  var $container = select.render();
 | 
			
		||||
 | 
			
		||||
  assert.ok($container.hasClass('test'));
 | 
			
		||||
  assert.ok($container.hasClass('copy'));
 | 
			
		||||
  assert.ok($container.hasClass('works'));
 | 
			
		||||
  assert.ok(!$container.hasClass(':all:'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test(':all: can be used with other classes', function (assert) {
 | 
			
		||||
  var $element = $('<select class="test copy works"></select>');
 | 
			
		||||
  var options = new Options({
 | 
			
		||||
    containerCssClass: ':all: other'
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var select = new ContainerCSS($element, options);
 | 
			
		||||
  var $container = select.render();
 | 
			
		||||
 | 
			
		||||
  assert.ok($container.hasClass('test'));
 | 
			
		||||
  assert.ok($container.hasClass('copy'));
 | 
			
		||||
  assert.ok($container.hasClass('works'));
 | 
			
		||||
  assert.ok($container.hasClass('other'));
 | 
			
		||||
  assert.ok(!$container.hasClass(':all:'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('classes can be passed in as a string', function (assert) {
 | 
			
		||||
  var $element = $('<select class="test copy works"></select>');
 | 
			
		||||
  var options = new Options({
 | 
			
		||||
    containerCssClass: 'other'
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var select = new ContainerCSS($element, options);
 | 
			
		||||
  var $container = select.render();
 | 
			
		||||
 | 
			
		||||
  assert.ok($container.hasClass('other'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('a function can be used based on the element', function (assert){
 | 
			
		||||
  var $element = $('<select class="test"></select>');
 | 
			
		||||
  var options = new Options({
 | 
			
		||||
    containerCssClass: function ($element) {
 | 
			
		||||
      return 'function';
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var select = new ContainerCSS($element, options);
 | 
			
		||||
  var $container = select.render();
 | 
			
		||||
 | 
			
		||||
  assert.ok($container.hasClass('function'));
 | 
			
		||||
  assert.ok(!$container.hasClass('test'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test(':all: works around custom adapters', function (assert) {
 | 
			
		||||
  var $element = $('<select class="test"></select>');
 | 
			
		||||
  var options = new Options({
 | 
			
		||||
    containerCssClass: ':all: something',
 | 
			
		||||
    adaptContainerCssClass: function (clazz) {
 | 
			
		||||
      return clazz + '-modified';
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var select = new ContainerCSS($element, options);
 | 
			
		||||
  var $container = select.render();
 | 
			
		||||
 | 
			
		||||
  assert.ok($container.hasClass('something'));
 | 
			
		||||
 | 
			
		||||
  assert.ok($container.hasClass('test'));
 | 
			
		||||
  assert.ok($container.hasClass('test-modified'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
module('Selection - adaptContainerCss compatibility');
 | 
			
		||||
 | 
			
		||||
test('only return when adapted', function (assert) {
 | 
			
		||||
  var $element = $('<select class="original"></select>');
 | 
			
		||||
  var options = new Options({
 | 
			
		||||
    adaptContainerCssClass: function (clazz) {
 | 
			
		||||
      return 'modified';
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var select = new ContainerCSS($element, options);
 | 
			
		||||
  var $container = select.render();
 | 
			
		||||
 | 
			
		||||
  assert.ok(!$container.hasClass('original'));
 | 
			
		||||
  assert.ok($container.hasClass('modified'));
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										151
									
								
								static/vendor/select2/tests/selection/multiple-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								static/vendor/select2/tests/selection/multiple-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,151 @@
 | 
			
		||||
module('Selection containers - Multiple');
 | 
			
		||||
 | 
			
		||||
var MultipleSelection = require('select2/selection/multiple');
 | 
			
		||||
 | 
			
		||||
var $ = require('jquery');
 | 
			
		||||
var Options = require('select2/options');
 | 
			
		||||
var Utils = require('select2/utils');
 | 
			
		||||
 | 
			
		||||
var options = new Options({});
 | 
			
		||||
 | 
			
		||||
test('display uses templateSelection', function (assert) {
 | 
			
		||||
  var called = false;
 | 
			
		||||
 | 
			
		||||
  var templateOptions = new Options({
 | 
			
		||||
    templateSelection: function (data) {
 | 
			
		||||
      called = true;
 | 
			
		||||
 | 
			
		||||
      return data.text;
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var selection = new MultipleSelection(
 | 
			
		||||
    $('#qunit-fixture .multiple'),
 | 
			
		||||
    templateOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var out = selection.display({
 | 
			
		||||
    text: 'test'
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  assert.ok(called);
 | 
			
		||||
 | 
			
		||||
  assert.equal(out, 'test');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('templateSelection can addClass', function (assert) {
 | 
			
		||||
  var called = false;
 | 
			
		||||
 | 
			
		||||
  var templateOptions = new Options({
 | 
			
		||||
    templateSelection: function (data, container) {
 | 
			
		||||
      called = true;
 | 
			
		||||
      container.addClass('testclass');
 | 
			
		||||
      return data.text;
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var selection = new MultipleSelection(
 | 
			
		||||
    $('#qunit-fixture .multiple'),
 | 
			
		||||
    templateOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $container = selection.selectionContainer();
 | 
			
		||||
 | 
			
		||||
  var out = selection.display({
 | 
			
		||||
    text: 'test'
 | 
			
		||||
  }, $container);
 | 
			
		||||
 | 
			
		||||
  assert.ok(called);
 | 
			
		||||
 | 
			
		||||
  assert.equal(out, 'test');
 | 
			
		||||
 | 
			
		||||
  assert.ok($container.hasClass('testclass'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('empty update clears the selection', function (assert) {
 | 
			
		||||
  var selection = new MultipleSelection(
 | 
			
		||||
    $('#qunit-fixture .multiple'),
 | 
			
		||||
    options
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  var $rendered = $selection.find('.select2-selection__rendered');
 | 
			
		||||
 | 
			
		||||
  $rendered.text('testing');
 | 
			
		||||
  $rendered.attr('title', 'testing');
 | 
			
		||||
 | 
			
		||||
  selection.update([]);
 | 
			
		||||
 | 
			
		||||
  assert.equal($rendered.text(), '');
 | 
			
		||||
  assert.equal($rendered.attr('title'), undefined);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('escapeMarkup is being used', function (assert) {
 | 
			
		||||
  var selection = new MultipleSelection(
 | 
			
		||||
    $('#qunit-fixture .multiple'),
 | 
			
		||||
    options
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  var $rendered = $selection.find('.select2-selection__rendered');
 | 
			
		||||
 | 
			
		||||
  var unescapedText = '<script>bad("stuff");</script>';
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    text: unescapedText
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $rendered.text().substr(1),
 | 
			
		||||
    unescapedText,
 | 
			
		||||
    'The text should be escaped by default to prevent injection'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('clear button respects the disabled state', function (assert) {
 | 
			
		||||
  var options = new Options({
 | 
			
		||||
    disabled: true
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var $select = $('#qunit-fixture .multiple');
 | 
			
		||||
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
  var $container = $('<div></div>');
 | 
			
		||||
 | 
			
		||||
  var selection = new MultipleSelection(
 | 
			
		||||
    $select,
 | 
			
		||||
    options
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  $container.append($selection);
 | 
			
		||||
 | 
			
		||||
  selection.bind(container, $container);
 | 
			
		||||
 | 
			
		||||
  // Select an option
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    text: 'Test'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  var $rendered = $selection.find('.select2-selection__rendered');
 | 
			
		||||
 | 
			
		||||
  var $pill = $rendered.find('.select2-selection__choice');
 | 
			
		||||
 | 
			
		||||
  assert.equal($pill.length, 1, 'There should only be one selection');
 | 
			
		||||
 | 
			
		||||
  var $remove = $pill.find('.select2-selection__choice__remove');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $remove.length,
 | 
			
		||||
    1,
 | 
			
		||||
    'The remove icon is displayed for the selection'
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  // Set up the unselect handler
 | 
			
		||||
  selection.on('unselect', function (params) {
 | 
			
		||||
    assert.ok(false, 'The unselect handler should not be triggered');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  // Trigger the handler for the remove icon
 | 
			
		||||
  $remove.trigger('click');
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										74
									
								
								static/vendor/select2/tests/selection/placeholder-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								static/vendor/select2/tests/selection/placeholder-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
module('Selection containers - Placeholders');
 | 
			
		||||
 | 
			
		||||
var Placeholder = require('select2/selection/placeholder');
 | 
			
		||||
var SingleSelection = require('select2/selection/single');
 | 
			
		||||
 | 
			
		||||
var $ = require('jquery');
 | 
			
		||||
var Options = require('select2/options');
 | 
			
		||||
var Utils = require('select2/utils');
 | 
			
		||||
 | 
			
		||||
var SinglePlaceholder = Utils.Decorate(SingleSelection, Placeholder);
 | 
			
		||||
 | 
			
		||||
var placeholderOptions = new Options({
 | 
			
		||||
  placeholder: {
 | 
			
		||||
    id: 'placeholder',
 | 
			
		||||
    text: 'This is the placeholder'
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('normalizing placeholder ignores objects', function (assert) {
 | 
			
		||||
  var selection = new SinglePlaceholder(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    placeholderOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var original = {
 | 
			
		||||
    id: 'test',
 | 
			
		||||
    text: 'testing'
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  var normalized = selection.normalizePlaceholder(original);
 | 
			
		||||
 | 
			
		||||
  assert.equal(original, normalized);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('normalizing placeholder gives object for string', function (assert) {
 | 
			
		||||
  var selection = new SinglePlaceholder(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    placeholderOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var normalized = selection.normalizePlaceholder('placeholder');
 | 
			
		||||
 | 
			
		||||
  assert.equal(normalized.id, '');
 | 
			
		||||
  assert.equal(normalized.text, 'placeholder');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
test('text is shown for placeholder option on single', function (assert) {
 | 
			
		||||
  var selection = new SinglePlaceholder(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    placeholderOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    id: 'placeholder'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  assert.equal($selection.text(), 'This is the placeholder');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('placeholder is shown when no options are selected', function (assert) {
 | 
			
		||||
  var selection = new SinglePlaceholder(
 | 
			
		||||
    $('#qunit-fixture .multiple'),
 | 
			
		||||
    placeholderOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
 | 
			
		||||
  selection.update([]);
 | 
			
		||||
 | 
			
		||||
  assert.equal($selection.text(), 'This is the placeholder');
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										191
									
								
								static/vendor/select2/tests/selection/search-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								static/vendor/select2/tests/selection/search-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,191 @@
 | 
			
		||||
module('Selection containers - Inline search');
 | 
			
		||||
 | 
			
		||||
var MultipleSelection = require('select2/selection/multiple');
 | 
			
		||||
var InlineSearch = require('select2/selection/search');
 | 
			
		||||
 | 
			
		||||
var $ = require('jquery');
 | 
			
		||||
var Options = require('select2/options');
 | 
			
		||||
var Utils = require('select2/utils');
 | 
			
		||||
 | 
			
		||||
var options = new Options({});
 | 
			
		||||
 | 
			
		||||
test('backspace will remove a choice', function (assert) {
 | 
			
		||||
  assert.expect(3);
 | 
			
		||||
 | 
			
		||||
  var KEYS = require('select2/keys');
 | 
			
		||||
 | 
			
		||||
  var $container = $('#qunit-fixture .event-container');
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
 | 
			
		||||
 | 
			
		||||
  var $element = $('#qunit-fixture .multiple');
 | 
			
		||||
  var selection = new CustomSelection($element, options);
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  selection.bind(container, $container);
 | 
			
		||||
 | 
			
		||||
  // The unselect event should be triggered at some point
 | 
			
		||||
  selection.on('unselect', function () {
 | 
			
		||||
    assert.ok(true, 'A choice was unselected');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  // Add some selections and render the search
 | 
			
		||||
  selection.update([
 | 
			
		||||
    {
 | 
			
		||||
      id: '1',
 | 
			
		||||
      text: 'One'
 | 
			
		||||
    }
 | 
			
		||||
  ]);
 | 
			
		||||
 | 
			
		||||
  var $search = $selection.find('input');
 | 
			
		||||
  var $choices = $selection.find('.select2-selection__choice');
 | 
			
		||||
 | 
			
		||||
  assert.equal($search.length, 1, 'The search was visible');
 | 
			
		||||
  assert.equal($choices.length, 1, 'The choice was rendered');
 | 
			
		||||
 | 
			
		||||
  // Trigger the backspace on the search
 | 
			
		||||
  var backspace = $.Event('keydown', {
 | 
			
		||||
    which: KEYS.BACKSPACE
 | 
			
		||||
  });
 | 
			
		||||
  $search.trigger(backspace);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('backspace will set the search text', function (assert) {
 | 
			
		||||
  assert.expect(3);
 | 
			
		||||
 | 
			
		||||
  var KEYS = require('select2/keys');
 | 
			
		||||
 | 
			
		||||
  var $container = $('#qunit-fixture .event-container');
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
 | 
			
		||||
 | 
			
		||||
  var $element = $('#qunit-fixture .multiple');
 | 
			
		||||
  var selection = new CustomSelection($element, options);
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  selection.bind(container, $container);
 | 
			
		||||
 | 
			
		||||
  // Add some selections and render the search
 | 
			
		||||
  selection.update([
 | 
			
		||||
    {
 | 
			
		||||
      id: '1',
 | 
			
		||||
      text: 'One'
 | 
			
		||||
    }
 | 
			
		||||
  ]);
 | 
			
		||||
 | 
			
		||||
  var $search = $selection.find('input');
 | 
			
		||||
  var $choices = $selection.find('.select2-selection__choice');
 | 
			
		||||
 | 
			
		||||
  assert.equal($search.length, 1, 'The search was visible');
 | 
			
		||||
  assert.equal($choices.length, 1, 'The choice was rendered');
 | 
			
		||||
 | 
			
		||||
  // Trigger the backspace on the search
 | 
			
		||||
  var backspace = $.Event('keydown', {
 | 
			
		||||
    which: KEYS.BACKSPACE
 | 
			
		||||
  });
 | 
			
		||||
  $search.trigger(backspace);
 | 
			
		||||
 | 
			
		||||
  assert.equal($search.val(), 'One', 'The search text was set');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('updating selection does not shift the focus', function (assert) {
 | 
			
		||||
  // Check for IE 8, which triggers a false negative during testing
 | 
			
		||||
  if (window.attachEvent && !window.addEventListener) {
 | 
			
		||||
    // We must expect 0 assertions or the test will fail
 | 
			
		||||
    assert.expect(0);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  var $container = $('#qunit-fixture .event-container');
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
 | 
			
		||||
 | 
			
		||||
  var $element = $('#qunit-fixture .multiple');
 | 
			
		||||
  var selection = new CustomSelection($element, options);
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  selection.bind(container, $container);
 | 
			
		||||
 | 
			
		||||
  // Update the selection so the search is rendered
 | 
			
		||||
  selection.update([]);
 | 
			
		||||
 | 
			
		||||
  // Make it visible so the browser can place focus on the search
 | 
			
		||||
  $container.append($selection);
 | 
			
		||||
 | 
			
		||||
  var $search = $selection.find('input');
 | 
			
		||||
  $search.trigger('focus');
 | 
			
		||||
 | 
			
		||||
  assert.equal($search.length, 1, 'The search was not visible');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    document.activeElement,
 | 
			
		||||
    $search[0],
 | 
			
		||||
    'The search did not have focus originally'
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  // Trigger an update, this should redraw the search box
 | 
			
		||||
  selection.update([]);
 | 
			
		||||
 | 
			
		||||
  assert.equal($search.length, 1, 'The search box disappeared');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    document.activeElement,
 | 
			
		||||
    $search[0],
 | 
			
		||||
    'The search did not have focus after the selection was updated'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('the focus event shifts the focus', function (assert) {
 | 
			
		||||
  // Check for IE 8, which triggers a false negative during testing
 | 
			
		||||
  if (window.attachEvent && !window.addEventListener) {
 | 
			
		||||
    // We must expect 0 assertions or the test will fail
 | 
			
		||||
    assert.expect(0);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  var $container = $('#qunit-fixture .event-container');
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
 | 
			
		||||
 | 
			
		||||
  var $element = $('#qunit-fixture .multiple');
 | 
			
		||||
  var selection = new CustomSelection($element, options);
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  selection.bind(container, $container);
 | 
			
		||||
 | 
			
		||||
  // Update the selection so the search is rendered
 | 
			
		||||
  selection.update([]);
 | 
			
		||||
 | 
			
		||||
  // Make it visible so the browser can place focus on the search
 | 
			
		||||
  $container.append($selection);
 | 
			
		||||
 | 
			
		||||
  // The search should not be automatically focused
 | 
			
		||||
 | 
			
		||||
  var $search = $selection.find('input');
 | 
			
		||||
 | 
			
		||||
  assert.notEqual(
 | 
			
		||||
    document.activeElement,
 | 
			
		||||
    $search[0],
 | 
			
		||||
    'The search had focus originally'
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  assert.equal($search.length, 1, 'The search was not visible');
 | 
			
		||||
 | 
			
		||||
  // Focus the container
 | 
			
		||||
 | 
			
		||||
  container.trigger('focus');
 | 
			
		||||
 | 
			
		||||
  // Make sure it focuses the search
 | 
			
		||||
 | 
			
		||||
  assert.equal($search.length, 1, 'The search box disappeared');
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    document.activeElement,
 | 
			
		||||
    $search[0],
 | 
			
		||||
    'The search did not have focus originally'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										119
									
								
								static/vendor/select2/tests/selection/single-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								static/vendor/select2/tests/selection/single-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,119 @@
 | 
			
		||||
module('Selection containers - Single');
 | 
			
		||||
 | 
			
		||||
var SingleSelection = require('select2/selection/single');
 | 
			
		||||
 | 
			
		||||
var $ = require('jquery');
 | 
			
		||||
var Options = require('select2/options');
 | 
			
		||||
var Utils = require('select2/utils');
 | 
			
		||||
 | 
			
		||||
var options = new Options({});
 | 
			
		||||
 | 
			
		||||
test('display uses templateSelection', function (assert) {
 | 
			
		||||
  var called = false;
 | 
			
		||||
 | 
			
		||||
  var templateOptions = new Options({
 | 
			
		||||
    templateSelection: function (data) {
 | 
			
		||||
      called = true;
 | 
			
		||||
 | 
			
		||||
      return data.text;
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var selection = new SingleSelection(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    templateOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var out = selection.display({
 | 
			
		||||
    text: 'test'
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  assert.ok(called);
 | 
			
		||||
 | 
			
		||||
  assert.equal(out, 'test');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('templateSelection can addClass', function (assert) {
 | 
			
		||||
  var called = false;
 | 
			
		||||
 | 
			
		||||
  var templateOptions = new Options({
 | 
			
		||||
    templateSelection: function (data, container) {
 | 
			
		||||
      called = true;
 | 
			
		||||
      container.addClass('testclass');
 | 
			
		||||
      return data.text;
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  var selection = new SingleSelection(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    templateOptions
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $container = selection.selectionContainer();
 | 
			
		||||
  
 | 
			
		||||
  var out = selection.display({
 | 
			
		||||
    text: 'test'
 | 
			
		||||
  }, $container);
 | 
			
		||||
 | 
			
		||||
  assert.ok(called);
 | 
			
		||||
 | 
			
		||||
  assert.equal(out, 'test');
 | 
			
		||||
  
 | 
			
		||||
  assert.ok($container.hasClass('testclass'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('empty update clears the selection', function (assert) {
 | 
			
		||||
  var selection = new SingleSelection(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    options
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  var $rendered = $selection.find('.select2-selection__rendered');
 | 
			
		||||
 | 
			
		||||
  $rendered.text('testing');
 | 
			
		||||
  $rendered.attr('title', 'testing');
 | 
			
		||||
 | 
			
		||||
  selection.update([]);
 | 
			
		||||
 | 
			
		||||
  assert.equal($rendered.text(), '');
 | 
			
		||||
  assert.equal($rendered.attr('title'), undefined);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('update renders the data text', function (assert) {
 | 
			
		||||
  var selection = new SingleSelection(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    options
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  var $rendered = $selection.find('.select2-selection__rendered');
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    text: 'test'
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  assert.equal($rendered.text(), 'test');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('escapeMarkup is being used', function (assert) {
 | 
			
		||||
  var selection = new SingleSelection(
 | 
			
		||||
    $('#qunit-fixture .single'),
 | 
			
		||||
    options
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  var $rendered = $selection.find('.select2-selection__rendered');
 | 
			
		||||
 | 
			
		||||
  var unescapedText = '<script>bad("stuff");</script>';
 | 
			
		||||
 | 
			
		||||
  selection.update([{
 | 
			
		||||
    text: unescapedText
 | 
			
		||||
  }]);
 | 
			
		||||
 | 
			
		||||
  assert.equal(
 | 
			
		||||
    $rendered.text(),
 | 
			
		||||
    unescapedText,
 | 
			
		||||
    'The text should be escaped by default to prevent injection'
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										33
									
								
								static/vendor/select2/tests/selection/stopPropagation-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								static/vendor/select2/tests/selection/stopPropagation-tests.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
module('Selection containers - Stoping event propagation');
 | 
			
		||||
 | 
			
		||||
var SingleSelection = require('select2/selection/single');
 | 
			
		||||
var StopPropagation = require('select2/selection/stopPropagation');
 | 
			
		||||
 | 
			
		||||
var $ = require('jquery');
 | 
			
		||||
var Options = require('select2/options');
 | 
			
		||||
var Utils = require('select2/utils');
 | 
			
		||||
 | 
			
		||||
var CutomSelection = Utils.Decorate(SingleSelection, StopPropagation);
 | 
			
		||||
 | 
			
		||||
var options = new Options();
 | 
			
		||||
 | 
			
		||||
test('click event does not propagate', function (assert) {
 | 
			
		||||
  assert.expect(1);
 | 
			
		||||
 | 
			
		||||
  var $container = $('#qunit-fixture .event-container');
 | 
			
		||||
  var container = new MockContainer();
 | 
			
		||||
 | 
			
		||||
  var selection = new CutomSelection($('#qunit-fixture select'), options);
 | 
			
		||||
 | 
			
		||||
  var $selection = selection.render();
 | 
			
		||||
  selection.bind(container, $container);
 | 
			
		||||
 | 
			
		||||
  $container.append($selection);
 | 
			
		||||
  $container.on('click', function () {
 | 
			
		||||
    assert.ok(false, 'The click event should have been stopped');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $selection.trigger('click');
 | 
			
		||||
 | 
			
		||||
  assert.ok(true, 'Something went wrong if this failed');
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user