visibleRange.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. describe('visibleRange', function() {
  2. describe('when custom view with a flexible range', function() {
  3. pushOptions({
  4. defaultView: 'agenda'
  5. });
  6. describe('when given a valid date range', function() {
  7. var startInput = '2017-06-26';
  8. var endInput = '2017-06-29';
  9. describeOptions('visibleRange', {
  10. 'of moment objects': {
  11. start: $.fullCalendar.moment(startInput),
  12. end: $.fullCalendar.moment(endInput)
  13. },
  14. 'of strings': {
  15. start: startInput,
  16. end: endInput
  17. },
  18. 'of a function that returns moment objects': function() {
  19. return {
  20. start: $.fullCalendar.moment(startInput),
  21. end: $.fullCalendar.moment(endInput)
  22. };
  23. },
  24. 'of a function that returns strings': function() {
  25. return {
  26. start: startInput,
  27. end: endInput
  28. };
  29. },
  30. }, function() {
  31. it('gets set to the given range', function() {
  32. initCalendar();
  33. ViewDateUtils.expectActiveRange(startInput, endInput);
  34. });
  35. });
  36. it('works as a custom view', function() {
  37. initCalendar({
  38. views: {
  39. myCustomView: {
  40. type: 'agenda',
  41. visibleRange: {
  42. start: startInput,
  43. end: endInput
  44. }
  45. }
  46. },
  47. defaultView: 'myCustomView'
  48. });
  49. ViewDateUtils.expectActiveRange(startInput, endInput);
  50. });
  51. it('ignores dateAlignment', function() {
  52. initCalendar({
  53. dateAlignment: 'month',
  54. visibleRange: {
  55. start: startInput,
  56. end: endInput
  57. }
  58. });
  59. ViewDateUtils.expectActiveRange(startInput, endInput);
  60. });
  61. it('works as a dynamic option', function() {
  62. initCalendar({
  63. defaultView: 'basic'
  64. });
  65. currentCalendar.option('visibleRange', {
  66. start: startInput,
  67. end: endInput
  68. });
  69. ViewDateUtils.expectActiveRange(startInput, endInput);
  70. });
  71. });
  72. describe('when a function', function() {
  73. var defaultDateInput = '2017-06-08T12:30:00';
  74. it('receives the calendar\'s defaultDate, timezoneless', function() {
  75. var matched = false;
  76. initCalendar({
  77. defaultDate: defaultDateInput,
  78. visibleRange: function(date) {
  79. // this function will receive the date for prev/next,
  80. // which should be ignored. make sure just one call matches.
  81. if (date.format() === defaultDateInput) {
  82. matched = true;
  83. }
  84. }
  85. });
  86. expect(matched).toBe(true);
  87. });
  88. it('receives the calendar\'s defaultDate, with UTC timezone', function() {
  89. var matched = false;
  90. initCalendar({
  91. timezone: 'UTC',
  92. defaultDate: defaultDateInput,
  93. visibleRange: function(date) {
  94. // this function will receive the date for prev/next,
  95. // which should be ignored. make sure just one call matches.
  96. if (date.format() === defaultDateInput + 'Z') {
  97. matched = true;
  98. }
  99. }
  100. });
  101. expect(matched).toBe(true);
  102. });
  103. it('does not cause side effects when given date is mutated', function() {
  104. initCalendar({
  105. defaultDate: defaultDateInput,
  106. visibleRange: function(date) {
  107. date.add(1, 'year');
  108. }
  109. });
  110. expect(currentCalendar.getDate()).toEqualMoment(defaultDateInput);
  111. });
  112. });
  113. describe('when given an invalid range', function() {
  114. describeOptions('visibleRange', {
  115. 'with end before start': {
  116. start: '2017-06-18',
  117. end: '2017-06-15'
  118. },
  119. 'with no end': {
  120. start: '2017-06-18'
  121. },
  122. 'with no start': {
  123. end: '2017-06-15'
  124. }
  125. }, function() {
  126. it('defaults to the defaultDate', function() { // TODO: have it report an warning
  127. initCalendar({
  128. defaultDate: '2017-08-01'
  129. })
  130. ViewDateUtils.expectActiveRange('2017-08-01', '2017-08-02');
  131. });
  132. });
  133. });
  134. describe('when later switching to a one-day view', function() {
  135. it('constrains the current date to the start of visibleRange', function() {
  136. initCalendar({
  137. defaultDate: '2017-06-25',
  138. visibleRange: {
  139. start: '2017-06-26',
  140. end: '2017-06-29'
  141. }
  142. });
  143. currentCalendar.changeView('agendaDay');
  144. ViewDateUtils.expectActiveRange('2017-06-26', '2017-06-27');
  145. });
  146. it('constrains the current date to the end of visibleRange', function() {
  147. initCalendar({
  148. defaultDate: '2017-07-01',
  149. visibleRange: {
  150. start: '2017-06-26',
  151. end: '2017-06-29'
  152. }
  153. });
  154. currentCalendar.changeView('agendaDay');
  155. ViewDateUtils.expectActiveRange('2017-06-28', '2017-06-29');
  156. });
  157. });
  158. });
  159. describe('when a list view', function() {
  160. pushOptions({
  161. defaultView: 'list',
  162. visibleRange: {
  163. start: '2017-06-07',
  164. end: '2017-06-10'
  165. },
  166. events: [
  167. { start: '2017-06-08' }
  168. ]
  169. });
  170. it('respects the given range', function() {
  171. initCalendar();
  172. ViewDateUtils.expectActiveRange('2017-06-07', '2017-06-10');
  173. });
  174. });
  175. describe('when custom view with fixed duration', function() {
  176. pushOptions({
  177. defaultDate: '2015-06-08',
  178. defaultView: 'agenda',
  179. duration: { days: 3 }
  180. });
  181. it('ignores the given visibleRange', function() {
  182. initCalendar({
  183. visibleRange: {
  184. start: '2017-06-29',
  185. end: '2017-07-04'
  186. }
  187. });
  188. ViewDateUtils.expectActiveRange('2015-06-08', '2015-06-11');
  189. });
  190. });
  191. describe('when standard view', function() {
  192. pushOptions({
  193. defaultDate: '2015-06-08',
  194. defaultView: 'agendaWeek'
  195. });
  196. it('ignores the given visibleRange', function() {
  197. initCalendar({
  198. visibleRange: {
  199. start: '2017-06-29',
  200. end: '2017-07-04'
  201. }
  202. });
  203. ViewDateUtils.expectActiveRange('2015-06-07', '2015-06-14');
  204. });
  205. });
  206. });