twitter_browser_test.rb 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. # encoding: utf-8
  2. require 'browser_test_helper'
  3. class TwitterBrowserTest < TestCase
  4. def test_add_config
  5. # app config
  6. if !ENV['TWITTER_BT_CONSUMER_KEY']
  7. raise "ERROR: Need TWITTER_BT_CONSUMER_KEY - hint TWITTER_BT_CONSUMER_KEY='1234'"
  8. end
  9. consumer_key = ENV['TWITTER_BT_CONSUMER_KEY']
  10. if !ENV['TWITTER_BT_CONSUMER_SECRET']
  11. raise "ERROR: Need TWITTER_BT_CONSUMER_SECRET - hint TWITTER_BT_CONSUMER_SECRET='1234'"
  12. end
  13. consumer_secret = ENV['TWITTER_BT_CONSUMER_SECRET']
  14. if !ENV['TWITTER_BT_USER_LOGIN']
  15. raise "ERROR: Need TWITTER_BT_USER_LOGIN - hint TWITTER_BT_USER_LOGIN='1234'"
  16. end
  17. twitter_user_login = ENV['TWITTER_BT_USER_LOGIN']
  18. if !ENV['TWITTER_BT_USER_PW']
  19. raise "ERROR: Need TWITTER_BT_USER_PW - hint TWITTER_BT_USER_PW='1234'"
  20. end
  21. twitter_user_pw = ENV['TWITTER_BT_USER_PW']
  22. if !ENV['TWITTER_BT_CUSTOMER_TOKEN']
  23. raise "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN - hint TWITTER_BT_CUSTOMER_TOKEN='1234'"
  24. end
  25. twitter_customer_token = ENV['TWITTER_BT_CUSTOMER_TOKEN']
  26. if !ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET']
  27. raise "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN_SECRET - hint TWITTER_BT_CUSTOMER_TOKEN_SECRET='1234'"
  28. end
  29. twitter_customer_token_secret = ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET']
  30. hash = "#sweet#{hash_gen}"
  31. @browser = browser_instance
  32. login(
  33. username: 'master@example.com',
  34. password: 'test',
  35. url: browser_url,
  36. auto_wizard: true,
  37. )
  38. tasks_close_all()
  39. click(css: 'a[href="#manage"]')
  40. click(css: '.content.active a[href="#channels/twitter"]')
  41. click(css: '.content.active .js-configApp')
  42. sleep 2
  43. set(
  44. css: '.content.active .modal [name=consumer_key]',
  45. value: consumer_key,
  46. )
  47. set(
  48. css: '.content.active .modal [name=consumer_secret]',
  49. value: 'wrong',
  50. )
  51. click(css: '.content.active .modal .js-submit')
  52. watch_for(
  53. css: '.content.active .modal .alert',
  54. value: 'Authorization Required',
  55. )
  56. set(
  57. css: '.content.active .modal [name=consumer_secret]',
  58. value: consumer_secret,
  59. )
  60. click(css: '.content.active .modal .js-submit')
  61. watch_for_disappear(
  62. css: '.content.active .modal .alert',
  63. value: 'Authorization Required',
  64. )
  65. watch_for(
  66. css: '.content.active .js-new',
  67. value: 'add account',
  68. )
  69. click(css: '.content.active .js-configApp')
  70. set(
  71. css: '.content.active .modal [name=consumer_secret]',
  72. value: 'wrong',
  73. )
  74. click(css: '.content.active .modal .js-submit')
  75. watch_for(
  76. css: '.content.active .modal .alert',
  77. value: 'Authorization Required',
  78. )
  79. set(
  80. css: '.content.active .modal [name=consumer_secret]',
  81. value: consumer_secret,
  82. )
  83. click(css: '.content.active .modal .js-submit')
  84. watch_for_disappear(
  85. css: '.content.active .modal .alert',
  86. value: 'Authorization Required',
  87. )
  88. watch_for(
  89. css: '.content.active .js-new',
  90. value: 'add account',
  91. )
  92. click(css: '.content.active .js-new')
  93. sleep 10
  94. set(
  95. css: '#username_or_email',
  96. value: twitter_user_login,
  97. no_click: true, # <label> other element would receive the click
  98. )
  99. set(
  100. css: '#password',
  101. value: twitter_user_pw,
  102. no_click: true, # <label> other element would receive the click
  103. )
  104. click(css: '#allow')
  105. #watch_for(
  106. # css: '.notice.callback',
  107. # value: 'Redirecting you back to the application',
  108. #)
  109. watch_for(
  110. css: '.content.active .modal',
  111. value: 'Search Terms',
  112. )
  113. # add hash tag to search
  114. click(css: '.content.active .modal .js-searchTermAdd')
  115. set(css: '.content.active .modal [name="search::term"]', value: hash)
  116. select(css: '.content.active .modal [name="search::group_id"]', value: 'Users')
  117. click(css: '.content.active .modal .js-submit')
  118. sleep 5
  119. watch_for(
  120. css: '.content.active',
  121. value: 'Bob Mutschler',
  122. )
  123. watch_for(
  124. css: '.content.active',
  125. value: "@#{twitter_user_login}",
  126. )
  127. exists(
  128. css: '.content.active .main .action:nth-child(1)'
  129. )
  130. exists_not(
  131. css: '.content.active .main .action:nth-child(2)'
  132. )
  133. # add account again
  134. click(css: '.content.active .js-new')
  135. sleep 10
  136. click(css: '#allow')
  137. watch_for(
  138. css: '.content.active .modal',
  139. value: 'Search Terms',
  140. )
  141. click(css: '.content.active .modal .js-close')
  142. watch_for(
  143. css: '.content.active',
  144. value: 'Bob Mutschler',
  145. )
  146. watch_for(
  147. css: '.content.active',
  148. value: "@#{twitter_user_login}",
  149. )
  150. exists(
  151. css: '.content.active .main .action:nth-child(1)'
  152. )
  153. exists_not(
  154. css: '.content.active .main .action:nth-child(2)'
  155. )
  156. # wait till new streaming of channel is active
  157. sleep 60
  158. # start tweet from customer
  159. client = Twitter::REST::Client.new do |config|
  160. config.consumer_key = consumer_key
  161. config.consumer_secret = consumer_secret
  162. config.access_token = twitter_customer_token
  163. config.access_token_secret = twitter_customer_token_secret
  164. end
  165. text = "Today #{rand_word}... #{hash} #{hash_gen}"
  166. tweet = client.update(
  167. text,
  168. )
  169. # watch till tweet is in app
  170. click(text: 'Overviews')
  171. # enable full overviews
  172. execute(
  173. js: '$(".content.active .sidebar").css("display", "block")',
  174. )
  175. click(text: 'Unassigned & Open')
  176. sleep 6 # till overview is rendered
  177. watch_for(
  178. css: '.content.active',
  179. value: hash,
  180. timeout: 36,
  181. )
  182. ticket_open_by_title(
  183. title: hash,
  184. )
  185. # reply via app
  186. click(css: '.content.active [data-type="twitterStatusReply"]')
  187. ticket_update(
  188. data: {
  189. body: '@dzucker6 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890',
  190. },
  191. do_not_submit: true,
  192. )
  193. click(
  194. css: '.content.active .js-submit',
  195. )
  196. sleep 10
  197. click(
  198. css: '.content.active .js-reset',
  199. )
  200. sleep 2
  201. match_not(
  202. css: '.content.active',
  203. value: '1234567890',
  204. )
  205. click(css: '.content.active [data-type="twitterStatusReply"]')
  206. sleep 2
  207. re_hash = "#{hash}re#{rand(99_999)}"
  208. ticket_update(
  209. data: {
  210. body: "@dzucker6 #{rand_word} reply #{re_hash} #{rand(999_999)}",
  211. },
  212. )
  213. sleep 20
  214. match(
  215. css: '.content.active .ticket-article',
  216. value: re_hash,
  217. )
  218. # watch till tweet reached customer
  219. sleep 10
  220. text = nil
  221. client.search(re_hash, result_type: 'mixed').collect { |local_tweet|
  222. text = local_tweet.text
  223. }
  224. assert(text)
  225. end
  226. def hash_gen
  227. (0...10).map { ('a'..'z').to_a[rand(26)] }.join + rand(999).to_s
  228. end
  229. def rand_word
  230. words = [
  231. 'dog',
  232. 'cat',
  233. 'house',
  234. 'home',
  235. 'yesterday',
  236. 'tomorrow',
  237. 'new york',
  238. 'berlin',
  239. 'coffee script',
  240. 'java script',
  241. 'bob smith',
  242. 'be open',
  243. 'really nice',
  244. 'stay tuned',
  245. 'be a good boy',
  246. 'invent new things',
  247. ]
  248. words[rand(words.length)]
  249. end
  250. end