form_test.rb 9.4 KB

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