scrollbarNative.spec.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. describe('WalkontableScrollbarNative', function () {
  2. var $table,
  3. $container,
  4. $wrapper,
  5. debug = false;
  6. beforeEach(function () {
  7. $wrapper = $('<div></div>').css({ overflow: 'hidden' });
  8. $wrapper.width(100).height(200);
  9. $container = $('<div></div>');
  10. $table = $('<table></table>'); // create a table that is not attached to document
  11. $wrapper.append($container);
  12. $container.append($table);
  13. $wrapper.appendTo('body');
  14. createDataArray();
  15. });
  16. afterEach(function () {
  17. if (!debug) {
  18. $('.wtHolder').remove();
  19. }
  20. $wrapper.remove();
  21. });
  22. it('initial render should be no different than the redraw (vertical)', function () {
  23. createDataArray(100, 1);
  24. var wt = new Walkontable.Core({
  25. table: $table[0],
  26. data: getData,
  27. totalRows: getTotalRows,
  28. totalColumns: getTotalColumns
  29. });
  30. wt.draw();
  31. var tds = $table.find('td').length;
  32. wt.draw();
  33. expect($table.find('td').length).toEqual(tds);
  34. });
  35. it('initial render should be no different than the redraw (horizontal)', function () {
  36. createDataArray(1, 50);
  37. var wt = new Walkontable.Core({
  38. table: $table[0],
  39. data: getData,
  40. totalRows: getTotalRows,
  41. totalColumns: getTotalColumns
  42. });
  43. wt.draw();
  44. var tds = $table.find('td').length;
  45. wt.draw();
  46. expect($table.find('td').length).toEqual(tds);
  47. });
  48. it('scrolling 50px down should render 2 more rows', function () {
  49. createDataArray(20, 4);
  50. var wt = new Walkontable.Core({
  51. table: $table[0],
  52. data: getData,
  53. totalRows: getTotalRows,
  54. totalColumns: getTotalColumns
  55. });
  56. wt.draw();
  57. var lastRenderedRow = wt.wtTable.getLastRenderedRow();
  58. $(wt.wtTable.holder).scrollTop(50);
  59. wt.draw();
  60. expect(wt.wtTable.getLastRenderedRow()).toEqual(lastRenderedRow + 2);
  61. });
  62. it('should recognize the scrollHandler properly, even if the \'overflow\' property is assigned in an external stylesheet', function () {
  63. $wrapper.css({
  64. overflow: ''
  65. });
  66. $wrapper.addClass('testOverflowHidden');
  67. createDataArray(20, 4);
  68. var wt = new Walkontable.Core({
  69. table: $table[0],
  70. data: getData,
  71. totalRows: getTotalRows,
  72. totalColumns: getTotalColumns
  73. });
  74. wt.draw();
  75. wt.wtOverlays.topOverlay.scrollTo(3);
  76. expect($(wt.wtTable.holder).scrollTop()).toEqual(69);
  77. });
  78. });