width-tests.js 1.4 KB

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