taskbar_spec.rb 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. require 'rails_helper'
  2. RSpec.describe Taskbar do
  3. context 'single creation' do
  4. Taskbar.destroy_all
  5. UserInfo.current_user_id = 1
  6. taskbar = Taskbar.create(
  7. client_id: 123,
  8. key: 'Ticket-1234',
  9. callback: 'TicketZoom',
  10. params: {
  11. id: 1234,
  12. },
  13. state: {},
  14. prio: 1,
  15. notify: false,
  16. )
  17. it 'existing key' do
  18. expect(taskbar.key).to eq('Ticket-1234')
  19. end
  20. it 'params' do
  21. expect(taskbar.params[:id]).to eq(1234)
  22. end
  23. it 'state' do
  24. expect(taskbar.state.blank?).to eq(true)
  25. end
  26. it 'check last_contact' do
  27. UserInfo.current_user_id = 1
  28. last_contact1 = taskbar.last_contact
  29. travel 2.minutes
  30. taskbar.notify = false
  31. taskbar.state = { a: 1 }
  32. taskbar.save!
  33. expect(taskbar.last_contact.to_s).not_to eq(last_contact1.to_s)
  34. last_contact2 = taskbar.last_contact
  35. travel 2.minutes
  36. taskbar.notify = true
  37. taskbar.save!
  38. expect(taskbar.last_contact.to_s).not_to eq(last_contact1.to_s)
  39. expect(taskbar.last_contact.to_s).to eq(last_contact2.to_s)
  40. travel 2.minutes
  41. taskbar.notify = true
  42. taskbar.save!
  43. expect(taskbar.last_contact.to_s).not_to eq(last_contact1.to_s)
  44. expect(taskbar.last_contact.to_s).to eq(last_contact2.to_s)
  45. travel 2.minutes
  46. taskbar.notify = false
  47. taskbar.state = { a: 1 }
  48. taskbar.save!
  49. expect(taskbar.last_contact.to_s).not_to eq(last_contact1.to_s)
  50. expect(taskbar.last_contact.to_s).to eq(last_contact2.to_s)
  51. travel 2.minutes
  52. taskbar.notify = true
  53. taskbar.state = { a: 1 }
  54. taskbar.save!
  55. expect(taskbar.last_contact.to_s).not_to eq(last_contact1.to_s)
  56. expect(taskbar.last_contact.to_s).to eq(last_contact2.to_s)
  57. travel 2.minutes
  58. taskbar.notify = true
  59. taskbar.state = { a: 2 }
  60. taskbar.save!
  61. expect(taskbar.last_contact.to_s).not_to eq(last_contact1.to_s)
  62. expect(taskbar.last_contact.to_s).not_to eq(last_contact2.to_s)
  63. travel_back
  64. end
  65. UserInfo.current_user_id = nil
  66. end
  67. context 'multible creation' do
  68. it 'create tasks' do
  69. Taskbar.destroy_all
  70. UserInfo.current_user_id = 1
  71. taskbar1 = Taskbar.create(
  72. client_id: 123,
  73. key: 'Ticket-1234',
  74. callback: 'TicketZoom',
  75. params: {
  76. id: 1234,
  77. },
  78. state: {},
  79. prio: 1,
  80. notify: false,
  81. )
  82. UserInfo.current_user_id = 2
  83. taskbar2 = Taskbar.create(
  84. client_id: 123,
  85. key: 'Ticket-1234',
  86. callback: 'TicketZoom',
  87. params: {
  88. id: 1234,
  89. },
  90. state: {},
  91. prio: 2,
  92. notify: false,
  93. )
  94. taskbar1.reload
  95. expect(taskbar1.preferences[:tasks].count).to eq(2)
  96. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  97. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false)
  98. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  99. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(false)
  100. taskbar2.reload
  101. expect(taskbar2.preferences[:tasks].count).to eq(2)
  102. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  103. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false)
  104. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  105. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(false)
  106. taskbar3 = Taskbar.create(
  107. client_id: 123,
  108. key: 'Ticket-4444',
  109. callback: 'TicketZoom',
  110. params: {
  111. id: 4444,
  112. },
  113. state: {},
  114. prio: 2,
  115. notify: false,
  116. )
  117. taskbar1.reload
  118. expect(taskbar1.preferences[:tasks].count).to eq(2)
  119. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  120. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false)
  121. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  122. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(false)
  123. taskbar2.reload
  124. expect(taskbar2.preferences[:tasks].count).to eq(2)
  125. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  126. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false)
  127. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  128. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(false)
  129. taskbar3.reload
  130. expect(taskbar3.preferences[:tasks].count).to eq(1)
  131. expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2)
  132. expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false)
  133. UserInfo.current_user_id = 3
  134. taskbar4 = Taskbar.create(
  135. client_id: 123,
  136. key: 'Ticket-1234',
  137. callback: 'TicketZoom',
  138. params: {
  139. id: 1234,
  140. },
  141. state: {},
  142. prio: 4,
  143. notify: false,
  144. )
  145. taskbar1.reload
  146. expect(taskbar1.preferences[:tasks].count).to eq(3)
  147. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  148. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false)
  149. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  150. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(false)
  151. expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(3)
  152. expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false)
  153. taskbar2.reload
  154. expect(taskbar2.preferences[:tasks].count).to eq(3)
  155. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  156. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false)
  157. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  158. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(false)
  159. expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(3)
  160. expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false)
  161. taskbar3.reload
  162. expect(taskbar3.preferences[:tasks].count).to eq(1)
  163. expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2)
  164. expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false)
  165. taskbar4.reload
  166. expect(taskbar4.preferences[:tasks].count).to eq(3)
  167. expect(taskbar4.preferences[:tasks][0][:user_id]).to eq(1)
  168. expect(taskbar4.preferences[:tasks][0][:changed]).to eq(false)
  169. expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2)
  170. expect(taskbar4.preferences[:tasks][1][:changed]).to eq(false)
  171. expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(3)
  172. expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false)
  173. UserInfo.current_user_id = 2
  174. taskbar2.state = { article: {}, ticket: {} }
  175. taskbar2.save!
  176. taskbar1.reload
  177. expect(taskbar1.preferences[:tasks].count).to eq(3)
  178. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  179. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false)
  180. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  181. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(false)
  182. expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(3)
  183. expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false)
  184. taskbar2.reload
  185. expect(taskbar2.preferences[:tasks].count).to eq(3)
  186. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  187. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false)
  188. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  189. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(false)
  190. expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(3)
  191. expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false)
  192. taskbar3.reload
  193. expect(taskbar3.preferences[:tasks].count).to eq(1)
  194. expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2)
  195. expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false)
  196. taskbar4.reload
  197. expect(taskbar4.preferences[:tasks].count).to eq(3)
  198. expect(taskbar4.preferences[:tasks][0][:user_id]).to eq(1)
  199. expect(taskbar4.preferences[:tasks][0][:changed]).to eq(false)
  200. expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2)
  201. expect(taskbar4.preferences[:tasks][1][:changed]).to eq(false)
  202. expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(3)
  203. expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false)
  204. UserInfo.current_user_id = 2
  205. taskbar2.state = { article: { body: 'some body' }, ticket: {} }
  206. taskbar2.save!
  207. taskbar1.reload
  208. expect(taskbar1.preferences[:tasks].count).to eq(3)
  209. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  210. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(false)
  211. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  212. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true)
  213. expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(3)
  214. expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false)
  215. taskbar2.reload
  216. expect(taskbar2.preferences[:tasks].count).to eq(3)
  217. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  218. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(false)
  219. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  220. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true)
  221. expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(3)
  222. expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false)
  223. taskbar3.reload
  224. expect(taskbar3.preferences[:tasks].count).to eq(1)
  225. expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2)
  226. expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false)
  227. taskbar4.reload
  228. expect(taskbar4.preferences[:tasks].count).to eq(3)
  229. expect(taskbar4.preferences[:tasks][0][:user_id]).to eq(1)
  230. expect(taskbar4.preferences[:tasks][0][:changed]).to eq(false)
  231. expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2)
  232. expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true)
  233. expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(3)
  234. expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false)
  235. UserInfo.current_user_id = 1
  236. taskbar1.state = { article: { body: '' }, ticket: { state_id: 123 } }
  237. taskbar1.save!
  238. taskbar1.reload
  239. expect(taskbar1.preferences[:tasks].count).to eq(3)
  240. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  241. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(true)
  242. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  243. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true)
  244. expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(3)
  245. expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false)
  246. taskbar2.reload
  247. expect(taskbar2.preferences[:tasks].count).to eq(3)
  248. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  249. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(true)
  250. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  251. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true)
  252. expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(3)
  253. expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false)
  254. taskbar3.reload
  255. expect(taskbar3.preferences[:tasks].count).to eq(1)
  256. expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2)
  257. expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false)
  258. taskbar4.reload
  259. expect(taskbar4.preferences[:tasks].count).to eq(3)
  260. expect(taskbar4.preferences[:tasks][0][:user_id]).to eq(1)
  261. expect(taskbar4.preferences[:tasks][0][:changed]).to eq(true)
  262. expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2)
  263. expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true)
  264. expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(3)
  265. expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false)
  266. taskbar1_last_contact = taskbar1.last_contact.to_s
  267. taskbar2_last_contact = taskbar2.last_contact.to_s
  268. taskbar3_last_contact = taskbar3.last_contact.to_s
  269. taskbar4_last_contact = taskbar4.last_contact.to_s
  270. travel 2.minutes
  271. UserInfo.current_user_id = 2
  272. taskbar2.state = { article: { body: 'some body' }, ticket: {} }
  273. taskbar2.notify = true
  274. taskbar2.save!
  275. taskbar1.reload
  276. expect(taskbar1.preferences[:tasks].count).to eq(3)
  277. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  278. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(true)
  279. expect(taskbar1.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar1_last_contact)
  280. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  281. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true)
  282. expect(taskbar1.preferences[:tasks][1][:last_contact].to_s).to eq(taskbar2_last_contact)
  283. expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(3)
  284. expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false)
  285. expect(taskbar1.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact)
  286. taskbar2.reload
  287. expect(taskbar2.preferences[:tasks].count).to eq(3)
  288. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  289. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(true)
  290. expect(taskbar2.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar1_last_contact)
  291. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  292. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true)
  293. expect(taskbar2.preferences[:tasks][1][:last_contact].to_s).to eq(taskbar2_last_contact)
  294. expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(3)
  295. expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false)
  296. expect(taskbar2.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact)
  297. taskbar3.reload
  298. expect(taskbar3.preferences[:tasks].count).to eq(1)
  299. expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2)
  300. expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false)
  301. expect(taskbar3.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar3_last_contact)
  302. taskbar4.reload
  303. expect(taskbar4.preferences[:tasks].count).to eq(3)
  304. expect(taskbar4.preferences[:tasks][0][:user_id]).to eq(1)
  305. expect(taskbar4.preferences[:tasks][0][:changed]).to eq(true)
  306. expect(taskbar4.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar1_last_contact)
  307. expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2)
  308. expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true)
  309. expect(taskbar4.preferences[:tasks][1][:last_contact].to_s).to eq(taskbar2_last_contact)
  310. expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(3)
  311. expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false)
  312. expect(taskbar4.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact)
  313. UserInfo.current_user_id = 2
  314. taskbar2.state = { article: { body: 'some body 222' }, ticket: {} }
  315. taskbar2.notify = true
  316. taskbar2.save!
  317. taskbar1.reload
  318. expect(taskbar1.preferences[:tasks].count).to eq(3)
  319. expect(taskbar1.preferences[:tasks][0][:user_id]).to eq(1)
  320. expect(taskbar1.preferences[:tasks][0][:changed]).to eq(true)
  321. expect(taskbar1.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar1_last_contact)
  322. expect(taskbar1.preferences[:tasks][1][:user_id]).to eq(2)
  323. expect(taskbar1.preferences[:tasks][1][:changed]).to eq(true)
  324. expect(taskbar1.preferences[:tasks][1][:last_contact].to_s).not_to eq(taskbar2_last_contact)
  325. expect(taskbar1.preferences[:tasks][2][:user_id]).to eq(3)
  326. expect(taskbar1.preferences[:tasks][2][:changed]).to eq(false)
  327. expect(taskbar1.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact)
  328. taskbar2.reload
  329. expect(taskbar2.preferences[:tasks].count).to eq(3)
  330. expect(taskbar2.preferences[:tasks][0][:user_id]).to eq(1)
  331. expect(taskbar2.preferences[:tasks][0][:changed]).to eq(true)
  332. expect(taskbar2.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar1_last_contact)
  333. expect(taskbar2.preferences[:tasks][1][:user_id]).to eq(2)
  334. expect(taskbar2.preferences[:tasks][1][:changed]).to eq(true)
  335. expect(taskbar2.preferences[:tasks][1][:last_contact].to_s).not_to eq(taskbar2_last_contact)
  336. expect(taskbar2.preferences[:tasks][2][:user_id]).to eq(3)
  337. expect(taskbar2.preferences[:tasks][2][:changed]).to eq(false)
  338. expect(taskbar2.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact)
  339. taskbar3.reload
  340. expect(taskbar3.preferences[:tasks].count).to eq(1)
  341. expect(taskbar3.preferences[:tasks][0][:user_id]).to eq(2)
  342. expect(taskbar3.preferences[:tasks][0][:changed]).to eq(false)
  343. expect(taskbar3.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar3_last_contact)
  344. taskbar4.reload
  345. expect(taskbar4.preferences[:tasks].count).to eq(3)
  346. expect(taskbar4.preferences[:tasks][0][:user_id]).to eq(1)
  347. expect(taskbar4.preferences[:tasks][0][:changed]).to eq(true)
  348. expect(taskbar4.preferences[:tasks][0][:last_contact].to_s).to eq(taskbar1_last_contact)
  349. expect(taskbar4.preferences[:tasks][1][:user_id]).to eq(2)
  350. expect(taskbar4.preferences[:tasks][1][:changed]).to eq(true)
  351. expect(taskbar4.preferences[:tasks][1][:last_contact].to_s).not_to eq(taskbar2_last_contact)
  352. expect(taskbar4.preferences[:tasks][2][:user_id]).to eq(3)
  353. expect(taskbar4.preferences[:tasks][2][:changed]).to eq(false)
  354. expect(taskbar4.preferences[:tasks][2][:last_contact].to_s).to eq(taskbar4_last_contact)
  355. travel_back
  356. UserInfo.current_user_id = nil
  357. end
  358. end
  359. end