taskbar.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. window.onload = function() {
  2. test( "taskbar basic tests", function() {
  3. // create task bar div
  4. $('#taskbars').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. equal($('#taskbars .content').length, 1, "check available active contents")
  21. equal($('#taskbars .content.active').length, 1, "check available active contents")
  22. equal($('#taskbars .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. equal(task.notify, false)
  26. deepEqual(task.state, undefined)
  27. 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. equal(task.notify, true)
  35. deepEqual(task.state, 'abc')
  36. 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. equal($('#taskbars .content').length, 2, "check available active contents")
  47. equal($('#taskbars .content.active').length, 1, "check available active contents")
  48. equal($('#taskbars .content.active').text(), "some test controller message:'#2',show:'true',hide:'false',active:'true'", "check active content!")
  49. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  50. equal($('#taskbars #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'false',active:'true'", "check active content!")
  51. // check task history
  52. equal(App.TaskManager.nextTaskUrl(), '#/some/url/#2')
  53. 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. equal($('#taskbars .content').length, 2, "check available active contents")
  64. equal($('#taskbars .content.active').length, 1, "check available active contents")
  65. equal($('#taskbars .content.active').text(), "some test controller message:'#2',show:'true',hide:'false',active:'true'")
  66. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  67. equal($('#taskbars #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. equal($('#taskbars .content').length, 3, "check available active contents")
  78. equal($('#taskbars .content.active').length, 1, "check available active contents")
  79. equal($('#taskbars .content.active').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  80. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  81. equal($('#taskbars #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  82. equal($('#taskbars #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. equal($('#taskbars .content').length, 3, "check available active contents")
  93. equal($('#taskbars .content.active').length, 1, "check available active contents")
  94. equal($('#taskbars .content.active').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  95. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  96. equal($('#taskbars #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  97. equal($('#taskbars #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. equal($('#taskbars .content').length, 4, "check available active contents")
  108. equal($('#taskbars .content.active').length, 1, "check available active contents")
  109. equal($('#taskbars .content.active').text(), "some test controller message:'#5',show:'true',hide:'false',active:'true'")
  110. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  111. equal($('#taskbars #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  112. equal($('#taskbars #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  113. equal($('#taskbars #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. equal($('#taskbars .content').length, 5, "check available active contents")
  124. equal($('#taskbars .content.active').length, 1, "check available active contents")
  125. equal($('#taskbars .content.active').text(), "some test controller message:'#6',show:'true',hide:'false',active:'true'")
  126. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  127. equal($('#taskbars #content_permanent_TestKey2').text(), "some test controller message:'#2',show:'true',hide:'true',active:'false'", "check active content!")
  128. equal($('#taskbars #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  129. equal($('#taskbars #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  130. equal($('#taskbars #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. equal($('#taskbars .content').length, 4, "check available active contents")
  134. equal($('#taskbars .content.active').length, 1, "check available active contents")
  135. equal($('#taskbars .content.active').text(), "some test controller message:'#6',show:'true',hide:'false',active:'true'")
  136. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  137. equal($('#taskbars #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  138. equal($('#taskbars #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  139. equal($('#taskbars #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. equal($('#taskbars .content').length, 4, "check available active contents")
  151. equal($('#taskbars .content.active').length, 1, "check available active contents")
  152. equal($('#taskbars .content.active').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'")
  153. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'false'", "check active content!")
  154. equal($('#taskbars #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'true'", "check active content!")
  155. equal($('#taskbars #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  156. equal($('#taskbars #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. equal($('#taskbars .content').length, 4, "check available active contents")
  168. equal($('#taskbars .content.active').length, 1, "check available active contents")
  169. equal($('#taskbars .content.active').text(), "some test controller message:'#1',show:'true',hide:'true',active:'true'")
  170. equal($('#taskbars #content_permanent_TestKey1').text(), "some test controller message:'#1',show:'true',hide:'true',active:'true'", "check active content!")
  171. equal($('#taskbars #content_permanent_TestKey3').text(), "some test controller message:'#3',show:'true',hide:'true',active:'false'", "check active content!")
  172. equal($('#taskbars #content_permanent_TestKey5').text(), "some test controller message:'#5',show:'true',hide:'true',active:'false'", "check active content!")
  173. equal($('#taskbars #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. equal($('#taskbars .content').length, 3, "check available active contents")
  178. equal($('#taskbars .content.active').length, 0, "check available active contents")
  179. equal($('#taskbars .content.active').text(), "")
  180. // remove task#3
  181. App.TaskManager.remove('TestKey3')
  182. // verify if task#5 is active
  183. equal($('#taskbars .content').length, 2, "check available active contents")
  184. equal($('#taskbars .content.active').length, 0, "check available active contents")
  185. equal($('#taskbars .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. equal($('#taskbars .content').length, 2, "check available active contents")
  190. equal($('#taskbars .content.active').length, 0, "check available active contents")
  191. equal($('#taskbars .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. equal($('#taskbars .content').length, 3, "check available active contents")
  203. equal($('#taskbars .content.active').length, 1, "check available active contents")
  204. equal($('#taskbars .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. equal($('#taskbars .content').length, 2, "check available active contents")
  209. equal($('#taskbars .content.active').length, 0, "check available active contents")
  210. equal($('#taskbars .content.active').text(), "")
  211. // check task history
  212. equal(App.TaskManager.nextTaskUrl(), '#/some/url/#6')
  213. equal(App.TaskManager.nextTaskUrl(), '#/some/url/#5')
  214. equal(App.TaskManager.nextTaskUrl(), '#/some/url/#6')
  215. equal(App.TaskManager.nextTaskUrl(), '#/some/url/#6')
  216. // remove task#6
  217. App.TaskManager.remove('TestKey6')
  218. // check task history
  219. equal(App.TaskManager.nextTaskUrl(), false)
  220. equal(App.TaskManager.nextTaskUrl(), false)
  221. // destroy task bar
  222. App.TaskManager.reset()
  223. // check if any taskar exists
  224. equal($('#taskbars .content').length, 0, "check available active contents")
  225. })
  226. }