No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery-calls.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. module('select2(val)');
  2. var Utils = require('select2/utils');
  3. test('multiple elements with arguments works', function (assert) {
  4. var $ = require('jquery');
  5. require('jquery.select2');
  6. var $first = $(
  7. '<select>' +
  8. '<option>1</option>' +
  9. '<option>2</option>' +
  10. '</select>'
  11. );
  12. var $second = $first.clone();
  13. var $both = $first.add($second);
  14. $both.select2();
  15. $both.select2('val', '2');
  16. assert.equal(
  17. $first.val(),
  18. '2',
  19. 'The call should change the value on the first element'
  20. );
  21. assert.equal(
  22. $second.val(),
  23. '2',
  24. 'The call should also change the value on the second element'
  25. );
  26. });
  27. test('initializes when jQuery $.data contains' +
  28. ' cyclic reference', function (assert) {
  29. var $ = require('jquery');
  30. require('jquery.select2');
  31. var $select = $(
  32. '<select>' +
  33. '<option>One</option>' +
  34. '<option>Two</option>' +
  35. '<option value="3" selected>Three</option>' +
  36. '</select>'
  37. );
  38. // Add a circular reference object using jQuery.
  39. var recursiveObject = {};
  40. recursiveObject.same = recursiveObject;
  41. $select.data('same', recursiveObject);
  42. $select.select2();
  43. assert.equal(
  44. $select.val(),
  45. '3',
  46. 'The option value should be pulled correctly'
  47. );
  48. });
  49. test('$element.data returns instance and options correctly',
  50. function (assert) {
  51. var $ = require('jquery');
  52. require('jquery.select2');
  53. var $select = $(
  54. '<select>' +
  55. '<option value="1">One</option>' +
  56. '<option value="2">Two</option>' +
  57. '<option value="3" selected>Three</option>' +
  58. '</select>'
  59. );
  60. // Initialize.
  61. $select.select2({maximumSelectionLength: 2, multiple: true});
  62. assert.equal(
  63. $select.val(),
  64. '3',
  65. 'Only 1 option should be pulled.'
  66. );
  67. // Try to resolve instance via .data('select2').
  68. var $instance = $select.data('select2');
  69. assert.ok($instance);
  70. assert.ok($instance.options);
  71. // Ensure $select.data('select2') is the same instance
  72. // created by .select2()
  73. assert.equal($instance, Utils.GetData($instance.$element[0],
  74. 'select2'));
  75. // Ensure initialized property matches.
  76. assert.equal($instance.options.options.maximumSelectionLength,
  77. 2);
  78. });