From 20da08408f8ea574b82335a8980c87f9d64b6dc8 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Wed, 11 Apr 2012 17:00:57 -0700 Subject: [PATCH] can mention in new composer --- app/assets/javascripts/app/forms/post_form.js | 14 +-------- app/assets/javascripts/app/pages/composer.js | 14 +++++---- features/step_definitions/trumpeter_steps.rb | 29 ++++++++++++++----- features/trumpeter.feature | 8 ++--- spec/javascripts/app/pages/composer_spec.js | 9 ++++-- 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/app/forms/post_form.js b/app/assets/javascripts/app/forms/post_form.js index c21137691..d5a3ff84b 100644 --- a/app/assets/javascripts/app/forms/post_form.js +++ b/app/assets/javascripts/app/forms/post_form.js @@ -11,19 +11,7 @@ app.forms.Post = app.views.Base.extend({ }, postRenderTemplate : function() { - //this.prepAndBindMentions() - }, - - prepAndBindMentions : function(){ Mentions.initialize(this.$("textarea.text")); - Mentions.fetchContacts(); - - this.$("textarea.text").bind("textchange", $.proxy(this.updateTextWithMarkup, this)) - }, - - updateTextWithMarkup : function() { - this.$("form textarea.text").mentionsInput('val', function(markup){ - $('#text_with_markup').val(markup); - }); + Mentions.fetchContacts(); //mentions should use app.currentUser } }); \ No newline at end of file diff --git a/app/assets/javascripts/app/pages/composer.js b/app/assets/javascripts/app/pages/composer.js index fe5f947e1..3eb552a52 100644 --- a/app/assets/javascripts/app/pages/composer.js +++ b/app/assets/javascripts/app/pages/composer.js @@ -11,8 +11,7 @@ app.pages.Composer = app.views.Base.extend({ }, formAttrs : { -// "textarea#text_with_markup" : "text", //fix mentions - "textarea.text" : "text", + "textarea#text_with_markup" : "text", "input.aspect_ids" : "aspect_ids", "input.service:checked" : "services" }, @@ -25,8 +24,13 @@ app.pages.Composer = app.views.Base.extend({ }, navigateNext : function(){ - this.setModelAttributes(); - app.router.navigate("framer", true); + this.$("form textarea.text").mentionsInput('val', + _.bind(function(markup){ + $('#text_with_markup').val(markup); + this.setModelAttributes(); + app.router.navigate("framer", true); + }, this) + ); }, setModelAttributes : function(evt){ @@ -57,7 +61,7 @@ app.views.ComposerControls = app.views.Base.extend({ subviews : { ".aspect-selector" : "aspectsDropdown", - ".service-selector" : "servicesSelector", + ".service-selector" : "servicesSelector" }, initialize : function() { diff --git a/features/step_definitions/trumpeter_steps.rb b/features/step_definitions/trumpeter_steps.rb index 273b0c782..98f382be0 100644 --- a/features/step_definitions/trumpeter_steps.rb +++ b/features/step_definitions/trumpeter_steps.rb @@ -1,6 +1,21 @@ -def fill_in_autocomplete(selector, value) - pending #make me work if yr board, investigate send_keys - page.execute_script %Q{$('#{selector}').val('#{value}').keyup()} +def mention_alice(user_name) + #find(selector).native.send_keys(value) + page.execute_script <<-JAVASCRIPT + var mentionsInput = $("textarea.text") + + triggerKeypress(64) //@ + triggerKeypress(97) //a + mentionsInput.trigger("input") //bring up c + + + function triggerKeypress(keyCode){ + var e = new $.Event("keypress") + e.which = keyCode //@ + mentionsInput.trigger(e) + } + JAVASCRIPT + page.find(".mentions-autocomplete-list li:contains('Alice Smith')").click() + sleep(1) end def aspects_dropdown @@ -62,9 +77,7 @@ When /^I write "([^"]*)"(?:| with body "([^"]*)")$/ do |headline, body| end Then /I mention "([^"]*)"$/ do |text| - fill_in_autocomplete('textarea.text', '@a') - sleep(5) - find("li.active").click + mention_alice('@a') end When /^I select "([^"]*)" in my aspects dropdown$/ do |title| @@ -135,6 +148,6 @@ When /^the frame's body should be "([^"]*)"$/ do |body_text| find("section.body").text.should == body_text end -Then /^the first post should mention "([^"]*)"$/ do |user_name| - pending +Then /^the post should mention "([^"]*)"$/ do |user_name| + within('#post-content') { find("a:contains('#{user_name}')").should be_present } end diff --git a/features/trumpeter.feature b/features/trumpeter.feature index f0f2deb64..ff10f679b 100644 --- a/features/trumpeter.feature +++ b/features/trumpeter.feature @@ -23,14 +23,14 @@ Feature: Creating a new post Then I should see "This is super skrunkle" as the first post in my stream Then "This is super skrunkle" should be a limited post in my stream - @wip Scenario: Mention a contact Given a user named "Alice Smith" with email "alice@alice.alice" And a user with email "bob@bob.bob" is connected with "alice@alice.alice" - And I mention "alice@alice.alice" + And I trumpet + And I wait for the ajax to finish + And I mention "Alice Smith" And I go through the default composer - And I go to "/stream" - Then the first post should mention "Alice Smith" + Then the post should mention "Alice Smith" Scenario: Uploading multiple photos When I write "check out these pictures" diff --git a/spec/javascripts/app/pages/composer_spec.js b/spec/javascripts/app/pages/composer_spec.js index e50ac9e98..d4312ee02 100644 --- a/spec/javascripts/app/pages/composer_spec.js +++ b/spec/javascripts/app/pages/composer_spec.js @@ -46,9 +46,12 @@ describe("app.pages.Composer", function(){ it("instantiates a post on form submit", function(){ this.page.$("button.next").click() - expect(this.page.model.get("text")).toBe("Oh My") - expect(this.page.model.get("aspect_ids")).toBe("public") - expect(this.page.model.get("services").length).toBe(2) + waitsFor(function(){ return this.page.$("#text_with_markup").text() == "Oh My" }) + runs(function(){ + expect(this.page.model.get("aspect_ids")).toBe("public") + expect(this.page.model.get("services").length).toBe(2) + expect(this.page.model.get("text")).toBe("Oh My")) + }) }) }); })