header-rendering.js 4.5 KB

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