header-rendering.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. describe('header rendering', function() {
  2. beforeEach(function() {
  3. affix('#calendar');
  4. });
  5. describe('when using default header options', function() {
  6. it('should have title as default on left', function() {
  7. $('#calendar').fullCalendar();
  8. expect($('#calendar > .fc-toolbar > .fc-left > *')).toBeMatchedBy('h2');
  9. });
  10. it('should have empty center', function() {
  11. $('#calendar').fullCalendar();
  12. var center = $('#calendar > .fc-toolbar > .fc-center');
  13. expect(center).toBeEmpty();
  14. });
  15. it('should have right with today|space|left|right', function() {
  16. $('#calendar').fullCalendar();
  17. var rightChildren = $('#calendar > .fc-toolbar > .fc-right > *');
  18. var todayButton = rightChildren.eq(0);
  19. var buttonGroup = rightChildren.eq(1);
  20. var prevNextButtons = buttonGroup.children();
  21. expect(todayButton).toHaveClass('fc-today-button');
  22. expect(buttonGroup).toHaveClass('fc-button-group');
  23. expect(prevNextButtons.eq(0)).toHaveClass('fc-prev-button');
  24. expect(prevNextButtons.eq(1)).toHaveClass('fc-next-button');
  25. });
  26. });
  27. describe('when supplying header options', function() {
  28. beforeEach(function() {
  29. var options = {
  30. header: {
  31. left: 'next,prev',
  32. center: 'prevYear today nextYear agendaView,dayView',
  33. right: 'title'
  34. }
  35. };
  36. $('#calendar').fullCalendar(options);
  37. });
  38. it('should have title on the right', function() {
  39. expect($('#calendar > .fc-toolbar > .fc-right > *')).toBeMatchedBy('h2');
  40. });
  41. it('should have next|prev on left', function() {
  42. var buttonGroup = $('#calendar > .fc-toolbar > .fc-left > *');
  43. var prevNextButtons = buttonGroup.children();
  44. expect(prevNextButtons.eq(0)).toHaveClass('fc-next-button');
  45. expect(prevNextButtons.eq(1)).toHaveClass('fc-prev-button');
  46. });
  47. it('should have prevYear|space|today|space|nextYear in center', function() {
  48. var items = $('#calendar > .fc-toolbar > .fc-center > *');
  49. expect(items.eq(0)).toHaveClass('fc-prevYear-button');
  50. expect(items.eq(1)).toHaveClass('fc-today-button');
  51. expect(items.eq(2)).toHaveClass('fc-nextYear-button');
  52. });
  53. });
  54. describe('when setting header to false', function() {
  55. beforeEach(function() {
  56. var options = {
  57. header: false
  58. };
  59. $('#calendar').fullCalendar(options);
  60. });
  61. it('should not have header table', function() {
  62. expect($('.fc-toolbar')).not.toBeInDOM();
  63. });
  64. });
  65. it('allow for dynamically changing', function() {
  66. $('#calendar').fullCalendar();
  67. expect($('.fc-toolbar')).toBeInDOM();
  68. $('#calendar').fullCalendar('option', 'header', false);
  69. expect($('.fc-toolbar')).not.toBeInDOM();
  70. });
  71. describe('renders left and right literally', function() {
  72. [ true, false ].forEach(function(isRTL) {
  73. describe('when isRTL is ' + isRTL, function() {
  74. beforeEach(function() {
  75. var options = {};
  76. $('#calendar').fullCalendar({
  77. header: {
  78. left: 'prev',
  79. center: 'today',
  80. right: 'next'
  81. },
  82. isRTL: isRTL
  83. });
  84. });
  85. it('should have prev in left', function() {
  86. var fcHeaderLeft = $('#calendar .fc-toolbar > .fc-left');
  87. expect(fcHeaderLeft).toContainElement('.fc-prev-button');
  88. });
  89. it('should have today in center', function() {
  90. var fcHeaderCenter = $('#calendar .fc-toolbar > .fc-center');
  91. expect(fcHeaderCenter).toContainElement('.fc-today-button');
  92. });
  93. it('should have next in right', function() {
  94. var fcHeaderRight = $('#calendar .fc-toolbar > .fc-right');
  95. expect(fcHeaderRight).toContainElement('.fc-next-button');
  96. });
  97. });
  98. });
  99. });
  100. describe('when calendar is within a form', function() {
  101. beforeEach(function() {
  102. $('#calendar').wrap('<form action="http://google.com/"></form>');
  103. });
  104. it('should not submit the form when clicking the button', function(done) {
  105. var options = {
  106. header: {
  107. left: 'prev,next',
  108. right: 'title'
  109. }
  110. };
  111. var unloadCalled = false;
  112. function beforeUnloadHandler() {
  113. console.log('when calendar is within a form, it submits!!!');
  114. unloadCalled = true;
  115. cleanup();
  116. return 'click stay on this page';
  117. }
  118. $(window).on('beforeunload', beforeUnloadHandler);
  119. function cleanup() {
  120. $(window).off('beforeunload', beforeUnloadHandler);
  121. }
  122. $('#calendar').fullCalendar(options);
  123. $('.fc-next-button').simulate('click');
  124. setTimeout(function() { // wait to see if handler was called
  125. expect(unloadCalled).toBe(false);
  126. cleanup();
  127. done();
  128. }, 100);
  129. });
  130. });
  131. });