text_module.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // text module
  2. QUnit.test('test text module behaviour with group_ids', assert => {
  3. // active textmodule without group_ids
  4. App.TextModule.refresh([
  5. {
  6. id: 1,
  7. name: 'main',
  8. keywords: 'keywordsmain',
  9. content: 'contentmain',
  10. active: true,
  11. },
  12. {
  13. id: 2,
  14. name: 'test2',
  15. keywords: 'keywords2',
  16. content: 'content2',
  17. active: false,
  18. },
  19. {
  20. id: 3,
  21. name: 'test3',
  22. keywords: 'keywords3',
  23. content: 'content3',
  24. active: true,
  25. group_ids: [1,2],
  26. },
  27. {
  28. id: 4,
  29. name: 'test4',
  30. keywords: 'keywords4',
  31. content: 'content4',
  32. active: false,
  33. group_ids: [1,2],
  34. },
  35. ])
  36. var textModule = new App.WidgetTextModule({
  37. el: $('.js-textarea').parent(),
  38. data:{
  39. user: App.Session.get(),
  40. config: App.Config.all(),
  41. },
  42. taskKey: 'test1',
  43. })
  44. var currentCollection = textModule.currentCollection();
  45. assert.equal(currentCollection.length, 2, 'active textmodule')
  46. assert.equal(currentCollection[0].id, 1)
  47. assert.equal(currentCollection[1].id, 3)
  48. // trigered TextModulePreconditionUpdate with group_id
  49. var params = {
  50. group_id: 1
  51. }
  52. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
  53. currentCollection = textModule.currentCollection();
  54. assert.equal(currentCollection.length, 2, 'trigered TextModulePreconditionUpdate with group_id')
  55. assert.equal(currentCollection[0].id, 1)
  56. assert.equal(currentCollection[1].id, 3)
  57. // trigered TextModulePreconditionUpdate with wrong group_id
  58. params = {
  59. group_id: 3
  60. }
  61. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
  62. currentCollection = textModule.currentCollection();
  63. assert.equal(currentCollection.length, 1, 'trigered TextModulePreconditionUpdate with wrong group_id')
  64. assert.equal(currentCollection[0].id, 1)
  65. // trigered TextModulePreconditionUpdate with group_id but wrong taskKey
  66. params = {
  67. group_id: 3
  68. }
  69. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test2', params: params })
  70. currentCollection = textModule.currentCollection();
  71. assert.equal(currentCollection.length, 1, 'trigered TextModulePreconditionUpdate with group_id but wrong taskKey - nothing has changed')
  72. assert.equal(currentCollection[0].id, 1)
  73. // trigered TextModulePreconditionUpdate without group_id
  74. params = {
  75. owner_id: 2
  76. }
  77. App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
  78. currentCollection = textModule.currentCollection();
  79. assert.equal(currentCollection.length, 2, 'trigered TextModulePreconditionUpdate without group_id')
  80. assert.equal(currentCollection[0].id, 1)
  81. assert.equal(currentCollection[1].id, 3)
  82. });