weekNumberCalculation.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. describe('weekNumberCalculation', function() {
  2. var options;
  3. beforeEach(function() {
  4. options = {
  5. weekNumbers: true
  6. };
  7. });
  8. function getRenderedWeekText() {
  9. // works for both kinds of views
  10. return $('.fc-agenda-view .fc-week-number, .fc-week:first .fc-content-skeleton .fc-week-number').text();
  11. }
  12. function getRenderedWeekNumber() {
  13. var text = getRenderedWeekText() || '';
  14. return parseInt(text.replace(/\D/g, ''), 10);
  15. }
  16. beforeEach(function() {
  17. affix('#cal');
  18. });
  19. [ 'basicDay', 'agendaDay' ].forEach(function(viewType) {
  20. describe('when in ' + viewType + ' view', function() {
  21. beforeEach(function() {
  22. options.defaultView = viewType;
  23. });
  24. it('should display the American standard when using \'local\'', function() {
  25. options.defaultDate = '2013-11-23'; // a Saturday
  26. options.weekNumberCalculation = 'local';
  27. $('#cal').fullCalendar(options);
  28. expect(getRenderedWeekNumber()).toBe(47);
  29. });
  30. it('should display a locale-specific local week number', function() {
  31. options.defaultDate = '2013-11-23'; // a Saturday
  32. options.locale = 'ar';
  33. options.weekNumberCalculation = 'local';
  34. $('#cal').fullCalendar(options);
  35. expect(getRenderedWeekText()).toMatch(/٤٨|48/);
  36. });
  37. // another local test, but to make sure it is different from ISO
  38. it('should display the American standard when using \'local\'', function() {
  39. options.defaultDate = '2013-11-17'; // a Sunday
  40. options.weekNumberCalculation = 'local';
  41. $('#cal').fullCalendar(options);
  42. expect(getRenderedWeekNumber()).toBe(47);
  43. });
  44. it('should display ISO standard when using \'ISO\'', function() {
  45. options.defaultDate = '2013-11-17'; // a Sunday
  46. options.weekNumberCalculation = 'ISO';
  47. $('#cal').fullCalendar(options);
  48. expect(getRenderedWeekNumber()).toBe(46);
  49. });
  50. it('should display the calculated number when a custom function', function() {
  51. options.weekNumberCalculation = function() {
  52. return 4;
  53. };
  54. $('#cal').fullCalendar(options);
  55. expect(getRenderedWeekNumber()).toBe(4);
  56. });
  57. });
  58. });
  59. });