width-tests.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. module('Options - Width');
  2. var $ = require('jquery');
  3. var Select2 = require('select2/core');
  4. var select = new Select2($('<select></select>'));
  5. test('string passed as width', function (assert) {
  6. var $test = $('<select></select>');
  7. var width = select._resolveWidth($test, '80%');
  8. assert.equal(width, '80%');
  9. });
  10. test('width from style attribute', function (assert) {
  11. var $test = $('<select style="width: 50%;"></selct>');
  12. var width = select._resolveWidth($test, 'style');
  13. assert.equal(width, '50%');
  14. });
  15. test('width from style returns null if nothing is found', function (assert) {
  16. var $test = $('<select></selct>');
  17. var width = select._resolveWidth($test, 'style');
  18. assert.equal(width, null);
  19. });
  20. test('width from computer element width', function (assert) {
  21. var $test = $('<select class="css-set-width"></select>');
  22. $('#qunit-fixture').append($test);
  23. var width = select._resolveWidth($test, 'element');
  24. assert.equal(width, '500px');
  25. });
  26. test('resolve gets the style if it is there', function (assert) {
  27. var $test = $('<select style="width: 20%;"></selct>');
  28. var width = select._resolveWidth($test, 'resolve');
  29. assert.equal(width, '20%');
  30. });
  31. test('resolve falls back to element if there is no style', function (assert) {
  32. var $test = $('<select class="css-set-width"></select>');
  33. $('#qunit-fixture').append($test);
  34. var width = select._resolveWidth($test, 'resolve');
  35. assert.equal(width, '500px');
  36. });