From b6797d09ec61655f1a3baa6fce27b2e83a34882d Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 26 Jul 2016 16:00:09 -0300 Subject: [PATCH] Add step for mention text --- features/step_definitions/custom_web_steps.rb | 16 ++++++++++++++++ features/user_mention.feature | 33 +++++++++++++++++++++++++++++++++ public/javascripts/vendor/jquery.mentionsInput.mod.js | 10 ++++++++++ public/javascripts/vendor/jquery.mentionsInput.mod.min.js | 2 +- 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 features/user_mention.feature diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 9d9503e..eb802ca 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -53,3 +53,19 @@ When /^I type in "([^\"]*)" into autocomplete list "([^\"]*)" and I choose "([^\ page.execute_script ("jQuery('.token-input-dropdown li:contains(\"#{result}\")').trigger('mousedown');") page.should have_selector('li.token-input-token') end + +When /^I type "([^\"]*)" into mention textarea "([^\"]*)" and I choose "([^\"]*)"$/ do |term, textarea, result| + # We seem to have to wait for the page to load js + sleep 1 + + page.execute_script("setInputBuffer('#{term}')") + + page.execute_script("jQuery('##{input}').trigger('focus').val('#{term}').trigger('input')") + + # We use this to wait for the search + page.should have_selector('.mentions-autocomplete-list li') + + page.execute_script ("jQuery('.mentions-autocomplete-list li:contains(\"#{result}\")').trigger('mousedown');") + + page.should have_selector('li.token-input-token') +end diff --git a/features/user_mention.feature b/features/user_mention.feature new file mode 100644 index 0000000..05ed9b5 --- /dev/null +++ b/features/user_mention.feature @@ -0,0 +1,33 @@ +Feature: user mention +As a user + I want to mention my friends and community members + So that they get notified about what I wrote + + Background: + Given the following users + | login | + | fulano | + | ciclano | + | deltrano | + And "ciclano" is friend of "fulano" + And the following communities + | identifier | name | owner | + | test-community | test community | fulano | + And "deltrano" is a member of "test community" + And the following articles + | owner | name | + | fulano | fulano article | + | test-community | comunity article | + And I am logged in as "fulano" + + + @selenium + Scenario: mention a friend + Given I am on /fulano/fulano-article + And I follow "Post a comment" + And I fill in "Title" with "Hey ho, let's go!" + And I type "@cic" into mention textarea "#comment_body" and I choose "ciclano" + And I should see "@ciclano" + When I press "Post comment" + Then I should see "Hey ho, let" + diff --git a/public/javascripts/vendor/jquery.mentionsInput.mod.js b/public/javascripts/vendor/jquery.mentionsInput.mod.js index c786cf8..a1bd266 100644 --- a/public/javascripts/vendor/jquery.mentionsInput.mod.js +++ b/public/javascripts/vendor/jquery.mentionsInput.mod.js @@ -176,6 +176,16 @@ inputBuffer = []; } + // selenium tests purposes only + function setInputBuffer(value) { + if (_.isArray(value)) { + inputBuffer = value; + } else if (_.isString(value)) { + inputBuffer = value.split(""); + } + } + window.setInputBuffer = setInputBuffer; + //Updates the mentions collection function updateMentionsCollection() { var inputText = getInputBoxValue(); //Get the actual value of text area diff --git a/public/javascripts/vendor/jquery.mentionsInput.mod.min.js b/public/javascripts/vendor/jquery.mentionsInput.mod.min.js index 306032b..2417c2e 100644 --- a/public/javascripts/vendor/jquery.mentionsInput.mod.min.js +++ b/public/javascripts/vendor/jquery.mentionsInput.mod.min.js @@ -1 +1 @@ -!function(e,t,n){t.templateSettings={interpolate:/<%=([\s\S]+?)%>/g};var i={BACKSPACE:8,TAB:9,RETURN:13,ESC:27,LEFT:37,UP:38,RIGHT:39,DOWN:40,COMMA:188,SPACE:32,HOME:36,END:35},a={triggerChar:"@",onDataRequest:e.noop,minChars:2,allowRepeat:!1,showAvatars:!0,elastic:!0,defaultValue:"",onCaret:!1,keepTriggerCharacter:!1,classes:{autoCompleteItemActive:"active"},templates:{wrapper:t.template('
'),autocompleteList:t.template('
'),autocompleteListItem:t.template('
  • <%= content %> <%= fullName %>
  • '),autocompleteListItemAvatar:t.template(''),autocompleteListItemIcon:t.template('
    '),mentionsOverlay:t.template('
    '),mentionItemSyntax:t.template("@[<%= value %>](<%= type %>:<%= id %>)"),mentionItemHighlight:t.template("<%= value %>")}},o={htmlEncode:function(e){return t.escape(e)},regexpEncode:function(e){return e.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")},highlightTerm:function(e,t){return t||t.length?e.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+t+")(?![^<>]*>)(?![^&;]+;)","gi"),"$1"):e},setCaratPosition:function(e,t){if(e.createTextRange){var n=e.createTextRange();n.move("character",t),n.select()}else e.selectionStart?(e.focus(),e.setSelectionRange(t,t)):e.focus()},rtrim:function(e){return e.replace(/\s+$/,"")}},r=function(n){function r(){M=e(k),"true"!==M.attr("data-mentions-input")&&(L=M.parent(),O=e(n.templates.wrapper()),M.wrapAll(O),O=L.find("> div.mentions-input-box"),M.attr("data-mentions-input","true"),M.bind("keydown",b),M.bind("keypress",E),M.bind("click",x),M.bind("blur",C),navigator.userAgent.indexOf("MSIE 8")>-1?M.bind("propertychange",w):M.bind("input",w),n.elastic&&M.elastic())}function l(){N=e(n.templates.autocompleteList()),N.appendTo(O),N.delegate("li","mousedown",v)}function s(){H=e(n.templates.mentionsOverlay()),H.prependTo(O)}function c(){var e=f();t.each(P,function(t){var i=n.templates.mentionItemSyntax(t);e=e.replace(new RegExp(o.regexpEncode(t.value),"g"),i)});var i=o.htmlEncode(e);t.each(P,function(e){var a=t.extend({},e,{value:o.htmlEncode(e.value)}),r=n.templates.mentionItemSyntax(a),l=n.templates.mentionItemHighlight(a);i=i.replace(new RegExp(o.regexpEncode(r),"g"),l)}),i=i.replace(/\n/g,"
    "),i=i.replace(/ {2}/g,"  "),M.data("messageText",e),M.trigger("updated"),H.find("div").html(i)}function d(){F=[]}function p(){var e=f();P=t.reject(P,function(t,n){return!t.value||e.indexOf(t.value)==-1}),P=t.compact(P)}function u(e){for(var i,a=f(),r=M[0].selectionStart,l=!1,s=!1,p=new RegExp("\\"+n.triggerChar+W,"gi");i=p.exec(a);)(l===!1||Math.abs(p.lastIndex-r)t&&e(window).scrollTop(t-n)}function v(t){var n=e(this),i=B[n.attr("data-uid")];return u(i),h(),!1}function x(e){d()}function C(e){y()}function w(e){c(),p();var i=t.lastIndexOf(F,n.triggerChar);i>-1&&(W=F.slice(i+1).join(""),W=o.rtrim(W),t.defer(t.bind(S,this,W)))}function E(e){if(e.keyCode!==i.BACKSPACE){var t=String.fromCharCode(e.which||e.keyCode);F.push(t)}}function b(n){if(n.keyCode===i.LEFT||n.keyCode===i.RIGHT||n.keyCode===i.HOME||n.keyCode===i.END)return t.defer(d),void(navigator.userAgent.indexOf("MSIE 9")>-1&&t.defer(c));if(n.keyCode===i.BACKSPACE)return void(F=F.slice(0,-1+F.length));if(!N.is(":visible"))return!0;switch(n.keyCode){case i.UP:case i.DOWN:var a=null;return a=n.keyCode===i.DOWN?D&&D.length?D.next():N.find("li").first():e(D).prev(),a.length&&T(a),!1;case i.RETURN:case i.TAB:if(D&&D.length)return D.trigger("mousedown"),!1}return!0}function y(){D=null,N.empty().hide()}function T(e){e.addClass(n.classes.autoCompleteItemActive),e.siblings().removeClass(n.classes.autoCompleteItemActive),D=e}function I(i,a){if(N.show(),!n.allowRepeat){var r=t.pluck(P,"value");a=t.reject(a,function(e){return t.include(r,e.name)})}if(!a.length)return void y();N.empty();var l=e("