notification_utils.spec.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js'
  2. describe('NotificationUtils', () => {
  3. describe('visibleNotificationsFromStore', () => {
  4. it('should return sorted notifications with configured types', () => {
  5. const store = {
  6. state: {
  7. statuses: {
  8. notifications: {
  9. data: [
  10. {
  11. id: 1,
  12. action: { id: '1' },
  13. type: 'like'
  14. },
  15. {
  16. id: 2,
  17. action: { id: '2' },
  18. type: 'mention'
  19. },
  20. {
  21. id: 3,
  22. action: { id: '3' },
  23. type: 'repeat'
  24. }
  25. ]
  26. }
  27. },
  28. config: {
  29. notificationVisibility: {
  30. likes: true,
  31. repeats: true,
  32. mentions: false
  33. }
  34. }
  35. }
  36. }
  37. const expected = [
  38. {
  39. action: { id: '3' },
  40. id: 3,
  41. type: 'repeat'
  42. },
  43. {
  44. action: { id: '1' },
  45. id: 1,
  46. type: 'like'
  47. }
  48. ]
  49. expect(NotificationUtils.visibleNotificationsFromStore(store)).to.eql(expected)
  50. })
  51. })
  52. describe('unseenNotificationsFromStore', () => {
  53. it('should return only notifications not marked as seen', () => {
  54. const store = {
  55. state: {
  56. statuses: {
  57. notifications: {
  58. data: [
  59. {
  60. action: { id: '1' },
  61. type: 'like',
  62. seen: false
  63. },
  64. {
  65. action: { id: '2' },
  66. type: 'mention',
  67. seen: true
  68. }
  69. ]
  70. }
  71. },
  72. config: {
  73. notificationVisibility: {
  74. likes: true,
  75. repeats: true,
  76. mentions: false
  77. }
  78. }
  79. }
  80. }
  81. const expected = [
  82. {
  83. action: { id: '1' },
  84. type: 'like',
  85. seen: false
  86. }
  87. ]
  88. expect(NotificationUtils.unseenNotificationsFromStore(store)).to.eql(expected)
  89. })
  90. })
  91. })