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.

placeholder-tests.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. module('Selection containers - Placeholders');
  2. var Placeholder = require('select2/selection/placeholder');
  3. var SingleSelection = require('select2/selection/single');
  4. var $ = require('jquery');
  5. var Options = require('select2/options');
  6. var Utils = require('select2/utils');
  7. var SinglePlaceholder = Utils.Decorate(SingleSelection, Placeholder);
  8. var placeholderOptions = new Options({
  9. placeholder: {
  10. id: 'placeholder',
  11. text: 'This is the placeholder'
  12. }
  13. });
  14. test('normalizing placeholder ignores objects', function (assert) {
  15. var selection = new SinglePlaceholder(
  16. $('#qunit-fixture .single'),
  17. placeholderOptions
  18. );
  19. var original = {
  20. id: 'test',
  21. text: 'testing'
  22. };
  23. var normalized = selection.normalizePlaceholder(original);
  24. assert.equal(original, normalized);
  25. });
  26. test('normalizing placeholder gives object for string', function (assert) {
  27. var selection = new SinglePlaceholder(
  28. $('#qunit-fixture .single'),
  29. placeholderOptions
  30. );
  31. var normalized = selection.normalizePlaceholder('placeholder');
  32. assert.equal(normalized.id, '');
  33. assert.equal(normalized.text, 'placeholder');
  34. });
  35. test('text is shown for placeholder option on single', function (assert) {
  36. var selection = new SinglePlaceholder(
  37. $('#qunit-fixture .single'),
  38. placeholderOptions
  39. );
  40. var $selection = selection.render();
  41. selection.update([{
  42. id: 'placeholder'
  43. }]);
  44. assert.equal($selection.text(), 'This is the placeholder');
  45. });
  46. test('placeholder is shown when no options are selected', function (assert) {
  47. var selection = new SinglePlaceholder(
  48. $('#qunit-fixture .multiple'),
  49. placeholderOptions
  50. );
  51. var $selection = selection.render();
  52. selection.update([]);
  53. assert.equal($selection.text(), 'This is the placeholder');
  54. });