getClientRect.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. describe('getClientRect', function() {
  2. var getClientRect = $.fullCalendar.getClientRect;
  3. defineTests(
  4. 'when margin',
  5. { margin: '5px 10px' },
  6. { width: 100, height: 100 },
  7. { width: 100, height: 100 }
  8. );
  9. defineTests(
  10. 'when padding',
  11. { padding: '5px 10px' },
  12. { width: 100, height: 100 },
  13. { width: 120, height: 110 }
  14. );
  15. //// getClientRect doesn't work with borders anymore
  16. //defineTests(
  17. // 'when border',
  18. // { border: '5px solid red' },
  19. // { width: 100, height: 100 },
  20. // { width: 100, height: 100 }
  21. //);
  22. //defineTests(
  23. // 'when border and padding',
  24. // { border: '5px solid red', padding: '5px 10px' },
  25. // { width: 100, height: 100 },
  26. // { width: 120, height: 110 }
  27. //);
  28. function defineTests(description, cssProps, innerDims, dims) {
  29. describe(description, function() {
  30. describe('when no scrolling', function() {
  31. describe('when LTR', function() {
  32. defineTest(false, 'ltr', cssProps, innerDims, dims);
  33. });
  34. describe('when RTL', function() {
  35. defineTest(false, 'rtl', cssProps, innerDims, dims);
  36. });
  37. });
  38. describe('when scrolling', function() {
  39. describe('when LTR', function() {
  40. defineTest(true, 'ltr', cssProps, innerDims, dims);
  41. });
  42. describe('when RTL', function() {
  43. defineTest(true, 'rtl', cssProps, innerDims, dims);
  44. });
  45. });
  46. });
  47. }
  48. function defineTest(isScrolling, dir, cssProps, innerDims, dims) {
  49. it('computes correct dimensions', function() {
  50. var el = $(
  51. '<div style="position:absolute" />'
  52. )
  53. .css('overflow', isScrolling ? 'scroll' : 'hidden')
  54. .css('direction', dir)
  55. .css(cssProps)
  56. .append(
  57. $('<div style="position:relative" />').css(innerDims)
  58. )
  59. .appendTo('body');
  60. var rect = getClientRect(el);
  61. var offset = el.offset();
  62. var borderLeftWidth = parseFloat(el.css('border-left-width')) || 0;
  63. var borderTopWidth = parseFloat(el.css('border-top-width')) || 0;
  64. var scrollbarWidths;
  65. if (isScrolling) {
  66. scrollbarWidths = getStockScrollbarWidths(dir);
  67. }
  68. else {
  69. scrollbarWidths = { left: 0, right: 0, top: 0, bottom: 0 };
  70. }
  71. expect(rect.left).toBe(offset.left + borderLeftWidth + scrollbarWidths.left);
  72. expect(rect.top).toBe(offset.top + borderTopWidth + scrollbarWidths.top);
  73. expect(rect.right - rect.left).toBe(dims.width);
  74. expect(rect.bottom - rect.top).toBe(dims.height);
  75. el.remove();
  76. });
  77. }
  78. });