notification_utils.spec.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. action: { id: '1' },
  12. type: 'like'
  13. },
  14. {
  15. action: { id: '2' },
  16. type: 'mention'
  17. },
  18. {
  19. action: { id: '3' },
  20. type: 'repeat'
  21. }
  22. ]
  23. }
  24. },
  25. config: {
  26. notificationVisibility: {
  27. likes: true,
  28. repeats: true,
  29. mentions: false
  30. }
  31. }
  32. }
  33. }
  34. const expected = [
  35. {
  36. action: { id: '3' },
  37. type: 'repeat'
  38. },
  39. {
  40. action: { id: '1' },
  41. type: 'like'
  42. }
  43. ]
  44. expect(NotificationUtils.visibleNotificationsFromStore(store)).to.eql(expected)
  45. })
  46. })
  47. describe('unseenNotificationsFromStore', () => {
  48. it('should return only notifications not marked as seen', () => {
  49. const store = {
  50. state: {
  51. statuses: {
  52. notifications: {
  53. data: [
  54. {
  55. action: { id: '1' },
  56. type: 'like',
  57. seen: false
  58. },
  59. {
  60. action: { id: '2' },
  61. type: 'mention',
  62. seen: true
  63. }
  64. ]
  65. }
  66. },
  67. config: {
  68. notificationVisibility: {
  69. likes: true,
  70. repeats: true,
  71. mentions: false
  72. }
  73. }
  74. }
  75. }
  76. const expected = [
  77. {
  78. action: { id: '1' },
  79. type: 'like',
  80. seen: false
  81. }
  82. ]
  83. expect(NotificationUtils.unseenNotificationsFromStore(store)).to.eql(expected)
  84. })
  85. })
  86. })