agent_ticket_online_notification_test.rb 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. # encoding: utf-8
  2. require 'browser_test_helper'
  3. class AgentTicketOnlineNotificationTest < TestCase
  4. def test_online_notifications
  5. @browser = browser_instance
  6. login(
  7. username: 'master@example.com',
  8. password: 'test',
  9. url: browser_url,
  10. )
  11. tasks_close_all()
  12. # create new ticket
  13. ticket1 = 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. ticket2 = 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. ticket3 = 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. watch_for(
  99. browser: browser2,
  100. css: '.js-notificationsCounter',
  101. value: '2',
  102. )
  103. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  104. count = items.count
  105. assert_equal(2, count)
  106. items[1].click
  107. click(
  108. browser: browser2,
  109. css: '.js-toggleNotifications',
  110. )
  111. watch_for(
  112. browser: browser2,
  113. css: '.js-notificationsCounter',
  114. value: '1',
  115. )
  116. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  117. assert_equal(2, items.count)
  118. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  119. assert_equal(1, items.count)
  120. ticket4 = ticket_create(
  121. data: {
  122. customer: 'nico',
  123. group: 'Users',
  124. title: 'online notification #4',
  125. body: 'online notification #4',
  126. },
  127. )
  128. watch_for(
  129. browser: browser2,
  130. css: '.js-notificationsCounter',
  131. value: '2',
  132. )
  133. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  134. assert_equal(3, items.count)
  135. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  136. assert_equal(1, items.count)
  137. click(
  138. browser: browser2,
  139. css: '.js-mark',
  140. )
  141. sleep 3
  142. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  143. assert_equal(3, items.count)
  144. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  145. assert_equal(3, items.count)
  146. match_not(
  147. browser: browser2,
  148. css: '.js-notificationsCounter',
  149. value: '\d',
  150. no_quote: true,
  151. )
  152. ticket5 = ticket_create(
  153. data: {
  154. customer: 'nico',
  155. group: 'Users',
  156. title: 'online notification #5',
  157. body: 'online notification #5',
  158. },
  159. )
  160. watch_for(
  161. browser: browser2,
  162. css: '.js-notificationsCounter',
  163. value: '1',
  164. )
  165. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  166. assert_equal(4, items.count)
  167. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  168. assert_equal(3, items.count)
  169. # Note: title update will generate extra notification - so we will have 5
  170. ticket_update(
  171. data: {
  172. title: 'online notification #5/5',
  173. state: 'closed',
  174. },
  175. )
  176. watch_for(
  177. browser: browser2,
  178. css: '.js-notificationsContainer .js-item',
  179. value: 'online notification #5/5',
  180. timeout: 20,
  181. )
  182. watch_for(
  183. browser: browser2,
  184. css: '.js-notificationsContainer .js-item.is-inactive',
  185. value: 'online notification #5/5',
  186. timeout: 20,
  187. )
  188. match_not(
  189. browser: browser2,
  190. css: '.js-notificationsCounter',
  191. value: '\d',
  192. no_quote: true,
  193. )
  194. items = browser2.find_elements(css: '.js-notificationsContainer .js-item')
  195. assert_equal(6, items.count)
  196. items = browser2.find_elements(css: '.js-notificationsContainer .js-item.is-inactive')
  197. assert_equal(6, items.count)
  198. end
  199. def test_online_notifications_render
  200. @browser = browser_instance
  201. login(
  202. username: 'master@example.com',
  203. password: 'test',
  204. url: browser_url,
  205. )
  206. tasks_close_all()
  207. browser2 = browser_instance
  208. login(
  209. browser: browser2,
  210. username: 'agent1@example.com',
  211. password: 'test',
  212. url: browser_url,
  213. )
  214. tasks_close_all(browser: browser2)
  215. click(
  216. browser: browser2,
  217. css: '.js-toggleNotifications',
  218. )
  219. online_notitifcation_close_all(browser: browser2)
  220. ticket1 = ticket_create(
  221. data: {
  222. customer: 'nico',
  223. group: 'Users',
  224. title: 'online notification render #1',
  225. body: 'online notification render #1',
  226. },
  227. )
  228. ticket2 = ticket_create(
  229. data: {
  230. customer: 'nico',
  231. group: 'Users',
  232. title: 'online notification render #2',
  233. body: 'online notification render #2',
  234. },
  235. )
  236. watch_for(
  237. browser: browser2,
  238. css: '.js-notificationsCounter',
  239. value: '2',
  240. )
  241. execute(
  242. browser: browser2,
  243. js: '$(".js-notificationsContainer .js-items .js-item:nth-child(1) .activity-text").text("render test 2")',
  244. )
  245. execute(
  246. browser: browser2,
  247. js: '$(".js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text").text("render test 1")',
  248. )
  249. match(
  250. browser: browser2,
  251. css: '.js-notificationsContainer .js-items .js-item:nth-child(1) .activity-text',
  252. value: 'render test 2',
  253. )
  254. match(
  255. browser: browser2,
  256. css: '.js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text',
  257. value: 'render test 1',
  258. )
  259. ticket3 = ticket_create(
  260. data: {
  261. customer: 'nico',
  262. group: 'Users',
  263. title: 'online notification render #3',
  264. body: 'online notification render #3',
  265. },
  266. )
  267. watch_for(
  268. browser: browser2,
  269. css: '.js-notificationsCounter',
  270. value: '3',
  271. )
  272. match(
  273. browser: browser2,
  274. css: '.js-notificationsContainer .js-items .js-item:nth-child(1) .activity-text',
  275. value: 'online notification render #3',
  276. )
  277. match(
  278. browser: browser2,
  279. css: '.js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text',
  280. value: 'render test 2',
  281. )
  282. match(
  283. browser: browser2,
  284. css: '.js-notificationsContainer .js-items .js-item:nth-child(3) .activity-text',
  285. value: 'render test 1',
  286. )
  287. ticket_update(
  288. data: {
  289. state: 'closed',
  290. },
  291. )
  292. watch_for(
  293. browser: browser2,
  294. css: '.js-notificationsCounter',
  295. value: '2',
  296. )
  297. match(
  298. browser: browser2,
  299. css: '.js-notificationsContainer .js-items .is-inactive.js-item:nth-child(1) .activity-text',
  300. value: 'online notification render #3',
  301. )
  302. match(
  303. browser: browser2,
  304. css: '.js-notificationsContainer .js-items .is-inactive.js-item:nth-child(2) .activity-text',
  305. value: 'online notification render #3',
  306. )
  307. match(
  308. browser: browser2,
  309. css: '.js-notificationsContainer .js-items .js-item:nth-child(3) .activity-text',
  310. value: 'render test 2',
  311. )
  312. match(
  313. browser: browser2,
  314. css: '.js-notificationsContainer .js-items .js-item:nth-child(4) .activity-text',
  315. value: 'render test 1',
  316. )
  317. execute(
  318. browser: browser2,
  319. js: '$(".js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text").text("render test 3")',
  320. )
  321. close_online_notitifcation(
  322. browser: browser2,
  323. data: {
  324. position: 3,
  325. },
  326. )
  327. match(
  328. browser: browser2,
  329. css: '.js-notificationsContainer .js-items .is-inactive.js-item:nth-child(1) .activity-text',
  330. value: 'online notification render #3',
  331. )
  332. match(
  333. browser: browser2,
  334. css: '.js-notificationsContainer .js-items .js-item:nth-child(2) .activity-text',
  335. value: 'render test 3',
  336. )
  337. match(
  338. browser: browser2,
  339. css: '.js-notificationsContainer .js-items .js-item:nth-child(3) .activity-text',
  340. value: 'render test 1',
  341. )
  342. end
  343. end