dayClick.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. describe('dayClick', function() {
  2. pushOptions({
  3. defaultDate: '2014-05-27',
  4. selectable: false
  5. });
  6. [ false, true ].forEach(function(isRTL) {
  7. describe('when isRTL is ' + isRTL, function() {
  8. pushOptions({isRTL: isRTL});
  9. [ false, true ].forEach(function(selectable) {
  10. describe('when selectable is ' + selectable, function() {
  11. pushOptions({selectable: selectable})
  12. describe('when in month view', function() {
  13. pushOptions({defaultView: 'month'})
  14. it('fires correctly when clicking on a cell', function(done) {
  15. var options = {}
  16. options.dayClick = function(date, jsEvent, view) {
  17. expect(moment.isMoment(date)).toEqual(true)
  18. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  19. expect(typeof view).toEqual('object') // "
  20. expect(date.hasTime()).toEqual(false)
  21. expect(date).toEqualMoment('2014-05-07')
  22. }
  23. spyOn(options, 'dayClick').and.callThrough()
  24. initCalendar(options)
  25. var dayCell = $('.fc-day:eq(10)') // 2014-05-07 (regardless of isRTL)
  26. // for simulating the mousedown/mouseup/click (relevant for selectable)
  27. dayCell.simulate('drag', {
  28. callback: function() {
  29. expect(options.dayClick).toHaveBeenCalled()
  30. done()
  31. }
  32. })
  33. })
  34. })
  35. describe('when in agendaWeek view', function() {
  36. pushOptions({defaultView: 'agendaWeek'})
  37. it('fires correctly when clicking on an all-day slot', function(done) {
  38. var options = {}
  39. options.dayClick = function(date, jsEvent, view) {
  40. expect(moment.isMoment(date)).toEqual(true)
  41. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  42. expect(typeof view).toEqual('object') // "
  43. expect(date.hasTime()).toEqual(false)
  44. expect(date).toEqualMoment('2014-05-28')
  45. }
  46. spyOn(options, 'dayClick').and.callThrough()
  47. initCalendar(options)
  48. // 2014-05-28 (regardless of isRTL)
  49. var dayContent = $('.fc-agenda-view .fc-day-grid .fc-day:eq(3)')
  50. // for simulating the mousedown/mouseup/click (relevant for selectable)
  51. dayContent.simulate('drag', {
  52. callback: function() {
  53. expect(options.dayClick).toHaveBeenCalled()
  54. done()
  55. }
  56. })
  57. })
  58. it('fires correctly when clicking on a timed slot', function(done) {
  59. var options = {}
  60. // make sure the click slot will be in scroll view
  61. options.contentHeight = 500
  62. options.scrollTime = '07:00:00'
  63. options.dayClick = function(date, jsEvent, view) {
  64. expect(moment.isMoment(date)).toEqual(true)
  65. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  66. expect(typeof view).toEqual('object') // "
  67. expect(date.hasTime()).toEqual(true)
  68. expect(date).toEqualMoment('2014-05-28T09:00:00')
  69. }
  70. spyOn(options, 'dayClick').and.callThrough()
  71. initCalendar(options)
  72. // the middle is 2014-05-28T09:00:00 (regardless of isRTL)
  73. var slotRow = $('.fc-slats tr:eq(18) td:not(.fc-time)')
  74. // for simulating the mousedown/mouseup/click (relevant for selectable)
  75. slotRow.simulate('drag', {
  76. callback: function() {
  77. expect(options.dayClick).toHaveBeenCalled()
  78. done()
  79. }
  80. })
  81. })
  82. // issue 2217
  83. it('fires correctly when clicking on a timed slot, with minTime set', function(done) {
  84. var options = {}
  85. // make sure the click slot will be in scroll view
  86. options.contentHeight = 500
  87. options.scrollTime = '07:00:00'
  88. options.minTime = '02:00:00'
  89. options.dayClick = function(date, jsEvent, view) {
  90. expect(moment.isMoment(date)).toEqual(true)
  91. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  92. expect(typeof view).toEqual('object') // "
  93. expect(date.hasTime()).toEqual(true)
  94. expect(date).toEqualMoment('2014-05-28T11:00:00')
  95. }
  96. spyOn(options, 'dayClick').and.callThrough()
  97. initCalendar(options)
  98. // the middle is 2014-05-28T11:00:00 (regardless of isRTL)
  99. var slotRow = $('.fc-slats tr:eq(18) td:not(.fc-time)')
  100. // for simulating the mousedown/mouseup/click (relevant for selectable)
  101. slotRow.simulate('drag', {
  102. callback: function() {
  103. expect(options.dayClick).toHaveBeenCalled()
  104. done()
  105. }
  106. })
  107. })
  108. })
  109. })
  110. })
  111. })
  112. })
  113. describe('when touch', function() {
  114. it('fires correctly when simulated short drag on a cell', function(done) {
  115. var options = {}
  116. options.dayClick = function(date, jsEvent, view) {
  117. expect(moment.isMoment(date)).toEqual(true)
  118. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  119. expect(typeof view).toEqual('object') // "
  120. expect(date.hasTime()).toEqual(false)
  121. expect(date).toEqualMoment('2014-05-07')
  122. }
  123. spyOn(options, 'dayClick').and.callThrough()
  124. initCalendar(options)
  125. var dayCell = $('.fc-day:eq(10)') // 2014-05-07 (regardless of isRTL)
  126. // for simulating the mousedown/mouseup/click (relevant for selectable)
  127. dayCell.simulate('drag', {
  128. isTouch: true,
  129. callback: function() {
  130. expect(options.dayClick).toHaveBeenCalled()
  131. done()
  132. }
  133. })
  134. })
  135. it('won\'t fire if touch moves outside of date cell', function(done) {
  136. var options = {}
  137. options.dayClick = function(date, jsEvent, view) {}
  138. spyOn(options, 'dayClick').and.callThrough()
  139. initCalendar(options)
  140. var startCell = $('.fc-day[data-date="2014-05-07"]')
  141. var endCell = $('.fc-day[data-date="2014-05-08"]')
  142. startCell.simulate('drag', {
  143. // FYI, when debug:true, not a good representation because the minimal delay is required
  144. // to recreate bug #3332
  145. isTouch: true,
  146. end: endCell,
  147. callback: function() {
  148. expect(options.dayClick).not.toHaveBeenCalled()
  149. done()
  150. }
  151. })
  152. })
  153. it('fires correctly when simulated click on a cell', function(done) {
  154. var options = {}
  155. options.dayClick = function(date, jsEvent, view) {
  156. expect(moment.isMoment(date)).toEqual(true)
  157. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  158. expect(typeof view).toEqual('object') // "
  159. expect(date.hasTime()).toEqual(false)
  160. expect(date).toEqualMoment('2014-05-07')
  161. }
  162. spyOn(options, 'dayClick').and.callThrough()
  163. initCalendar(options)
  164. var dayCell = $('.fc-day:eq(10)') // 2014-05-07 (regardless of isRTL)
  165. $.simulateTouchClick(dayCell)
  166. expect(options.dayClick).toHaveBeenCalled()
  167. done()
  168. })
  169. })
  170. })