taskbar.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. window.onload = function() {
  2. QUnit.test( "taskbar basic tests", assert => {
  3. // create task bar div
  4. $('#qunit').append('<hr><h1>taskbar basic tests</h1><div id="taskbar1"></div>')
  5. App.TaskManager.init({
  6. el: $('#taskbar1'),
  7. offlineModus: true,
  8. force: true,
  9. })
  10. // add tasks
  11. App.TaskManager.execute({
  12. key: 'TestKey1',
  13. controller: 'TestController1',
  14. params: {
  15. message: '#1',
  16. },
  17. show: true,
  18. persistent: false,
  19. })
  20. assert.equal($('#qunit .content').length, 1, "check available active contents")
  21. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  22. assert.equal($('#qunit .content.active').text(), "some test controller message:'#1',show:'true',hide:'false',active:'true'", "check active content!")
  23. // verify
  24. task = App.TaskManager.get('TestKey1')
  25. assert.equal(task.notify, false)
  26. assert.deepEqual(task.state, undefined)
  27. assert.deepEqual(task.params, { "message": "#1", "shown": true })
  28. // update
  29. App.TaskManager.update('TestKey1', { 'state': 'abc' })
  30. App.TaskManager.update('TestKey1', { 'params': { a: 12 } })
  31. App.TaskManager.notify('TestKey1')
  32. // verify
  33. task = App.TaskManager.get('TestKey1')
  34. assert.equal(task.notify, true)
  35. assert.deepEqual(task.state, 'abc')
  36. assert.deepEqual(task.params, { "a": 12 })
  37. App.TaskManager.execute({
  38. key: 'TestKey2',
  39. controller: 'TestController1',
  40. params: {
  41. message: '#2',
  42. },
  43. show: true,
  44. persistent: false,
  45. })
  46. assert.equal($('#qunit .content').length, 2, "check available active contents")
  47. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  48. assert.equal($('#qunit .content.active').text(), "some test controller message:'#2',show:'true',hide:'false',active:'true'", "check active content!")
  49. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  50. assert.equal($('#qunit #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'false',active:'true'", "check active content!")
  51. // check task history
  52. assert.equal(App.TaskManager.nextTaskUrl(), '#/some/url/#2')
  53. assert.equal(App.TaskManager.nextTaskUrl(), '#/some/url/#1')
  54. App.TaskManager.execute({
  55. key: 'TestKey3',
  56. controller: 'TestController1',
  57. params: {
  58. message: '#3',
  59. },
  60. show: false,
  61. persistent: false,
  62. })
  63. assert.equal($('#qunit .content').length, 2, "check available active contents")
  64. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  65. assert.equal($('#qunit .content.active').text(), "some test controller message:'#2',show:'true',hide:'false',active:'true'")
  66. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  67. assert.equal($('#qunit #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'false',active:'true'", "check active content!")
  68. App.TaskManager.execute({
  69. key: 'TestKey3',
  70. controller: 'TestController1',
  71. params: {
  72. message: '#3',
  73. },
  74. show: true,
  75. persistent: false,
  76. })
  77. assert.equal($('#qunit .content').length, 3, "check available active contents")
  78. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  79. assert.equal($('#qunit .content.active').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  80. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  81. assert.equal($('#qunit #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  82. assert.equal($('#qunit #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  83. App.TaskManager.execute({
  84. key: 'TestKey4',
  85. controller: 'TestController1',
  86. params: {
  87. message: '#4',
  88. },
  89. show: false,
  90. persistent: true,
  91. })
  92. assert.equal($('#qunit .content').length, 3, "check available active contents")
  93. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  94. assert.equal($('#qunit .content.active').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  95. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  96. assert.equal($('#qunit #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  97. assert.equal($('#qunit #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  98. App.TaskManager.execute({
  99. key: 'TestKey5',
  100. controller: 'TestController1',
  101. params: {
  102. message: '#5',
  103. },
  104. show: true,
  105. persistent: true,
  106. })
  107. assert.equal($('#qunit .content').length, 4, "check available active contents")
  108. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  109. assert.equal($('#qunit .content.active').text(), "some test controller message:'#5',show:'true',hide:'false',active:'true'")
  110. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  111. assert.equal($('#qunit #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  112. assert.equal($('#qunit #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  113. assert.equal($('#qunit #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'false',active:'true'", "check active content!")
  114. App.TaskManager.execute({
  115. key: 'TestKey6',
  116. controller: 'TestController1',
  117. params: {
  118. message: '#6',
  119. },
  120. show: true,
  121. persistent: false,
  122. })
  123. assert.equal($('#qunit .content').length, 5, "check available active contents")
  124. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  125. assert.equal($('#qunit .content.active').text(), "some test controller message:'#6',show:'true',hide:'false',active:'true'")
  126. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  127. assert.equal($('#qunit #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  128. assert.equal($('#qunit #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  129. assert.equal($('#qunit #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  130. assert.equal($('#qunit #content_permanent_TestKey6').text(), "some test controller message:'#6',show:'true',hide:'false',active:'true'", "check active content!")
  131. // remove task#2
  132. App.TaskManager.remove('TestKey2')
  133. assert.equal($('#qunit .content').length, 4, "check available active contents")
  134. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  135. assert.equal($('#qunit .content.active').text(), "some test controller message:'#6',show:'true',hide:'false',active:'true'")
  136. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  137. assert.equal($('#qunit #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  138. assert.equal($('#qunit #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  139. assert.equal($('#qunit #content_permanent_TestKey6').text(), "some test controller message:'#6',show:'true',hide:'false',active:'true'", "check active content!")
  140. // activate task#3
  141. App.TaskManager.execute({
  142. key: 'TestKey3',
  143. controller: 'TestController1',
  144. params: {
  145. message: '#3',
  146. },
  147. show: true,
  148. persistent: false,
  149. })
  150. assert.equal($('#qunit .content').length, 4, "check available active contents")
  151. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  152. assert.equal($('#qunit .content.active').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'")
  153. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  154. assert.equal($('#qunit #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  155. assert.equal($('#qunit #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  156. assert.equal($('#qunit #content_permanent_TestKey6').text(), "some test controller message:'#6',show:'true',hide:'true',active:'false'", "check active content!")
  157. // activate task#1
  158. App.TaskManager.execute({
  159. key: 'TestKey1',
  160. controller: 'TestController1',
  161. params: {
  162. message: '#1',
  163. },
  164. show: true,
  165. persistent: false,
  166. })
  167. assert.equal($('#qunit .content').length, 4, "check available active contents")
  168. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  169. assert.equal($('#qunit .content.active').text(), "some test controller message:'#1',show:'true',hide:'true',active:'true'")
  170. assert.equal($('#qunit #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'true'", "check active content!")
  171. assert.equal($('#qunit #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  172. assert.equal($('#qunit #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  173. assert.equal($('#qunit #content_permanent_TestKey6').text(), "some test controller message:'#6',show:'true',hide:'true',active:'false'", "check active content!")
  174. // remove task#1
  175. App.TaskManager.remove('TestKey1')
  176. // verify if task#3 is active
  177. assert.equal($('#qunit .content').length, 3, "check available active contents")
  178. assert.equal($('#qunit .content.active').length, 0, "check available active contents")
  179. assert.equal($('#qunit .content.active').text(), "")
  180. // remove task#3
  181. App.TaskManager.remove('TestKey3')
  182. // verify if task#5 is active
  183. assert.equal($('#qunit .content').length, 2, "check available active contents")
  184. assert.equal($('#qunit .content.active').length, 0, "check available active contents")
  185. assert.equal($('#qunit .content.active').text(), "")
  186. // remove task#5 // can not get removed because of permanent task
  187. App.TaskManager.remove('TestKey5')
  188. // verify if task#5 is active
  189. assert.equal($('#qunit .content').length, 2, "check available active contents")
  190. assert.equal($('#qunit .content.active').length, 0, "check available active contents")
  191. assert.equal($('#qunit .content.active').text(), "")
  192. // create task#7
  193. App.TaskManager.execute({
  194. key: 'TestKey7',
  195. controller: 'TestController1',
  196. params: {
  197. message: '#7',
  198. },
  199. show: true,
  200. persistent: false,
  201. })
  202. assert.equal($('#qunit .content').length, 3, "check available active contents")
  203. assert.equal($('#qunit .content.active').length, 1, "check available active contents")
  204. assert.equal($('#qunit .content.active').text(), "some test controller message:'#7',show:'true',hide:'false',active:'true'", "check active content!")
  205. // remove task#7
  206. App.TaskManager.remove('TestKey7')
  207. // verify if task#5 is active
  208. assert.equal($('#qunit .content').length, 2, "check available active contents")
  209. assert.equal($('#qunit .content.active').length, 0, "check available active contents")
  210. assert.equal($('#qunit .content.active').text(), "")
  211. // check task history
  212. assert.equal(App.TaskManager.nextTaskUrl(), '#/some/url/#6')
  213. assert.equal(App.TaskManager.nextTaskUrl(), '#/some/url/#5')
  214. assert.equal(App.TaskManager.nextTaskUrl(), '#/some/url/#6')
  215. assert.equal(App.TaskManager.nextTaskUrl(), '#/some/url/#6')
  216. // remove task#6
  217. App.TaskManager.remove('TestKey6')
  218. // check task history
  219. assert.equal(App.TaskManager.nextTaskUrl(), false)
  220. assert.equal(App.TaskManager.nextTaskUrl(), false)
  221. // check max tabs
  222. var times = 5;
  223. App.TaskManager.tasksAutoCleanupDelayTime(200)
  224. App.Config.set('ui_task_mananger_max_task_count', 3)
  225. for(var i=0; i < times; i++){
  226. App.TaskManager.execute({
  227. key: 'TestKeyLoop' + i,
  228. controller: 'TestController1',
  229. params: {
  230. message: "#" + i,
  231. },
  232. show: true,
  233. persistent: false,
  234. })
  235. }
  236. assert.equal(App.TaskManager.all().length, 5)
  237. })
  238. App.Delay.set(function() {
  239. QUnit.test( "taskbar check max tabs 2", assert => {
  240. assert.equal(App.TaskManager.all().length, 3)
  241. var times = 5;
  242. for(var i=0; i < times; i++){
  243. App.TaskManager.execute({
  244. key: 'TestKeyLoop2' + i,
  245. controller: 'TestController1',
  246. params: {
  247. message: "#" + i,
  248. changedState: true
  249. },
  250. show: true,
  251. persistent: false,
  252. })
  253. }
  254. assert.equal(App.TaskManager.all().length, 8)
  255. })
  256. }, 1000);
  257. App.Delay.set(function() {
  258. QUnit.test( "taskbar check max tabs 5", assert => {
  259. assert.equal(App.TaskManager.all().length, 5)
  260. // destroy task bar
  261. App.TaskManager.reset()
  262. // check if any taskar exists
  263. assert.equal($('#qunit .content').length, 0, "check available active contents")
  264. })
  265. }, 2000);
  266. }