select-callback.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. describe('select callback', function() {
  2. var options
  3. beforeEach(function() {
  4. affix('#cal')
  5. options = {
  6. defaultDate: '2014-05-25',
  7. selectable: true,
  8. longPressDelay: 100
  9. }
  10. })
  11. afterEach(function() {
  12. $('#cal').fullCalendar('destroy')
  13. });
  14. [ false, true ].forEach(function(isRTL) {
  15. describe('when isRTL is ' + isRTL, function() {
  16. beforeEach(function() {
  17. options.isRTL = isRTL
  18. })
  19. describe('when in month view', function() {
  20. beforeEach(function() {
  21. options.defaultView = 'month'
  22. })
  23. it('gets fired correctly when the user selects cells', function(done) {
  24. options.select = function(start, end, jsEvent, view) {
  25. expect(moment.isMoment(start)).toEqual(true)
  26. expect(moment.isMoment(end)).toEqual(true)
  27. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  28. expect(typeof view).toEqual('object') // "
  29. expect(start.hasTime()).toEqual(false)
  30. expect(end.hasTime()).toEqual(false)
  31. expect(start).toEqualMoment('2014-04-28')
  32. expect(end).toEqualMoment('2014-05-07')
  33. }
  34. spyOn(options, 'select').and.callThrough()
  35. $('#cal').fullCalendar(options)
  36. $('.fc-day[data-date="2014-04-28"]').simulate('drag', {
  37. end: '.fc-day[data-date="2014-05-06"]',
  38. callback: function() {
  39. expect(options.select).toHaveBeenCalled()
  40. done()
  41. }
  42. })
  43. })
  44. it('gets fired correctly when the user selects cells via touch', function(done) {
  45. options.select = function(start, end, jsEvent, view) {
  46. expect(moment.isMoment(start)).toEqual(true)
  47. expect(moment.isMoment(end)).toEqual(true)
  48. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  49. expect(typeof view).toEqual('object') // "
  50. expect(start.hasTime()).toEqual(false)
  51. expect(end.hasTime()).toEqual(false)
  52. expect(start).toEqualMoment('2014-04-28')
  53. expect(end).toEqualMoment('2014-05-07')
  54. }
  55. spyOn(options, 'select').and.callThrough()
  56. $('#cal').fullCalendar(options)
  57. $('.fc-day[data-date="2014-04-28"]').simulate('drag', {
  58. isTouch: true,
  59. delay: 200,
  60. end: '.fc-day[data-date="2014-05-06"]',
  61. callback: function() {
  62. expect(options.select).toHaveBeenCalled()
  63. done()
  64. }
  65. })
  66. })
  67. it('gets fired correctly when the user selects just one cell', function(done) {
  68. options.select = function(start, end, jsEvent, view) {
  69. expect(moment.isMoment(start)).toEqual(true)
  70. expect(moment.isMoment(end)).toEqual(true)
  71. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  72. expect(typeof view).toEqual('object') // "
  73. expect(start.hasTime()).toEqual(false)
  74. expect(end.hasTime()).toEqual(false)
  75. expect(start).toEqualMoment('2014-04-28')
  76. expect(end).toEqualMoment('2014-04-29')
  77. }
  78. spyOn(options, 'select').and.callThrough()
  79. $('#cal').fullCalendar(options)
  80. $('.fc-day[data-date="2014-04-28"]').simulate('drag', {
  81. end: '.fc-day[data-date="2014-04-28"]',
  82. callback: function() {
  83. expect(options.select).toHaveBeenCalled()
  84. done()
  85. }
  86. })
  87. })
  88. })
  89. describe('when in agendaWeek view', function() {
  90. beforeEach(function() {
  91. options.defaultView = 'agendaWeek'
  92. })
  93. describe('when selecting all-day slots', function() {
  94. it('gets fired correctly when the user selects cells', function(done) {
  95. options.select = function(start, end, jsEvent, view) {
  96. expect(moment.isMoment(start)).toEqual(true)
  97. expect(moment.isMoment(end)).toEqual(true)
  98. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  99. expect(typeof view).toEqual('object') // "
  100. expect(start.hasTime()).toEqual(false)
  101. expect(end.hasTime()).toEqual(false)
  102. expect(start).toEqualMoment('2014-05-28')
  103. expect(end).toEqualMoment('2014-05-30')
  104. }
  105. spyOn(options, 'select').and.callThrough()
  106. $('#cal').fullCalendar(options)
  107. $('.fc-agenda-view .fc-day-grid .fc-day:eq(3)').simulate('drag', { // will be 2014-05-28 for LTR and RTL
  108. dx: $('.fc-sun').outerWidth() * (isRTL ? -1 : 1), // the width of one column
  109. callback: function() {
  110. expect(options.select).toHaveBeenCalled()
  111. done()
  112. }
  113. })
  114. })
  115. it('gets fired correctly when the user selects a single cell', function(done) {
  116. options.select = function(start, end, jsEvent, view) {
  117. expect(moment.isMoment(start)).toEqual(true)
  118. expect(moment.isMoment(end)).toEqual(true)
  119. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  120. expect(typeof view).toEqual('object') // "
  121. expect(start.hasTime()).toEqual(false)
  122. expect(end.hasTime()).toEqual(false)
  123. expect(start).toEqualMoment('2014-05-28')
  124. expect(end).toEqualMoment('2014-05-29')
  125. }
  126. spyOn(options, 'select').and.callThrough()
  127. $('#cal').fullCalendar(options)
  128. $('.fc-agenda-view .fc-day-grid .fc-day:eq(3)').simulate('drag', { // will be 2014-05-28 for LTR and RTL
  129. callback: function() {
  130. expect(options.select).toHaveBeenCalled()
  131. done()
  132. }
  133. })
  134. })
  135. })
  136. describe('when selecting timed slots', function() {
  137. it('gets fired correctly when the user selects slots', function(done) {
  138. options.select = function(start, end, jsEvent, view) {
  139. expect(moment.isMoment(start)).toEqual(true)
  140. expect(moment.isMoment(end)).toEqual(true)
  141. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  142. expect(typeof view).toEqual('object') // "
  143. expect(start.hasTime()).toEqual(true)
  144. expect(end.hasTime()).toEqual(true)
  145. expect(start).toEqualMoment('2014-05-28T09:00:00')
  146. expect(end).toEqualMoment('2014-05-28T10:30:00')
  147. }
  148. spyOn(options, 'select').and.callThrough()
  149. $('#cal').fullCalendar(options)
  150. $('.fc-slats tr:eq(18) td:not(.fc-time)').simulate('drag', { // middle will be 2014-05-28T09:00:00
  151. dy: $('.fc-slats tr:eq(18)').outerHeight() * 2, // move down two slots
  152. callback: function() {
  153. expect(options.select).toHaveBeenCalled()
  154. done()
  155. }
  156. })
  157. })
  158. it('gets fired correctly when the user selects slots via touch', function(done) {
  159. options.select = function(start, end, jsEvent, view) {
  160. expect(moment.isMoment(start)).toEqual(true)
  161. expect(moment.isMoment(end)).toEqual(true)
  162. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  163. expect(typeof view).toEqual('object') // "
  164. expect(start.hasTime()).toEqual(true)
  165. expect(end.hasTime()).toEqual(true)
  166. expect(start).toEqualMoment('2014-05-28T09:00:00')
  167. expect(end).toEqualMoment('2014-05-28T10:30:00')
  168. }
  169. spyOn(options, 'select').and.callThrough()
  170. $('#cal').fullCalendar(options)
  171. setTimeout(function() { // prevent scroll from being triggered, killing the select interaction
  172. $('.fc-slats tr:eq(18) td:not(.fc-time)').simulate('drag', { // middle will be 2014-05-28T09:00:00
  173. isTouch: true,
  174. delay: 200,
  175. dy: $('.fc-slats tr:eq(18)').outerHeight() * 2, // move down two slots
  176. callback: function() {
  177. expect(options.select).toHaveBeenCalled()
  178. done()
  179. }
  180. })
  181. }, 0)
  182. })
  183. it('gets fired correctly when the user selects slots in a different day', function(done) {
  184. options.select = function(start, end, jsEvent, view) {
  185. expect(moment.isMoment(start)).toEqual(true)
  186. expect(moment.isMoment(end)).toEqual(true)
  187. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  188. expect(typeof view).toEqual('object') // "
  189. expect(start.hasTime()).toEqual(true)
  190. expect(end.hasTime()).toEqual(true)
  191. expect(start).toEqualMoment('2014-05-28T09:00:00')
  192. expect(end).toEqualMoment('2014-05-29T10:30:00')
  193. }
  194. spyOn(options, 'select').and.callThrough()
  195. $('#cal').fullCalendar(options)
  196. $('.fc-slats tr:eq(18) td:not(.fc-time)').simulate('drag', { // middle will be 2014-05-28T09:00:00
  197. dx: $('.fc-day-header:first').outerWidth() * 0.9 * (isRTL ? -1 : 1), // one day ahead
  198. dy: $('.fc-slats tr:eq(18)').outerHeight() * 2, // move down two slots
  199. callback: function() {
  200. expect(options.select).toHaveBeenCalled()
  201. done()
  202. }
  203. })
  204. })
  205. it('gets fired correctly when the user selects a single slot', function(done) {
  206. options.select = function(start, end, jsEvent, view) {
  207. expect(moment.isMoment(start)).toEqual(true)
  208. expect(moment.isMoment(end)).toEqual(true)
  209. expect(typeof jsEvent).toEqual('object') // TODO: more descrimination
  210. expect(typeof view).toEqual('object') // "
  211. expect(start.hasTime()).toEqual(true)
  212. expect(end.hasTime()).toEqual(true)
  213. expect(start).toEqualMoment('2014-05-28T09:00:00')
  214. expect(end).toEqualMoment('2014-05-28T09:30:00')
  215. }
  216. spyOn(options, 'select').and.callThrough()
  217. $('#cal').fullCalendar(options)
  218. $('.fc-slats tr:eq(18) td:not(.fc-time)').simulate('drag', { // middle will be 2014-05-28T09:00:00
  219. callback: function() {
  220. expect(options.select).toHaveBeenCalled()
  221. done()
  222. }
  223. })
  224. })
  225. })
  226. })
  227. })
  228. })
  229. describe('when selectMinDistance', function() {
  230. beforeEach(function() {
  231. options.selectMinDistance = 10
  232. })
  233. it('will fire when dragged beyond distance', function(done) {
  234. options.select = function() {}
  235. spyOn(options, 'select').and.callThrough()
  236. $('#cal').fullCalendar(options)
  237. $('.fc-day[data-date="2014-04-28"]').simulate('drag', {
  238. dx: 12,
  239. dy: 0,
  240. callback: function() {
  241. expect(options.select).toHaveBeenCalled()
  242. done()
  243. }
  244. })
  245. })
  246. it('will not fire when not dragged beyond distance', function(done) {
  247. options.select = function() {}
  248. spyOn(options, 'select').and.callThrough()
  249. $('#cal').fullCalendar(options)
  250. $('.fc-day[data-date="2014-04-28"]').simulate('drag', {
  251. dx: 8,
  252. dy: 0,
  253. callback: function() {
  254. expect(options.select).not.toHaveBeenCalled()
  255. done()
  256. }
  257. })
  258. })
  259. })
  260. it('will keep the correct locale', function(done) {
  261. options.locale = 'fr'
  262. options.select = function(start, end) {
  263. expect(start.locale()).toBe('fr')
  264. expect(end.locale()).toBe('fr')
  265. }
  266. spyOn(options, 'select').and.callThrough()
  267. $('#cal').fullCalendar(options)
  268. $('.fc-day[data-date="2014-04-28"]').simulate('drag', {
  269. callback: function() {
  270. expect(options.select).toHaveBeenCalled()
  271. done()
  272. }
  273. })
  274. })
  275. })