form_test.rb 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. require 'browser_test_helper'
  2. class FormTest < TestCase
  3. def test_basic
  4. agent = browser_instance
  5. login(
  6. browser: agent,
  7. username: 'master@example.com',
  8. password: 'test',
  9. url: browser_url,
  10. )
  11. tasks_close_all(
  12. browser: agent,
  13. )
  14. # disable form
  15. click(
  16. browser: agent,
  17. css: 'a[href="#manage"]',
  18. )
  19. click(
  20. browser: agent,
  21. css: '.content.active a[href="#channels/form"]',
  22. )
  23. switch(
  24. browser: agent,
  25. css: '.content.active .js-formSetting',
  26. type: 'off',
  27. )
  28. # admin preview test
  29. sleep 1
  30. click(
  31. browser: agent,
  32. css: '.content.active .js-formBtn',
  33. )
  34. sleep 10
  35. set(
  36. browser: agent,
  37. css: 'body div.zammad-form-modal [name="name"]',
  38. value: 'some sender',
  39. )
  40. set(
  41. browser: agent,
  42. css: 'body div.zammad-form-modal [name="body"]',
  43. value: '',
  44. )
  45. click(
  46. browser: agent,
  47. css: 'body div.zammad-form-modal button[type="submit"]',
  48. )
  49. watch_for(
  50. browser: agent,
  51. css: 'body div.zammad-form-modal .has-error [name="body"]',
  52. )
  53. watch_for_disappear(
  54. browser: agent,
  55. css: 'body div.zammad-form-modal button[type="submit"][disabled]',
  56. )
  57. set(
  58. browser: agent,
  59. css: 'body div.zammad-form-modal [name="body"]',
  60. value: 'new body',
  61. )
  62. set(
  63. browser: agent,
  64. css: 'body div.zammad-form-modal [name="email"]',
  65. value: 'somebody@notexistinginanydomainspacealsonothere.nowhere',
  66. )
  67. click(
  68. browser: agent,
  69. css: 'body div.zammad-form-modal button[type="submit"]',
  70. )
  71. watch_for(
  72. browser: agent,
  73. css: 'body div.zammad-form-modal .has-error [name="email"]',
  74. )
  75. watch_for_disappear(
  76. browser: agent,
  77. css: 'body div.zammad-form-modal button[type="submit"][disabled]',
  78. )
  79. set(
  80. browser: agent,
  81. css: 'body div.zammad-form-modal [name="email"]',
  82. value: 'discard@znuny.com',
  83. )
  84. click(
  85. browser: agent,
  86. css: 'body div.zammad-form-modal button[type="submit"]',
  87. )
  88. watch_for(
  89. browser: agent,
  90. css: 'body div.zammad-form-modal',
  91. value: 'Thank you for your inquiry',
  92. )
  93. # click on backgroud (not on thank you dialog)
  94. element = agent.find_elements({ css: 'body div.zammad-form-modal' })[0]
  95. agent.action.move_to(element, 200, 200).perform
  96. agent.action.click.perform
  97. customer = browser_instance
  98. location(
  99. browser: customer,
  100. url: "#{browser_url}/assets/form/form.html",
  101. )
  102. watch_for(
  103. browser: customer,
  104. css: '.js-logDisplay',
  105. value: 'Faild to load form config, feature is disabled',
  106. )
  107. switch(
  108. browser: agent,
  109. css: '.content.active .js-formSetting',
  110. type: 'on',
  111. )
  112. reload(
  113. browser: customer,
  114. )
  115. sleep 4
  116. match_not(
  117. browser: customer,
  118. css: '.js-logDisplay',
  119. value: 'Faild to load form config, feature is disabled',
  120. )
  121. exists_not(
  122. browser: customer,
  123. css: 'body div.zammad-form-modal',
  124. )
  125. # modal dialog
  126. click(
  127. browser: customer,
  128. css: '#feedback-form-modal',
  129. )
  130. watch_for(
  131. browser: customer,
  132. css: 'body div.zammad-form-modal',
  133. )
  134. # fill form valid data - but too fast
  135. set(
  136. browser: customer,
  137. css: 'body div.zammad-form-modal [name="name"]',
  138. value: 'some name',
  139. )
  140. set(
  141. browser: customer,
  142. css: 'body div.zammad-form-modal [name="email"]',
  143. value: 'discard@znuny.com',
  144. )
  145. set(
  146. browser: customer,
  147. css: 'body div.zammad-form-modal [name="body"]',
  148. value: "some text\nnew line",
  149. )
  150. click(
  151. browser: customer,
  152. css: 'body div.zammad-form-modal button[type="submit"]',
  153. )
  154. # check warning
  155. alert = customer.switch_to.alert
  156. alert.dismiss()
  157. sleep 10
  158. # fill form invalid data - within correct time
  159. set(
  160. browser: customer,
  161. css: 'body div.zammad-form-modal [name="name"]',
  162. value: 'some name',
  163. )
  164. set(
  165. browser: customer,
  166. css: 'body div.zammad-form-modal [name="email"]',
  167. value: 'invalid_email',
  168. )
  169. set(
  170. browser: customer,
  171. css: 'body div.zammad-form-modal [name="body"]',
  172. value: "some text\nnew line",
  173. )
  174. click(
  175. browser: customer,
  176. css: 'body div.zammad-form-modal button[type="submit"]',
  177. )
  178. sleep 10
  179. exists(
  180. browser: customer,
  181. css: 'body div.zammad-form-modal',
  182. )
  183. # fill form valid data
  184. set(
  185. browser: customer,
  186. css: 'body div.zammad-form-modal [name="email"]',
  187. value: 'discard@znuny.com',
  188. )
  189. click(
  190. browser: customer,
  191. css: 'body div.zammad-form-modal button[type="submit"]',
  192. )
  193. watch_for(
  194. browser: customer,
  195. css: 'body div.zammad-form-modal',
  196. value: 'Thank you for your inquiry',
  197. )
  198. # click on backgroud (not on thank you dialog)
  199. element = customer.find_elements({ css: 'body div.zammad-form-modal' })[0]
  200. customer.action.move_to(element, 200, 200).perform
  201. customer.action.click.perform
  202. sleep 1
  203. exists_not(
  204. browser: customer,
  205. css: 'body div.zammad-form-modal',
  206. )
  207. # fill form invalid data - within correct time
  208. click(
  209. browser: customer,
  210. css: '#feedback-form-modal',
  211. )
  212. sleep 10
  213. set(
  214. browser: customer,
  215. css: 'body div.zammad-form-modal [name="name"]',
  216. value: '',
  217. )
  218. set(
  219. browser: customer,
  220. css: 'body div.zammad-form-modal [name="email"]',
  221. value: 'discard@znuny.com',
  222. )
  223. set(
  224. browser: customer,
  225. css: 'body div.zammad-form-modal [name="body"]',
  226. value: "some text\nnew line",
  227. )
  228. click(
  229. browser: customer,
  230. css: 'body div.zammad-form-modal button[type="submit"]',
  231. )
  232. watch_for(
  233. browser: customer,
  234. css: 'body div.zammad-form-modal .has-error [name="name"]',
  235. )
  236. watch_for_disappear(
  237. browser: customer,
  238. css: 'body div.zammad-form-modal button[type="submit"][disabled]',
  239. )
  240. set(
  241. browser: customer,
  242. css: 'body div.zammad-form-modal [name="name"]',
  243. value: 'some sender',
  244. )
  245. set(
  246. browser: customer,
  247. css: 'body div.zammad-form-modal [name="body"]',
  248. value: '',
  249. )
  250. click(
  251. browser: customer,
  252. css: 'body div.zammad-form-modal button[type="submit"]',
  253. )
  254. watch_for(
  255. browser: customer,
  256. css: 'body div.zammad-form-modal .has-error [name="body"]',
  257. )
  258. watch_for_disappear(
  259. browser: customer,
  260. css: 'body div.zammad-form-modal button[type="submit"][disabled]',
  261. )
  262. set(
  263. browser: customer,
  264. css: 'body div.zammad-form-modal [name="body"]',
  265. value: 'new body',
  266. )
  267. set(
  268. browser: customer,
  269. css: 'body div.zammad-form-modal [name="email"]',
  270. value: 'somebody@notexistinginanydomainspacealsonothere.nowhere',
  271. )
  272. click(
  273. browser: customer,
  274. css: 'body div.zammad-form-modal button[type="submit"]',
  275. )
  276. watch_for(
  277. browser: customer,
  278. css: 'body div.zammad-form-modal .has-error [name="email"]',
  279. )
  280. watch_for_disappear(
  281. browser: customer,
  282. css: 'body div.zammad-form-modal button[type="submit"][disabled]',
  283. )
  284. set(
  285. browser: customer,
  286. css: 'body div.zammad-form-modal [name="email"]',
  287. value: 'discard@znuny.com',
  288. )
  289. click(
  290. browser: customer,
  291. css: 'body div.zammad-form-modal button[type="submit"]',
  292. )
  293. watch_for(
  294. browser: customer,
  295. css: 'body div.zammad-form-modal',
  296. value: 'Thank you for your inquiry',
  297. )
  298. # click on backgroud (not on thank you dialog)
  299. element = customer.find_elements({ css: 'body div.zammad-form-modal' })[0]
  300. customer.action.move_to(element, 200, 200).perform
  301. customer.action.click.perform
  302. sleep 1
  303. exists_not(
  304. browser: customer,
  305. css: 'body div.zammad-form-modal',
  306. )
  307. # inline form
  308. set(
  309. browser: customer,
  310. css: '.zammad-form [name="name"]',
  311. value: 'Some Name',
  312. )
  313. set(
  314. browser: customer,
  315. css: '.zammad-form [name="email"]',
  316. value: 'discard@znuny.com',
  317. )
  318. set(
  319. browser: customer,
  320. css: '.zammad-form [name="body"]',
  321. value: 'some text',
  322. )
  323. click(
  324. browser: customer,
  325. css: '.zammad-form button[type="submit"]',
  326. )
  327. watch_for(
  328. browser: customer,
  329. css: '.zammad-form',
  330. value: 'Thank you for your inquiry',
  331. )
  332. end
  333. end