scrollbarNative.spec.js 2.4 KB

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