selectAllow.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { selectTimeGrid } from '../lib/time-grid'
  2. describe('selectAllow', function() {
  3. pushOptions({
  4. now: '2016-09-04',
  5. defaultView: 'agendaWeek',
  6. scrollTime: '00:00',
  7. selectable: true
  8. })
  9. it('disallows selecting when returning false', function(done) { // and given correct params
  10. var options = {
  11. selectAllow: function(selectInfo) {
  12. expect(typeof selectInfo).toBe('object')
  13. expect(moment.isMoment(selectInfo.start)).toBe(true)
  14. expect(moment.isMoment(selectInfo.end)).toBe(true)
  15. return false
  16. }
  17. }
  18. spyOn(options, 'selectAllow').and.callThrough()
  19. initCalendar(options)
  20. selectTimeGrid('2016-09-04T01:00:00', '2016-09-04T05:00:00')
  21. .then(function(selectInfo) {
  22. expect(selectInfo).toBeFalsy()
  23. expect(options.selectAllow).toHaveBeenCalled()
  24. done()
  25. })
  26. })
  27. it('allows selecting when returning true', function(done) {
  28. var options = {
  29. selectAllow: function(selectInfo) {
  30. return true
  31. }
  32. }
  33. spyOn(options, 'selectAllow').and.callThrough()
  34. initCalendar(options)
  35. selectTimeGrid('2016-09-04T01:00:00', '2016-09-04T05:00:00')
  36. .then(function(selectInfo) {
  37. expect(typeof selectInfo).toBe('object')
  38. expect(selectInfo.start.format()).toBe('2016-09-04T01:00:00')
  39. expect(selectInfo.end.format()).toBe('2016-09-04T05:30:00')
  40. expect(options.selectAllow).toHaveBeenCalled()
  41. done()
  42. })
  43. })
  44. })