Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. import moment from 'moment';
  2. import jalaali from './jalaali';
  3.  
  4. describe('Jalaali Conversion Tests', () => {
  5. moment.defineLocale('ps', {});
  6. const testScenarios = [
  7. {
  8. testMoment: moment('2019-01-01').locale('fa'),
  9. expected: '11 دی 1397',
  10. summary:
  11. 'should return first day of the year 2019 in Jalaali for persian',
  12. },
  13. {
  14. testMoment: moment('2019-12-31').locale('fa'),
  15. expected: '10 دی 1398',
  16. summary: 'should return last day of the year 2019 in Jalaali for persian',
  17. },
  18. {
  19. testMoment: moment('2025-02-01').locale('fa'),
  20. expected: '13 بهمن 1403',
  21. summary: 'should return first day of Febuary 2025 in Jalaali for persian',
  22. },
  23. {
  24. testMoment: moment('2025-11-31').locale('fa'),
  25. expected: null,
  26. summary: "should return null as date doesn't exist",
  27. },
  28. {
  29. testMoment: moment('31-2019-12').locale('fa'),
  30. expected: null,
  31. summary: 'should return null as this is an invalid moment',
  32. },
  33. {
  34. testMoment: moment('2019-01-01').locale('ps'),
  35. expected: '11 مرغومی 1397',
  36. summary: 'should return first day of the year 2019 in Jalaali for pashto',
  37. },
  38. {
  39. testMoment: moment('2019-12-31').locale('ps'),
  40. expected: '10 مرغومی 1398',
  41. summary: 'should return last day of the year 2019 in Jalaali for pashto',
  42. },
  43. {
  44. testMoment: moment('2025-02-01').locale('ps'),
  45. expected: '13 سلواغه 1403',
  46. summary: 'should return first day of Febuary 2025 in Jalaali for pashto',
  47. },
  48. {
  49. testMoment: moment('2025-11-31').locale('ps'),
  50. expected: null,
  51. summary: "should return null as date doesn't exist",
  52. },
  53. {
  54. testMoment: moment('31-2019-12').locale('ps'),
  55. expected: null,
  56. summary: 'should return null as this is an invalid moment',
  57. },
  58. {
  59. testMoment: null,
  60. expected: null,
  61. summary: 'should return null if item passed is null',
  62. },
  63. {
  64. testMoment: undefined,
  65. expected: null,
  66. summary: 'should return null if item passed is undefined',
  67. },
  68. {
  69. testMoment: {},
  70. expected: null,
  71. summary: 'should return null if item passed is a random object',
  72. },
  73. {
  74. testMoment: '',
  75. expected: null,
  76. summary: 'should return null if item passed is a string',
  77. },
  78. {
  79. testMoment: 2,
  80. expected: null,
  81. summary: 'should return null if item passed is an integer',
  82. },
  83. {
  84. testMoment: false,
  85. expected: null,
  86. summary: 'should return null if item passed is a boolean',
  87. },
  88. ];
  89. testScenarios.forEach(({ testMoment, expected, summary }) => {
  90. it(summary, () => {
  91. const jalaaliCalendar = jalaali.formatDate(testMoment);
  92. expect(jalaaliCalendar).toEqual(expected);
  93. });
  94. });
  95. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement