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.

infiniteScroll-tests.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. module('Results - Infinite scrolling');
  2. test('loadingMore is triggered even without a scrollbar', function (assert) {
  3. assert.expect(1);
  4. var $ = require('jquery');
  5. var $select = $('<select></select>');
  6. var $container = $('<span></span>');
  7. var container = new MockContainer();
  8. var Utils = require('select2/utils');
  9. var Options = require('select2/options');
  10. var Results = require('select2/results');
  11. var InfiniteScroll = require('select2/dropdown/infiniteScroll');
  12. var InfiniteScrollResults = Utils.Decorate(Results, InfiniteScroll);
  13. var results = new InfiniteScrollResults($select, new Options({}));
  14. // Fake the data adapter for the `setClasses` method
  15. results.data = {};
  16. results.data.current = function (callback) {
  17. callback([{ id: 'test' }]);
  18. };
  19. $('#qunit-fixture').append(results.render());
  20. results.bind(container, $container);
  21. results.on('query:append', function () {
  22. assert.ok(true, 'It tried to load more immediately');
  23. });
  24. container.trigger('results:all', {
  25. data: {
  26. results: [
  27. {
  28. id: 'test',
  29. text: 'Test'
  30. }
  31. ],
  32. pagination: {
  33. more: true
  34. }
  35. }
  36. });
  37. });
  38. test('loadingMore is not triggered without scrolling', function (assert) {
  39. assert.expect(0);
  40. var $ = require('jquery');
  41. var $select = $('<select></select>');
  42. var $container = $('<span></span>');
  43. var container = new MockContainer();
  44. var Utils = require('select2/utils');
  45. var Options = require('select2/options');
  46. var Results = require('select2/results');
  47. var InfiniteScroll = require('select2/dropdown/infiniteScroll');
  48. var InfiniteScrollResults = Utils.Decorate(Results, InfiniteScroll);
  49. var results = new InfiniteScrollResults($select, new Options({}));
  50. // Fake the data adapter for the `setClasses` method
  51. results.data = {};
  52. results.data.current = function (callback) {
  53. callback([{ id: 'test' }]);
  54. };
  55. var $results = results.render();
  56. $('#qunit-fixture').append($results);
  57. $results.css('max-height', '100px');
  58. results.bind(container, $container);
  59. results.on('query:append', function () {
  60. assert.ok(false, 'It tried to load more immediately');
  61. });
  62. container.trigger('results:all', {
  63. data: {
  64. results: [
  65. {
  66. id: 'test',
  67. text: 'Test'
  68. },
  69. {
  70. id: 'test',
  71. text: 'Test'
  72. },
  73. {
  74. id: 'test',
  75. text: 'Test'
  76. },
  77. {
  78. id: 'test',
  79. text: 'Test'
  80. },
  81. {
  82. id: 'test',
  83. text: 'Test'
  84. },
  85. {
  86. id: 'test',
  87. text: 'Test'
  88. },
  89. {
  90. id: 'test',
  91. text: 'Test'
  92. }
  93. ],
  94. pagination: {
  95. more: true
  96. }
  97. }
  98. });
  99. });