From 2831e81985349b7d2b2ca5e452728b4e3cd57bdd Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 28 Jan 2016 09:50:05 +0100 Subject: [PATCH] Added facebook agent tests. --- .../ticket_zoom/article_actions.coffee | 25 ++++++ .../ticket_zoom/article_new.coffee | 11 ++- test/integration/facebook_browser_test.rb | 83 ++++++++++++++++--- 3 files changed, 104 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee index 2e8a84f8c..f80f79d3d 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee @@ -6,6 +6,7 @@ class App.TicketZoomArticleActions extends App.Controller 'click [data-type=emailReplyAll]': 'emailReplyAll' 'click [data-type=twitterStatusReply]': 'twitterStatusReply' 'click [data-type=twitterDirectMessageReply]': 'twitterDirectMessageReply' + 'click [data-type=facebookFeedReply]': 'facebookFeedReply' constructor: -> super @@ -110,6 +111,13 @@ class App.TicketZoomArticleActions extends App.Controller icon: 'reply' href: '#' } + if article.type.name is 'facebook feed post' || article.type.name is 'facebook feed comment' + actions.push { + name: 'reply' + type: 'facebookFeedReply' + icon: 'reply' + href: '#' + } actions.push { name: 'split' @@ -119,6 +127,23 @@ class App.TicketZoomArticleActions extends App.Controller } actions + facebookFeedReply: (e) => + e.preventDefault() + + type = App.TicketArticleType.findByAttribute('name', 'facebook feed comment') + console.log('tt', type) + @scrollToCompose() + + # empty form + articleNew = { + to: '' + cc: '' + body: '' + in_reply_to: '' + } + + App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew } ) + twitterStatusReply: (e) => e.preventDefault() diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee index 5975afeeb..f0381d2cd 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -40,6 +40,8 @@ class App.TicketZoomArticleNew extends App.Controller possibleArticleType['twitter direct-message'] = true else if articleTypeCreate is 'email' possibleArticleType['email'] = true + else if articleTypeCreate is 'facebook feed post' + possibleArticleType['facebook feed comment'] = true if @ticket && @ticket.customer_id customer = App.User.find(@ticket.customer_id) if customer.email @@ -62,11 +64,12 @@ class App.TicketZoomArticleNew extends App.Controller attributes: ['to', 'cc'] features: ['attachment'] } - if possibleArticleType.facebook + if possibleArticleType['facebook feed comment'] @articleTypes.push { - name: 'facebook' + name: 'facebook feed comment' icon: 'facebook' attributes: [] + features: [] } if possibleArticleType['twitter status'] @articleTypes.push { @@ -283,6 +286,10 @@ class App.TicketZoomArticleNew extends App.Controller App.Utils.htmlRemoveRichtext(@$('[data-name=body]')) params.content_type = 'text/plain' params.body = "#{App.Utils.html2text(params.body, true)}\n#{@signature.text()}" + if params.type is 'facebook feed comment' + App.Utils.htmlRemoveRichtext(@$('[data-name=body]')) + params.content_type = 'text/plain' + params.body = App.Utils.html2text(params.body, true) params diff --git a/test/integration/facebook_browser_test.rb b/test/integration/facebook_browser_test.rb index 3c36d172b..3774b7867 100644 --- a/test/integration/facebook_browser_test.rb +++ b/test/integration/facebook_browser_test.rb @@ -5,22 +5,33 @@ class FacebookBrowserTest < TestCase def test_add_config # app config - if !ENV['FACEBOOK_APP_ID'] - fail "ERROR: Need FACEBOOK_APP_ID - hint FACEBOOK_APP_ID='1234'" + if !ENV['FACEBOOK_BT_APP_ID'] + fail "ERROR: Need FACEBOOK_BT_APP_ID - hint FACEBOOK_BT_APP_ID='1234'" end - app_id = ENV['FACEBOOK_APP_ID'] - if !ENV['FACEBOOK_APP_SECRET'] - fail "ERROR: Need FACEBOOK_APP_SECRET - hint FACEBOOK_APP_SECRET='1234'" + app_id = ENV['FACEBOOK_BT_APP_ID'] + if !ENV['FACEBOOK_BT_APP_SECRET'] + fail "ERROR: Need FACEBOOK_BT_APP_SECRET - hint FACEBOOK_BT_APP_SECRET='1234'" end - app_secret = ENV['FACEBOOK_APP_SECRET'] - if !ENV['FACEBOOK_USER_LOGIN'] - fail "ERROR: Need FACEBOOK_USER_LOGIN - hint FACEBOOK_USER_LOGIN='1234'" + app_secret = ENV['FACEBOOK_BT_APP_SECRET'] + if !ENV['FACEBOOK_BT_USER_LOGIN'] + fail "ERROR: Need FACEBOOK_BT_USER_LOGIN - hint FACEBOOK_BT_USER_LOGIN='1234'" end - user_login = ENV['FACEBOOK_USER_LOGIN'] - if !ENV['FACEBOOK_USER_PW'] - fail "ERROR: Need FACEBOOK_USER_PW - hint FACEBOOK_USER_PW='1234'" + user_login = ENV['FACEBOOK_BT_USER_LOGIN'] + if !ENV['FACEBOOK_BT_USER_PW'] + fail "ERROR: Need FACEBOOK_BT_USER_PW - hint FACEBOOK_BT_USER_PW='1234'" end - user_pw = ENV['FACEBOOK_USER_PW'] + user_pw = ENV['FACEBOOK_BT_USER_PW'] + if !ENV['FACEBOOK_BT_PAGE_ID'] + fail "ERROR: Need FACEBOOK_BT_PAGE_ID - hint FACEBOOK_BT_PAGE_ID='1234'" + end + page_id = ENV['FACEBOOK_BT_PAGE_ID'] + + if !ENV['FACEBOOK_BT_CUSTOMER'] + fail "ERROR: Need FACEBOOK_BT_CUSTOMER - hint FACEBOOK_BT_CUSTOMER='name:1234:access_token'" + end + customer_name = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[0] + customer_id = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[1] + customer_access_token = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[2] @browser = browser_instance login( @@ -129,7 +140,9 @@ class FacebookBrowserTest < TestCase value: 'Dashboard', ) - click(css: '#content .modal .js-close') + select(css: '#content .modal [name="pages::' + page_id + '::group_id"]', value: 'Users') + click(css: '#content .modal .js-submit') + sleep 5 watch_for( css: '#content', @@ -165,6 +178,50 @@ class FacebookBrowserTest < TestCase exists_not( css: '#content .main .action:nth-child(2)' ) + sleep 50 + + # post new posting + hash = "##{rand(999_999)}" + customer_client = Koala::Facebook::API.new(customer_access_token) + message = "I need some help for your product #{hash}" + post = customer_client.put_wall_post(message, {}, page_id) + + # watch till post is in app + click( text: 'Overviews' ) + + # enable full overviews + execute( + js: '$(".content.active .sidebar").css("display", "block")', + ) + + click( text: 'Unassigned & Open' ) + sleep 6 # till overview is rendered + + watch_for( + css: '.content.active', + value: hash, + timeout: 40, + ) + + ticket_open_by_title( + title: hash, + ) + click( css: '.content.active [data-type="facebookFeedReply"]' ) + sleep 2 + + re_hash = "#{hash}re#{rand(99_999)}" + + ticket_update( + data: { + body: "You need to do this #{re_hash} #{rand(999_999)}", + }, + ) + sleep 20 + + match( + css: '.content.active .ticket-article', + value: re_hash, + ) end