titleFormat.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. describe('titleFormat', function() {
  2. var SELECTOR = '.fc-toolbar h2'
  3. beforeEach(function() {
  4. affix('#cal')
  5. })
  6. describe('when default', function() {
  7. var viewWithFormat = [
  8. { view: 'month', expected: 'June 2014' },
  9. { view: 'basicWeek', expected: /Jun 8 - 14,? 2014/ }, // moment changed LL defaults after 2.8
  10. { view: 'agendaWeek', expected: /Jun 8 - 14,? 2014/ }, // "
  11. { view: 'basicDay', expected: /June 12,? 2014/ }, // "
  12. { view: 'agendaDay', expected: /June 12,? 2014/ } // "
  13. ]
  14. beforeEach(function() {
  15. $('#cal').fullCalendar({
  16. defaultDate: '2014-06-12',
  17. titleRangeSeparator: ' - '
  18. })
  19. })
  20. it('should have default values', function() {
  21. var cal = $('#cal')
  22. for (var i = 0; i < viewWithFormat.length; i++) {
  23. var crtView = viewWithFormat[i]
  24. cal.fullCalendar('changeView', crtView.view)
  25. expect(cal.find(SELECTOR).text()).toMatch(crtView.expected)
  26. };
  27. })
  28. })
  29. describe('when set on a per-view basis', function() {
  30. var viewWithFormat = [
  31. { view: 'month', expected: '2014, June' },
  32. { view: 'basicWeek', expected: '8 - 14 6 2014' },
  33. { view: 'agendaWeek', expected: '8 - 14, 6, 2014' },
  34. { view: 'basicDay', expected: 'Thursday June 12 2014' },
  35. { view: 'agendaDay', expected: 'Thursday, June, 12, 2014' }
  36. ]
  37. beforeEach(function() {
  38. $('#cal').fullCalendar({
  39. defaultDate: '2014-06-12',
  40. titleRangeSeparator: ' - ',
  41. views: {
  42. month: { titleFormat: 'YYYY, MMMM' },
  43. basicWeek: { titleFormat: 'D M YYYY' },
  44. agendaWeek: { titleFormat: 'D, M, YYYY' },
  45. basicDay: { titleFormat: 'dddd MMMM D YYYY' },
  46. agendaDay: { titleFormat: 'dddd, MMMM, D, YYYY' }
  47. }
  48. })
  49. })
  50. it('should have the correct values', function() {
  51. var cal = $('#cal')
  52. for (var i = 0; i < viewWithFormat.length; i++) {
  53. var crtView = viewWithFormat[i]
  54. cal.fullCalendar('changeView', crtView.view)
  55. expect(cal.find(SELECTOR).text()).toBe(crtView.expected)
  56. };
  57. })
  58. })
  59. describe('when default and locale is French', function() {
  60. var viewWithFormat = [
  61. { view: 'month', expected: 'juin 2014' },
  62. { view: 'basicWeek', expected: '9 - 15 juin 2014' },
  63. { view: 'agendaWeek', expected: '9 - 15 juin 2014' },
  64. { view: 'basicDay', expected: '12 juin 2014' },
  65. { view: 'agendaDay', expected: '12 juin 2014' }
  66. ]
  67. beforeEach(function() {
  68. $('#cal').fullCalendar({
  69. defaultDate: '2014-06-12',
  70. titleRangeSeparator: ' - ',
  71. locale: 'fr'
  72. })
  73. })
  74. it('should have the translated dates', function() {
  75. var cal = $('#cal')
  76. for (var i = 0; i < viewWithFormat.length; i++) {
  77. var crtView = viewWithFormat[i]
  78. cal.fullCalendar('changeView', crtView.view)
  79. expect(cal.find(SELECTOR).text()).toBe(crtView.expected)
  80. };
  81. })
  82. })
  83. describe('using custom views', function() {
  84. it('multi-year default only displays year', function() {
  85. $('#cal').fullCalendar({
  86. views: {
  87. multiYear: {
  88. type: 'basic',
  89. duration: { years: 2 }
  90. }
  91. },
  92. defaultView: 'multiYear',
  93. defaultDate: '2014-12-25',
  94. titleRangeSeparator: ' - '
  95. })
  96. expect($('h2')).toHaveText('2014 - 2015')
  97. })
  98. it('multi-month default only displays month/year', function() {
  99. $('#cal').fullCalendar({
  100. views: {
  101. multiMonth: {
  102. type: 'basic',
  103. duration: { months: 2 }
  104. }
  105. },
  106. defaultView: 'multiMonth',
  107. defaultDate: '2014-12-25',
  108. titleRangeSeparator: ' - '
  109. })
  110. expect($('h2')).toHaveText('December 2014 - January 2015')
  111. })
  112. it('multi-week default displays short full date', function() {
  113. $('#cal').fullCalendar({
  114. views: {
  115. multiWeek: {
  116. type: 'basic',
  117. duration: { weeks: 2 }
  118. }
  119. },
  120. defaultView: 'multiWeek',
  121. defaultDate: '2014-12-25',
  122. titleRangeSeparator: ' - '
  123. })
  124. expect($('h2').text()).toMatch(/Dec 21,? 2014 - Jan 3,? 2015/)
  125. })
  126. it('multi-day default displays short full date', function() {
  127. $('#cal').fullCalendar({
  128. views: {
  129. multiDay: {
  130. type: 'basic',
  131. duration: { days: 2 }
  132. }
  133. },
  134. defaultView: 'multiDay',
  135. defaultDate: '2014-12-25',
  136. titleRangeSeparator: ' - '
  137. })
  138. expect($('h2').text()).toMatch(/Dec 25 - 26,? 2014/)
  139. })
  140. })
  141. describe('when not all days are shown', function() {
  142. it('doesn\'t include hidden days in the title', function() {
  143. $('#cal').fullCalendar({
  144. defaultView: 'agendaWeek',
  145. defaultDate: '2017-02-13',
  146. weekends: false,
  147. titleRangeSeparator: ' - '
  148. })
  149. expect($('h2')).toHaveText('Feb 13 - 17, 2017') // does not include Sunday
  150. })
  151. })
  152. })