chat_test.rb 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. # encoding: utf-8
  2. require 'browser_test_helper'
  3. class ChatTest < TestCase
  4. def test_basic
  5. chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
  6. agent = browser_instance
  7. login(
  8. browser: agent,
  9. username: 'master@example.com',
  10. password: 'test',
  11. url: browser_url,
  12. )
  13. tasks_close_all(
  14. browser: agent,
  15. )
  16. # disable chat
  17. click(
  18. browser: agent,
  19. css: 'a[href="#manage"]',
  20. )
  21. click(
  22. browser: agent,
  23. css: '.content.active a[href="#channels/chat"]',
  24. )
  25. switch(
  26. browser: agent,
  27. css: '.content.active .js-chatSetting',
  28. type: 'off',
  29. )
  30. # nav bar shuld be gone
  31. sleep 2
  32. exists_not(
  33. browser: agent,
  34. css: 'a[href="#customer_chat"]',
  35. )
  36. sleep 15
  37. customer = browser_instance
  38. location(
  39. browser: customer,
  40. url: chat_url,
  41. )
  42. sleep 4
  43. exists_not(
  44. browser: customer,
  45. css: '.zammad-chat',
  46. )
  47. match(
  48. browser: customer,
  49. css: '.settings',
  50. value: '{"state":"chat_disabled"}',
  51. )
  52. click(
  53. browser: agent,
  54. css: 'a[href="#manage"]',
  55. )
  56. click(
  57. browser: agent,
  58. css: '.content.active a[href="#channels/chat"]',
  59. )
  60. switch(
  61. browser: agent,
  62. css: '.content.active .js-chatSetting',
  63. type: 'on',
  64. )
  65. sleep 15 # wait for rerendering
  66. switch(
  67. browser: agent,
  68. css: '#navigation .js-chatMenuItem .js-switch',
  69. type: 'off',
  70. )
  71. click(
  72. browser: agent,
  73. css: 'a[href="#customer_chat"]',
  74. wait: 2,
  75. )
  76. match_not(
  77. browser: agent,
  78. css: '.active.content',
  79. value: 'disabled',
  80. )
  81. reload(
  82. browser: customer,
  83. )
  84. sleep 4
  85. exists_not(
  86. browser: customer,
  87. css: '.zammad-chat',
  88. )
  89. match_not(
  90. browser: customer,
  91. css: '.settings',
  92. value: '{"state":"chat_disabled"}',
  93. )
  94. match(
  95. browser: customer,
  96. css: '.settings',
  97. value: '{"event":"chat_status_customer","data":{"state":"offline"}}',
  98. )
  99. click(
  100. browser: agent,
  101. css: 'a[href="#customer_chat"]',
  102. )
  103. switch(
  104. browser: agent,
  105. css: '#navigation .js-chatMenuItem .js-switch',
  106. type: 'on',
  107. )
  108. reload(
  109. browser: customer,
  110. )
  111. watch_for(
  112. browser: customer,
  113. css: '.zammad-chat',
  114. timeout: 5,
  115. )
  116. match_not(
  117. browser: customer,
  118. css: '.settings',
  119. value: '{"state":"chat_disabled"}',
  120. )
  121. match_not(
  122. browser: customer,
  123. css: '.settings',
  124. value: '{"event":"chat_status_customer","data":{"state":"offline"}}',
  125. )
  126. match(
  127. browser: customer,
  128. css: '.settings',
  129. value: '"data":{"state":"online"}',
  130. )
  131. # init chat
  132. click(
  133. browser: customer,
  134. css: '.js-chat-open',
  135. )
  136. exists(
  137. browser: customer,
  138. css: '.zammad-chat-is-shown',
  139. )
  140. watch_for(
  141. browser: customer,
  142. css: '.zammad-chat',
  143. value: '(waiting|warte)',
  144. )
  145. watch_for(
  146. browser: agent,
  147. css: '.js-chatMenuItem .counter',
  148. value: '1',
  149. )
  150. click(
  151. browser: customer,
  152. css: '.js-chat-toggle',
  153. )
  154. watch_for_disappear(
  155. browser: customer,
  156. css: '.zammad-chat',
  157. value: '(waiting|warte)',
  158. )
  159. watch_for_disappear(
  160. browser: agent,
  161. css: '.js-chatMenuItem .counter',
  162. )
  163. end
  164. def test_basic_usecase1
  165. chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
  166. agent = browser_instance
  167. login(
  168. browser: agent,
  169. username: 'master@example.com',
  170. password: 'test',
  171. url: browser_url,
  172. )
  173. tasks_close_all(
  174. browser: agent,
  175. )
  176. click(
  177. browser: agent,
  178. css: 'a[href="#customer_chat"]',
  179. )
  180. agent.find_elements( { css: '.active .chat-window .js-disconnect' } ).each(&:click)
  181. agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
  182. customer = browser_instance
  183. location(
  184. browser: customer,
  185. url: chat_url,
  186. )
  187. watch_for(
  188. browser: customer,
  189. css: '.zammad-chat',
  190. timeout: 5,
  191. )
  192. click(
  193. browser: customer,
  194. css: '.js-chat-open',
  195. )
  196. exists(
  197. browser: customer,
  198. css: '.zammad-chat-is-shown',
  199. )
  200. watch_for(
  201. browser: customer,
  202. css: '.zammad-chat',
  203. value: '(waiting|warte)',
  204. )
  205. click(
  206. browser: agent,
  207. css: '.active .js-acceptChat',
  208. )
  209. sleep 2
  210. exists_not(
  211. browser: agent,
  212. css: '.active .chat-window .chat-status.is-modified',
  213. )
  214. match(
  215. browser: agent,
  216. css: '.active .chat-window .js-body',
  217. value: chat_url,
  218. )
  219. set(
  220. browser: agent,
  221. css: '.active .chat-window .js-customerChatInput',
  222. value: 'my name is me',
  223. )
  224. click(
  225. browser: agent,
  226. css: '.active .chat-window .js-send',
  227. )
  228. watch_for(
  229. browser: customer,
  230. css: '.zammad-chat .zammad-chat-agent-status',
  231. value: 'online',
  232. )
  233. watch_for(
  234. browser: customer,
  235. css: '.zammad-chat',
  236. value: 'my name is me',
  237. )
  238. set(
  239. browser: customer,
  240. css: '.zammad-chat .zammad-chat-input',
  241. value: 'my name is customer',
  242. )
  243. click(
  244. browser: customer,
  245. css: '.zammad-chat .zammad-chat-send',
  246. )
  247. watch_for(
  248. browser: agent,
  249. css: '.active .chat-window',
  250. value: 'my name is customer',
  251. )
  252. exists(
  253. browser: agent,
  254. css: '.active .chat-window .chat-status.is-modified',
  255. )
  256. click(
  257. browser: agent,
  258. css: '.active .chat-window .js-customerChatInput',
  259. )
  260. exists_not(
  261. browser: agent,
  262. css: '.active .chat-window .chat-status.is-modified',
  263. )
  264. click(
  265. browser: customer,
  266. css: '.js-chat-toggle',
  267. )
  268. watch_for(
  269. browser: agent,
  270. css: '.active .chat-window',
  271. value: 'closed the conversation',
  272. )
  273. end
  274. def test_basic_usecase2
  275. chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
  276. agent = browser_instance
  277. login(
  278. browser: agent,
  279. username: 'master@example.com',
  280. password: 'test',
  281. url: browser_url,
  282. )
  283. tasks_close_all(
  284. browser: agent,
  285. )
  286. click(
  287. browser: agent,
  288. css: 'a[href="#customer_chat"]',
  289. )
  290. agent.find_elements( { css: '.active .chat-window .js-disconnect' } ).each(&:click)
  291. agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
  292. customer = browser_instance
  293. location(
  294. browser: customer,
  295. url: chat_url,
  296. )
  297. watch_for(
  298. browser: customer,
  299. css: '.zammad-chat',
  300. timeout: 5,
  301. )
  302. click(
  303. browser: customer,
  304. css: '.js-chat-open',
  305. )
  306. exists(
  307. browser: customer,
  308. css: '.zammad-chat-is-shown',
  309. )
  310. watch_for(
  311. browser: customer,
  312. css: '.zammad-chat',
  313. value: '(waiting|warte)',
  314. )
  315. click(
  316. browser: agent,
  317. css: '.active .js-acceptChat',
  318. )
  319. sleep 2
  320. exists_not(
  321. browser: agent,
  322. css: '.active .chat-window .chat-status.is-modified',
  323. )
  324. # keep focus outside of chat window to check .chat-status.is-modified later
  325. click(
  326. browser: agent,
  327. css: '#global-search',
  328. )
  329. watch_for(
  330. browser: customer,
  331. css: '.zammad-chat .zammad-chat-agent-status',
  332. value: 'online',
  333. )
  334. set(
  335. browser: customer,
  336. css: '.zammad-chat .zammad-chat-input',
  337. value: 'my name is customer',
  338. )
  339. click(
  340. browser: customer,
  341. css: '.zammad-chat .zammad-chat-send',
  342. )
  343. watch_for(
  344. browser: agent,
  345. css: '.active .chat-window',
  346. value: 'my name is customer',
  347. )
  348. exists(
  349. browser: agent,
  350. css: '.active .chat-window .chat-status.is-modified',
  351. )
  352. set(
  353. browser: agent,
  354. css: '.active .chat-window .js-customerChatInput',
  355. value: 'my name is me',
  356. )
  357. exists_not(
  358. browser: agent,
  359. css: '.active .chat-window .chat-status.is-modified',
  360. )
  361. click(
  362. browser: agent,
  363. css: '.active .chat-window .js-send',
  364. )
  365. watch_for(
  366. browser: customer,
  367. css: '.zammad-chat',
  368. value: 'my name is me',
  369. )
  370. click(
  371. browser: agent,
  372. css: '.active .chat-window .js-disconnect',
  373. )
  374. click(
  375. browser: agent,
  376. css: '.active .chat-window .js-close',
  377. )
  378. watch_for(
  379. browser: customer,
  380. css: '.zammad-chat .zammad-chat-agent-status',
  381. value: 'offline',
  382. )
  383. watch_for(
  384. browser: customer,
  385. css: '.zammad-chat',
  386. value: 'Chat closed by',
  387. )
  388. click(
  389. browser: customer,
  390. css: '.zammad-chat .js-chat-toggle',
  391. )
  392. watch_for_disappear(
  393. browser: customer,
  394. css: '.zammad-chat-is-open',
  395. )
  396. agent.find_elements( { css: '.active .chat-window .js-disconnect' } ).each(&:click)
  397. agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
  398. sleep 2
  399. click(
  400. browser: customer,
  401. css: '.js-chat-open',
  402. )
  403. exists(
  404. browser: customer,
  405. css: '.zammad-chat-is-shown',
  406. )
  407. watch_for(
  408. browser: customer,
  409. css: '.zammad-chat',
  410. value: '(waiting|warte)',
  411. )
  412. click(
  413. browser: agent,
  414. css: '.active .js-acceptChat',
  415. )
  416. sleep 2
  417. exists_not(
  418. browser: agent,
  419. css: '.active .chat-window .chat-status.is-modified',
  420. )
  421. exists(
  422. browser: agent,
  423. css: '.active .chat-window .chat-status',
  424. )
  425. end
  426. def test_basic_usecase3
  427. chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
  428. agent = browser_instance
  429. login(
  430. browser: agent,
  431. username: 'master@example.com',
  432. password: 'test',
  433. url: browser_url,
  434. )
  435. tasks_close_all(
  436. browser: agent,
  437. )
  438. click(
  439. browser: agent,
  440. css: 'a[href="#customer_chat"]',
  441. )
  442. agent.find_elements( { css: '.active .chat-window .js-disconnect' } ).each(&:click)
  443. agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
  444. # set chat preferences
  445. click(
  446. browser: agent,
  447. css: '.active .js-settings',
  448. )
  449. set(
  450. browser: agent,
  451. css: '.modal [name="chat::phrase::1"]',
  452. value: 'Hi Stranger!;My Greeting',
  453. )
  454. click(
  455. browser: agent,
  456. css: '.modal .js-submit',
  457. )
  458. customer = browser_instance
  459. location(
  460. browser: customer,
  461. url: chat_url,
  462. )
  463. watch_for(
  464. browser: customer,
  465. css: '.zammad-chat',
  466. timeout: 5,
  467. )
  468. click(
  469. browser: customer,
  470. css: '.js-chat-open',
  471. )
  472. exists(
  473. browser: customer,
  474. css: '.zammad-chat-is-shown',
  475. )
  476. watch_for(
  477. browser: agent,
  478. css: '.active .js-badgeWaitingCustomers',
  479. value: '1',
  480. )
  481. click(
  482. browser: agent,
  483. css: '.active .js-acceptChat',
  484. )
  485. watch_for(
  486. browser: customer,
  487. css: '.zammad-chat',
  488. value: 'Hi Stranger|My Greeting',
  489. )
  490. watch_for(
  491. browser: customer,
  492. css: '.zammad-chat .zammad-chat-agent-status',
  493. value: 'online',
  494. )
  495. match(
  496. browser: agent,
  497. css: '.active .chat-window .js-body',
  498. value: chat_url,
  499. )
  500. set(
  501. browser: agent,
  502. css: '.active .chat-window .js-customerChatInput',
  503. value: 'my name is me',
  504. )
  505. click(
  506. browser: agent,
  507. css: '.active .chat-window .js-send',
  508. )
  509. watch_for(
  510. browser: customer,
  511. css: '.zammad-chat',
  512. value: 'my name is me',
  513. )
  514. set(
  515. browser: customer,
  516. css: '.zammad-chat .zammad-chat-input',
  517. value: 'my name is customer',
  518. )
  519. click(
  520. browser: customer,
  521. css: '.zammad-chat .zammad-chat-send',
  522. )
  523. watch_for(
  524. browser: agent,
  525. css: '.active .chat-window',
  526. value: 'my name is customer',
  527. )
  528. click(
  529. browser: agent,
  530. css: '.active .chat-window .js-customerChatInput',
  531. )
  532. reload(
  533. browser: customer,
  534. )
  535. exists(
  536. browser: customer,
  537. css: '.zammad-chat',
  538. )
  539. watch_for(
  540. browser: customer,
  541. css: '.zammad-chat',
  542. value: 'Hi Stranger|My Greeting',
  543. )
  544. watch_for(
  545. browser: customer,
  546. css: '.zammad-chat',
  547. value: 'my name is me',
  548. )
  549. watch_for(
  550. browser: customer,
  551. css: '.zammad-chat',
  552. value: 'my name is customer',
  553. )
  554. location(
  555. browser: customer,
  556. url: "#{chat_url}#new_hash",
  557. )
  558. sleep 2
  559. match(
  560. browser: agent,
  561. css: '.active .chat-window .js-body',
  562. value: "#{chat_url}#new_hash",
  563. )
  564. click(
  565. browser: customer,
  566. css: '.js-chat-toggle',
  567. )
  568. watch_for(
  569. browser: agent,
  570. css: '.active .chat-window',
  571. value: 'closed the conversation',
  572. )
  573. end
  574. def test_timeouts
  575. chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
  576. agent = browser_instance
  577. login(
  578. browser: agent,
  579. username: 'master@example.com',
  580. password: 'test',
  581. url: browser_url,
  582. )
  583. tasks_close_all(
  584. browser: agent,
  585. )
  586. click(
  587. browser: agent,
  588. css: 'a[href="#customer_chat"]',
  589. )
  590. agent.find_elements( { css: '.active .chat-window .js-disconnect' } ).each(&:click)
  591. agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
  592. exists(
  593. browser: agent,
  594. css: '#navigation .js-chatMenuItem .js-switch input[checked]'
  595. )
  596. # no customer action, hide widget
  597. customer = browser_instance
  598. location(
  599. browser: customer,
  600. url: chat_url,
  601. )
  602. watch_for(
  603. browser: customer,
  604. css: '.zammad-chat',
  605. timeout: 5,
  606. )
  607. watch_for_disappear(
  608. browser: customer,
  609. css: '.zammad-chat',
  610. timeout: 95,
  611. )
  612. # no agent action, show sorry screen
  613. reload(
  614. browser: customer,
  615. )
  616. exists(
  617. browser: customer,
  618. css: '.zammad-chat',
  619. )
  620. click(
  621. browser: customer,
  622. css: '.js-chat-open',
  623. )
  624. watch_for(
  625. browser: customer,
  626. css: '.zammad-chat',
  627. value: '(waiting|warte)',
  628. timeout: 35,
  629. )
  630. watch_for(
  631. browser: customer,
  632. css: '.zammad-chat',
  633. value: '(takes longer|dauert länger)',
  634. timeout: 120,
  635. )
  636. # check if agent is offline, idle timeout, chat not answered
  637. exists_not(
  638. browser: agent,
  639. css: '#navigation .js-chatMenuItem .js-switch input[checked]'
  640. )
  641. switch(
  642. browser: agent,
  643. css: '#navigation .js-chatMenuItem .js-switch',
  644. type: 'on',
  645. )
  646. # no customer action, show sorry screen
  647. reload(
  648. browser: customer,
  649. )
  650. exists(
  651. browser: customer,
  652. css: '.zammad-chat',
  653. )
  654. click(
  655. browser: customer,
  656. css: '.js-chat-open',
  657. )
  658. watch_for(
  659. browser: agent,
  660. css: '.js-chatMenuItem .counter',
  661. value: '1',
  662. )
  663. click(
  664. browser: agent,
  665. css: '.active .js-acceptChat',
  666. )
  667. sleep 2
  668. set(
  669. browser: agent,
  670. css: '.active .chat-window .js-customerChatInput',
  671. value: 'agent is asking',
  672. )
  673. click(
  674. browser: agent,
  675. css: '.active .chat-window .js-send',
  676. )
  677. watch_for(
  678. browser: customer,
  679. css: '.zammad-chat',
  680. value: 'agent is asking',
  681. )
  682. watch_for(
  683. browser: customer,
  684. css: '.zammad-chat',
  685. value: '(Since you didn\'t respond|Da Sie in den letzten)',
  686. timeout: 150,
  687. )
  688. agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
  689. sleep 2
  690. click(
  691. browser: customer,
  692. css: '.js-restart',
  693. )
  694. sleep 5
  695. click(
  696. browser: customer,
  697. css: '.js-chat-open',
  698. )
  699. exists(
  700. browser: customer,
  701. css: '.zammad-chat-is-shown',
  702. )
  703. watch_for(
  704. browser: customer,
  705. css: '.zammad-chat',
  706. value: '(waiting|warte)',
  707. )
  708. click(
  709. browser: agent,
  710. css: '.active .js-acceptChat',
  711. )
  712. sleep 2
  713. exists(
  714. browser: agent,
  715. css: '.active .chat-window .chat-status',
  716. )
  717. set(
  718. browser: agent,
  719. css: '.active .chat-window .js-customerChatInput',
  720. value: 'my name is me',
  721. )
  722. click(
  723. browser: agent,
  724. css: '.active .chat-window .js-send',
  725. )
  726. watch_for(
  727. browser: customer,
  728. css: '.zammad-chat .zammad-chat-agent-status',
  729. value: 'online',
  730. )
  731. watch_for(
  732. browser: customer,
  733. css: '.zammad-chat',
  734. value: 'my name is me',
  735. )
  736. end
  737. end