select-method.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. describe('select method', function() {
  2. var options
  3. beforeEach(function() {
  4. affix('#cal')
  5. options = {
  6. defaultDate: '2014-05-25',
  7. selectable: true
  8. }
  9. })
  10. afterEach(function() {
  11. $('#cal').fullCalendar('destroy')
  12. });
  13. /*
  14. THINGS TO IMPLEMENT IN SRC (in addition to notes further down):
  15. - better date normalization (for both render and reporting to select callback)
  16. - if second date is the same or before the first
  17. - if given a mixture of timed/all-day
  18. - for basic/month views, when given timed dates, should really be all-day
  19. */
  20. [ false, true ].forEach(function(isRTL) {
  21. describe('when isRTL is ' + isRTL, function() {
  22. beforeEach(function() {
  23. options.isRTL = isRTL
  24. })
  25. describe('when in month view', function() {
  26. beforeEach(function() {
  27. options.defaultView = 'month'
  28. })
  29. describe('when called with all-day moments', function() {
  30. describe('when in bounds', function() {
  31. it('renders a selection', function() {
  32. $('#cal').fullCalendar(options)
  33. $('#cal').fullCalendar('select', '2014-05-07', '2014-05-09')
  34. expect($('.fc-highlight')).toBeVisible()
  35. })
  36. it('renders a selection when called with one argument', function() {
  37. $('#cal').fullCalendar(options)
  38. $('#cal').fullCalendar('select', '2014-05-07')
  39. expect($('.fc-highlight')).toBeVisible()
  40. })
  41. it('fires a selection event', function() {
  42. options.select = function(start, end) {
  43. expect(start.hasTime()).toEqual(false)
  44. expect(end.hasTime()).toEqual(false)
  45. expect(start).toEqualMoment('2014-05-07')
  46. expect(end).toEqualMoment('2014-05-09')
  47. }
  48. spyOn(options, 'select').and.callThrough()
  49. $('#cal').fullCalendar(options)
  50. $('#cal').fullCalendar('select', '2014-05-07', '2014-05-09')
  51. expect(options.select).toHaveBeenCalled()
  52. })
  53. })
  54. describe('when out of bounds', function() {
  55. it('doesn\'t render a selection', function() {
  56. $('#cal').fullCalendar(options)
  57. $('#cal').fullCalendar('select', '2015-05-07', '2015-05-09')
  58. expect($('.fc-highlight')).not.toBeVisible()
  59. })
  60. /*
  61. TODO: implement this behavior
  62. it('doesn\'t fire a selection event', function() {
  63. options.select = function(start, end) {
  64. expect(start).toEqualMoment('2014-05-07');
  65. expect(end).toEqualMoment('2014-05-09');
  66. };
  67. spyOn(options, 'select').and.callThrough();
  68. $('#cal').fullCalendar(options);
  69. $('#cal').fullCalendar('select', '2015-05-07', '2015-05-09');
  70. expect(options.select).not.toHaveBeenCalled();
  71. });
  72. */
  73. })
  74. })
  75. describe('when called with timed moments', function() {
  76. it('renders a selection', function() {
  77. $('#cal').fullCalendar(options)
  78. $('#cal').fullCalendar('select', '2014-05-07T06:00:00', '2014-05-09T07:00:00')
  79. expect($('.fc-highlight')).toBeVisible()
  80. })
  81. it('fires a selection event', function() {
  82. options.select = function(start, end) {
  83. expect(start.hasTime()).toEqual(true)
  84. expect(end.hasTime()).toEqual(true)
  85. expect(start).toEqualMoment('2014-05-07T06:00:00')
  86. expect(end).toEqualMoment('2014-05-09T06:00:00')
  87. }
  88. spyOn(options, 'select').and.callThrough()
  89. $('#cal').fullCalendar(options)
  90. $('#cal').fullCalendar('select', '2014-05-07T06:00:00', '2014-05-09T06:00:00')
  91. expect(options.select).toHaveBeenCalled()
  92. })
  93. })
  94. })
  95. describe('when in agendaWeek view', function() { // May 25 - 31
  96. beforeEach(function() {
  97. options.defaultView = 'agendaWeek'
  98. options.scrollTime = '01:00:00' // so that most events will be below the divider
  99. options.height = 400 // short enought to make scrolling happen
  100. })
  101. describe('when called with timed moments', function() {
  102. describe('when in bounds', function() {
  103. it('renders a selection when called with one argument', function() {
  104. $('#cal').fullCalendar(options)
  105. $('#cal').fullCalendar('select', '2014-05-26T06:00:00')
  106. expect($('.fc-highlight')).toBeVisible()
  107. })
  108. it('renders a selection over the slot area', function() {
  109. $('#cal').fullCalendar(options)
  110. $('#cal').fullCalendar('select', '2014-05-26T06:00:00', '2014-05-26T08:00:00')
  111. expect($('.fc-highlight')).toBeVisible()
  112. var slotAreaTop = $('.fc-time-grid-container').offset().top
  113. var overlayTop = $('.fc-highlight').offset().top
  114. expect(overlayTop).toBeGreaterThan(slotAreaTop)
  115. })
  116. })
  117. describe('when out of bounds', function() {
  118. it('doesn\'t render a selection', function() {
  119. $('#cal').fullCalendar(options)
  120. $('#cal').fullCalendar('select', '2015-05-26T06:00:00', '2015-05-26T07:00:00')
  121. expect($('.fc-highlight')).not.toBeVisible()
  122. })
  123. /*
  124. TODO: implement this behavior
  125. it('doesn\'t fire a selection event', function() {
  126. options.select = function(start, end) {
  127. expect(start).toEqualMoment('2015-05-07T06:00:00');
  128. expect(end).toEqualMoment('2015-05-09T07:00:00');
  129. };
  130. spyOn(options, 'select').and.callThrough();
  131. $('#cal').fullCalendar(options);
  132. $('#cal').fullCalendar('select', '2015-05-07T06:00:00', '2015-05-09T07:00:00');
  133. expect(options.select).not.toHaveBeenCalled();
  134. });
  135. */
  136. })
  137. })
  138. describe('when called with all-day moments', function() { // forget about in/out bounds for this :)
  139. describe('when allDaySlot is on', function() {
  140. beforeEach(function() {
  141. options.allDaySlot = true
  142. })
  143. it('renders a selection over the day area', function() {
  144. $('#cal').fullCalendar(options)
  145. $('#cal').fullCalendar('select', '2014-05-26', '2014-05-28')
  146. expect($('.fc-highlight')).toBeVisible()
  147. var slotAreaTop = $('.fc-time-grid-container').offset().top
  148. var overlayTop = $('.fc-highlight').offset().top
  149. expect(overlayTop).toBeLessThan(slotAreaTop)
  150. })
  151. it('fires a selection event', function() {
  152. options.select = function(start, end) {
  153. expect(start.hasTime()).toEqual(false)
  154. expect(end.hasTime()).toEqual(false)
  155. expect(start).toEqualMoment('2014-05-26')
  156. expect(end).toEqualMoment('2014-05-28')
  157. }
  158. spyOn(options, 'select').and.callThrough()
  159. $('#cal').fullCalendar(options)
  160. $('#cal').fullCalendar('select', '2014-05-26', '2014-05-28')
  161. expect(options.select).toHaveBeenCalled()
  162. })
  163. })
  164. describe('when allDaySlot is off', function() {
  165. beforeEach(function() {
  166. options.allDaySlot = false
  167. })
  168. it('doesn\'t render', function() {
  169. $('#cal').fullCalendar(options)
  170. $('#cal').fullCalendar('select', '2014-05-26', '2014-05-28')
  171. expect($('.fc-highlight')).not.toBeVisible()
  172. })
  173. /*
  174. TODO: implement
  175. it('doesn\'t fire a selection event', function() {
  176. options.select = function(start, end) {
  177. expect(start.hasTime()).toEqual(false);
  178. expect(end.hasTime()).toEqual(false);
  179. expect(start).toEqualMoment('2014-05-26');
  180. expect(end).toEqualMoment('2014-05-28');
  181. };
  182. spyOn(options, 'select').and.callThrough();
  183. $('#cal').fullCalendar(options);
  184. $('#cal').fullCalendar('select', '2014-05-26', '2014-05-28');
  185. expect(options.select).not.toHaveBeenCalled();
  186. });
  187. */
  188. })
  189. })
  190. })
  191. })
  192. })
  193. })