dropdownCss-tests.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. module('Dropdown - dropdownCssClass compatibility');
  2. var $ = require('jquery');
  3. var Utils = require('select2/utils');
  4. var Options = require('select2/options');
  5. var Dropdown = require('select2/dropdown');
  6. var DropdownCSS = Utils.Decorate(
  7. Dropdown,
  8. require('select2/compat/dropdownCss')
  9. );
  10. test('all classes will be copied if :all: is used', function (assert) {
  11. var $element = $('<select class="test copy works"></select>');
  12. var options = new Options({
  13. dropdownCssClass: ':all:'
  14. });
  15. var select = new DropdownCSS($element, options);
  16. var $dropdown = select.render();
  17. assert.ok($dropdown.hasClass('test'));
  18. assert.ok($dropdown.hasClass('copy'));
  19. assert.ok($dropdown.hasClass('works'));
  20. assert.ok(!$dropdown.hasClass(':all:'));
  21. });
  22. test(':all: can be used with other classes', function (assert) {
  23. var $element = $('<select class="test copy works"></select>');
  24. var options = new Options({
  25. dropdownCssClass: ':all: other'
  26. });
  27. var select = new DropdownCSS($element, options);
  28. var $dropdown = select.render();
  29. assert.ok($dropdown.hasClass('test'));
  30. assert.ok($dropdown.hasClass('copy'));
  31. assert.ok($dropdown.hasClass('works'));
  32. assert.ok($dropdown.hasClass('other'));
  33. assert.ok(!$dropdown.hasClass(':all:'));
  34. });
  35. test('classes can be passed in as a string', function (assert) {
  36. var $element = $('<select class="test copy works"></select>');
  37. var options = new Options({
  38. dropdownCssClass: 'other'
  39. });
  40. var select = new DropdownCSS($element, options);
  41. var $dropdown = select.render();
  42. assert.ok($dropdown.hasClass('other'));
  43. });
  44. test('a function can be used based on the element', function (assert){
  45. var $element = $('<select class="test"></select>');
  46. var options = new Options({
  47. dropdownCssClass: function ($element) {
  48. return 'function';
  49. }
  50. });
  51. var select = new DropdownCSS($element, options);
  52. var $dropdown = select.render();
  53. assert.ok($dropdown.hasClass('function'));
  54. assert.ok(!$dropdown.hasClass('test'));
  55. });
  56. test(':all: works around custom adapters', function (assert) {
  57. var $element = $('<select class="test"></select>');
  58. var options = new Options({
  59. dropdownCssClass: ':all: something',
  60. adaptDropdownCssClass: function (clazz) {
  61. return clazz + '-modified';
  62. }
  63. });
  64. var select = new DropdownCSS($element, options);
  65. var $dropdown = select.render();
  66. assert.ok($dropdown.hasClass('something'));
  67. assert.ok($dropdown.hasClass('test'));
  68. assert.ok($dropdown.hasClass('test-modified'));
  69. });
  70. module('Dropdown - adaptDropdownCss compatibility');
  71. test('only return when adapted', function (assert) {
  72. var $element = $('<select class="original"></select>');
  73. var options = new Options({
  74. adaptDropdownCssClass: function (clazz) {
  75. return 'modified';
  76. }
  77. });
  78. var select = new DropdownCSS($element, options);
  79. var $dropdown = select.render();
  80. assert.ok(!$dropdown.hasClass('original'));
  81. assert.ok($dropdown.hasClass('modified'));
  82. });