agent_ticket_online_notification_test.rb 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'browser_test_helper'
  3. class AgentTicketOnlineNotificationTest < TestCase
  4. def test_online_notifications
  5. @browser = browser_instance
  6. login(
  7. username: 'admin@example.com',
  8. password: 'test',
  9. url: browser_url,
  10. )
  11. tasks_close_all
  12. # create new ticket
  13. ticket_create(
  14. data: {
  15. customer: 'nico',
  16. group: 'Users',
  17. title: 'online notification #1',
  18. body: 'online notification #1',
  19. },
  20. )
  21. browser2 = browser_instance
  22. login(
  23. browser: browser2,
  24. username: 'agent1@example.com',
  25. password: 'test',
  26. url: browser_url,
  27. )
  28. tasks_close_all(browser: browser2)
  29. click(
  30. browser: browser2,
  31. css: '.js-toggleNotifications',
  32. )
  33. click(
  34. browser: browser2,
  35. css: '.js-mark',
  36. )
  37. sleep 2
  38. # remove all notificatons
  39. online_notitifcation_close_all(
  40. browser: browser2,
  41. )
  42. exists_not(
  43. browser: browser2,
  44. css: '.js-noNotifications.hide',
  45. )
  46. match(
  47. browser: browser2,
  48. css: '.js-noNotifications',
  49. value: 'No unread Notifications',
  50. )
  51. exists(
  52. browser: browser2,
  53. css: '.js-mark.hide',
  54. )
  55. match_not(
  56. browser: browser2,
  57. css: '.js-notificationsCounter',
  58. value: '\d',
  59. no_quote: true,
  60. )
  61. ticket_create(
  62. data: {
  63. customer: 'nico',
  64. group: 'Users',
  65. title: 'online notification #2',
  66. body: 'online notification #2',
  67. },
  68. )
  69. watch_for(
  70. browser: browser2,
  71. css: '.js-notificationsContainer .js-item',
  72. value: 'online notification #2',
  73. timeout: 10,
  74. )
  75. match(
  76. browser: browser2,
  77. css: '.js-notificationsCounter',
  78. value: '1',
  79. )
  80. exists_not(
  81. browser: browser2,
  82. css: '.js-mark.hide',
  83. )
  84. ticket_create(
  85. data: {
  86. customer: 'nico',
  87. group: 'Users',
  88. title: 'online notification #3',
  89. body: 'online notification #3',
  90. },
  91. )
  92. watch_for(
  93. browser: browser2,
  94. css: '.js-notificationsContainer .js-item',
  95. value: 'online notification #3',
  96. timeout: 6,
  97. )
  98. # flanky
  99. watch_for(
  100. browser: browser2,
  101. css: '.js-notificationsCounter',
  102. value: '2',
  103. )
  104. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  105. count = items.count
  106. assert_equal(2, count)
  107. items[1].click
  108. click(
  109. browser: browser2,
  110. css: '.js-toggleNotifications',
  111. )
  112. watch_for(
  113. browser: browser2,
  114. css: '.js-notificationsCounter',
  115. value: '1',
  116. )
  117. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  118. assert_equal(2, items.count)
  119. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  120. assert_equal(1, items.count)
  121. ticket_create(
  122. data: {
  123. customer: 'nico',
  124. group: 'Users',
  125. title: 'online notification #4',
  126. body: 'online notification #4',
  127. },
  128. )
  129. watch_for(
  130. browser: browser2,
  131. css: '.js-notificationsCounter',
  132. value: '2',
  133. )
  134. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  135. assert_equal(3, items.count)
  136. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  137. assert_equal(1, items.count)
  138. click(
  139. browser: browser2,
  140. css: '.js-mark',
  141. )
  142. sleep 3
  143. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  144. assert_equal(3, items.count)
  145. # flanky
  146. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  147. assert_equal(3, items.count)
  148. match_not(
  149. browser: browser2,
  150. css: '.js-notificationsCounter',
  151. value: '\d',
  152. no_quote: true,
  153. )
  154. ticket_create(
  155. data: {
  156. customer: 'nico',
  157. group: 'Users',
  158. title: 'online notification #5',
  159. body: 'online notification #5',
  160. },
  161. )
  162. watch_for(
  163. browser: browser2,
  164. css: '.js-notificationsCounter',
  165. value: '1',
  166. )
  167. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  168. assert_equal(4, items.count)
  169. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  170. assert_equal(3, items.count)
  171. # NOTE: title update will generate extra notification - so we will have 5
  172. ticket_update(
  173. data: {
  174. title: 'online notification #5/5',
  175. state: 'closed',
  176. },
  177. )
  178. watch_for(
  179. browser: browser2,
  180. css: '.js-notificationsContainer .js-item',
  181. value: 'online notification #5/5',
  182. timeout: 20,
  183. )
  184. watch_for(
  185. browser: browser2,
  186. css: '.js-notificationsContainer .js-item.is-inactive',
  187. value: 'online notification #5/5',
  188. timeout: 20,
  189. )
  190. match_not(
  191. browser: browser2,
  192. css: '.js-notificationsCounter',
  193. value: '\d',
  194. no_quote: true,
  195. )
  196. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  197. assert_equal(6, items.count)
  198. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  199. assert_equal(6, items.count)
  200. end
  201. def test_online_notifications_render
  202. @browser = browser_instance
  203. login(
  204. username: 'admin@example.com',
  205. password: 'test',
  206. url: browser_url,
  207. )
  208. tasks_close_all
  209. browser2 = browser_instance
  210. login(
  211. browser: browser2,
  212. username: 'agent1@example.com',
  213. password: 'test',
  214. url: browser_url,
  215. )
  216. tasks_close_all(browser: browser2)
  217. click(
  218. browser: browser2,
  219. css: '.js-toggleNotifications',
  220. )
  221. online_notitifcation_close_all(browser: browser2)
  222. ticket_create(
  223. data: {
  224. customer: 'nico',
  225. group: 'Users',
  226. title: 'online notification render #1',
  227. body: 'online notification render #1',
  228. },
  229. )
  230. ticket_create(
  231. data: {
  232. customer: 'nico',
  233. group: 'Users',
  234. title: 'online notification render #2',
  235. body: 'online notification render #2',
  236. },
  237. )
  238. watch_for(
  239. browser: browser2,
  240. css: '.js-notificationsCounter',
  241. value: '2',
  242. )
  243. execute(
  244. browser: browser2,
  245. js: '$(".js-notificationsContainer .js-items .js-item:nth-child(1) .activity-text").text("render test 2")',
  246. )
  247. execute(
  248. browser: browser2,
  249. js: '$(".js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text").text("render test 1")',
  250. )
  251. match(
  252. browser: browser2,
  253. css: '.js-notificationsContainer .js-items .js-item:nth-child(1) .activity-text',
  254. value: 'render test 2',
  255. )
  256. match(
  257. browser: browser2,
  258. css: '.js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text',
  259. value: 'render test 1',
  260. )
  261. ticket_create(
  262. data: {
  263. customer: 'nico',
  264. group: 'Users',
  265. title: 'online notification render #3',
  266. body: 'online notification render #3',
  267. },
  268. )
  269. watch_for(
  270. browser: browser2,
  271. css: '.js-notificationsCounter',
  272. value: '3',
  273. )
  274. match(
  275. browser: browser2,
  276. css: '.js-notificationsContainer .js-items .js-item:nth-child(1) .activity-text',
  277. value: 'online notification render #3',
  278. )
  279. match(
  280. browser: browser2,
  281. css: '.js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text',
  282. value: 'render test 2',
  283. )
  284. match(
  285. browser: browser2,
  286. css: '.js-notificationsContainer .js-items .js-item:nth-child(3) .activity-text',
  287. value: 'render test 1',
  288. )
  289. ticket_update(
  290. data: {
  291. state: 'closed',
  292. },
  293. )
  294. watch_for(
  295. browser: browser2,
  296. css: '.js-notificationsCounter',
  297. value: '2',
  298. )
  299. match(
  300. browser: browser2,
  301. css: '.js-notificationsContainer .js-items .is-inactive.js-item:nth-child(1) .activity-text',
  302. value: 'online notification render #3',
  303. )
  304. match(
  305. browser: browser2,
  306. css: '.js-notificationsContainer .js-items .is-inactive.js-item:nth-child(2) .activity-text',
  307. value: 'online notification render #3',
  308. )
  309. match(
  310. browser: browser2,
  311. css: '.js-notificationsContainer .js-items .js-item:nth-child(3) .activity-text',
  312. value: 'render test 2',
  313. )
  314. match(
  315. browser: browser2,
  316. css: '.js-notificationsContainer .js-items .js-item:nth-child(4) .activity-text',
  317. value: 'render test 1',
  318. )
  319. execute(
  320. browser: browser2,
  321. js: '$(".js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text").text("render test 3")',
  322. )
  323. close_online_notitifcation(
  324. browser: browser2,
  325. data: {
  326. position: 3,
  327. },
  328. )
  329. match(
  330. browser: browser2,
  331. css: '.js-notificationsContainer .js-items .is-inactive.js-item:nth-child(1) .activity-text',
  332. value: 'online notification render #3',
  333. )
  334. match(
  335. browser: browser2,
  336. css: '.js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text',
  337. value: 'render test 3',
  338. )
  339. match(
  340. browser: browser2,
  341. css: '.js-notificationsContainer .js-items .js-item:nth-child(3) .activity-text',
  342. value: 'render test 1',
  343. )
  344. end
  345. end