text_module.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // text module
  2. QUnit.test('test text module behaviour with group_ids', assert => {
  3. App.User.refresh([{
  4. "login": "hh@example.com",
  5. "firstname": "Harald",
  6. "lastname": "Habebe",
  7. "email": "hh@example.com",
  8. "role_ids": [ 1, 2, 4 ],
  9. "group_ids": [ 1, 2 ],
  10. "active": true,
  11. "updated_at": "2017-02-09T09:17:04.770Z",
  12. "address": "",
  13. "vip": false,
  14. "custom_key": undefined,
  15. "asdf": "",
  16. "id": 6
  17. }]);
  18. App.Session.set(6)
  19. // mock user methods
  20. App.Session.get().allGroupIds = () => ['1','2']
  21. App.Session.get().permission = () => true
  22. // active textmodule without group_ids
  23. App.TextModule.refresh([
  24. {
  25. id: 1,
  26. name: 'main',
  27. keywords: 'keywordsmain',
  28. content: 'contentmain',
  29. active: true,
  30. },
  31. {
  32. id: 2,
  33. name: 'test2',
  34. keywords: 'keywords2',
  35. content: 'content2',
  36. active: false,
  37. },
  38. {
  39. id: 3,
  40. name: 'test3',
  41. keywords: 'keywords3',
  42. content: 'content3',
  43. active: true,
  44. group_ids: [1,2],
  45. },
  46. {
  47. id: 4,
  48. name: 'test4',
  49. keywords: 'keywords4',
  50. content: 'content4',
  51. active: false,
  52. group_ids: [1,2],
  53. },
  54. {
  55. id: 5,
  56. name: 'test5',
  57. keywords: 'keywords5',
  58. content: 'content5',
  59. active: false,
  60. group_ids: [3],
  61. },
  62. ])
  63. var textModule = new App.WidgetTextModule({
  64. el: $('.js-textarea').parent(),
  65. data:{
  66. user: App.Session.get(),
  67. config: App.Config.all(),
  68. },
  69. taskKey: 'test1',
  70. })
  71. var currentCollection = textModule.currentCollection();
  72. assert.equal(currentCollection.length, 2, 'active textmodule')
  73. assert.equal(currentCollection[0].id, 1)
  74. assert.equal(currentCollection[1].id, 3)
  75. // trigered TextModulePreconditionUpdate with group_id
  76. var params = {
  77. group_id: 1
  78. }
  79. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
  80. currentCollection = textModule.currentCollection();
  81. assert.equal(currentCollection.length, 2, 'trigered TextModulePreconditionUpdate with group_id')
  82. assert.equal(currentCollection[0].id, 1)
  83. assert.equal(currentCollection[1].id, 3)
  84. // trigered TextModulePreconditionUpdate with wrong group_id
  85. params = {
  86. group_id: 3
  87. }
  88. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
  89. currentCollection = textModule.currentCollection();
  90. assert.equal(currentCollection.length, 1, 'trigered TextModulePreconditionUpdate with wrong group_id')
  91. assert.equal(currentCollection[0].id, 1)
  92. // trigered TextModulePreconditionUpdate with group_id but wrong taskKey
  93. params = {
  94. group_id: 3
  95. }
  96. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test2', params: params })
  97. currentCollection = textModule.currentCollection();
  98. assert.equal(currentCollection.length, 1, 'trigered TextModulePreconditionUpdate with group_id but wrong taskKey - nothing has changed')
  99. assert.equal(currentCollection[0].id, 1)
  100. // trigered TextModulePreconditionUpdate without group_id
  101. params = {
  102. owner_id: 2
  103. }
  104. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
  105. currentCollection = textModule.currentCollection();
  106. assert.equal(currentCollection.length, 2, 'trigered TextModulePreconditionUpdate without group_id')
  107. assert.equal(currentCollection[0].id, 1)
  108. assert.equal(currentCollection[1].id, 3)
  109. });