diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.html.haml similarity index 87% rename from app/views/shared/_publisher.haml rename to app/views/shared/_publisher.html.haml index 2e2dd88ca..35bc9ce8d 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.html.haml @@ -3,7 +3,7 @@ -# the COPYRIGHT file. -#publisher{:class => ("closed" unless params[:op] || params[:prefill])} +#publisher #click_to_share = image_tag 'icons/doc_edit.png' @@ -27,8 +27,8 @@ %params #publisher_textarea_wrapper %ul#photodropzone - = status.text_area :message, :rows => 2, :value => h(params[:prefill]) - = javascript_tag "if ($('textarea#status_message_message').val() != ''){ $('textarea#status_message_message').focus();}" + = status.text_area :fake_message, :rows => 2, :value => h(params[:prefill]) + = status.hidden_field :message, :value => '' - for aspect_id in @aspect_ids = hidden_field_tag 'aspect_ids[]', aspect_id.to_s diff --git a/features/posts.feature b/features/posts.feature index 6eb0ae968..bcb4c6094 100644 --- a/features/posts.feature +++ b/features/posts.feature @@ -1,27 +1,26 @@ +@javascript Feature: posting In order to enlighten humanity for the good of society As a rock star I want to tell the world I am eating a yogurt - @javascript Scenario: post to all aspects Given I am signed in And I have an aspect called "Family" And I am on the home page And I expand the publisher - When I fill in "status_message_message" with "I am eating a yogurt" + When I fill in "status_message_fake_message" with "I am eating a yogurt" And I press "Share" And I am on the home page Then I should see "I am eating a yogurt" within ".stream_element" - @javascript Scenario: delete a post Given I am signed in And I have an aspect called "Family" And I am on the home page And I expand the publisher - When I fill in "status_message_message" with "I am eating a yogurt" + When I fill in "status_message_fake_message" with "I am eating a yogurt" And I press "Share" And I am on the home page And I hover over the post @@ -32,12 +31,13 @@ Feature: posting Scenario Outline: post to one aspect + Given I have no open aspects saved Given I am signed in And I have an aspect called "PostTo" And I have an aspect called "DidntPostTo" And I am on the home page When I follow "PostTo" - And I fill in "status_message_message" with "I am eating a yogurt" + And I fill in "status_message_fake_message" with "I am eating a yogurt" And I press "Share" And I follow "" Then I should "I am eating a yogurt" diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 3ce3cf4f3..eb5adb46a 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -72,8 +72,11 @@ When /^I click on the contact request$/ do find(".person.request.ui-draggable a").click end +Given /^I have no open aspects saved$/ do + @me.aspects.update_all(:open => false) +end Then /^I should have aspect "([^"]*)" "([^"]*)"$/ do |arg1, arg2| - val = evaluate_script("$('a:contains(\"#{arg1}\")').parent('li').hasClass('selected');") # + val = evaluate_script("$('a:contains(\"#{arg1}\")').parent('li').hasClass('selected');") # if arg2 == "selected" val.should == true elsif arg2 == "not selected" diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index ee8075b86..1750b506f 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -5,8 +5,21 @@ //TODO: make this a widget var Publisher = { + close: function(){ + Publisher.form().addClass('closed'); + Publisher.form().find(".options_and_submit").hide(); + }, + open: function(){ + Publisher.form().removeClass('closed'); + Publisher.form().find(".options_and_submit").show(); + }, + form: function(){return $('#publisher');}, + updateHiddenField: function(evt){ + Publisher.form().find('#status_message_message').val( + Publisher.form().find('#status_message_fake_message').val()); + }, initialize: function() { - var $publisher = $("#publisher"); + var $publisher = Publisher.form(); $("div.public_toggle input").live("click", function(evt) { $("#publisher_service_icons").toggleClass("dim"); if ($(this).attr('checked') == true) { @@ -14,38 +27,16 @@ var Publisher = { } }); - if ($("#status_message_message").val() != "") { - $publisher - .removeClass("closed") - .find("textarea") - .focus(); + if ($("#status_message_fake_message").val() == "") { + Publisher.close(); + }; - $publisher - .find(".options_and_submit") - .show(); - } - - $publisher.find("textarea").live("focus", function(evt) { - $publisher.find(".options_and_submit").show(); - }); - - $publisher.find("textarea").live("click", function(evt) { - $publisher - .removeClass("closed") - .find("textarea") - .focus(); - }); - - - $publisher.find("textarea").bind("focus", function() { - $(this) - .css('min-height', '42px'); - }); - - $publisher.find("form").bind("blur", function() { - $publisher - .find("textarea") - .css('min-height', '2px'); + Publisher.updateHiddenField(); + $publisher.find('#status_message_fake_message').change( + Publisher.updateHiddenField); + $publisher.find("textarea").bind("focus", function(evt) { + Publisher.open(); + $(this).css('min-height', '42px'); }); } }; diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 11fe163a3..b7fd036c9 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -57,7 +57,14 @@ describe AspectsController do get :index assigns[:contacts].map{|c| c.id}.should == @user.contacts.map{|c| c.id} end - + it "generates a jasmine fixture" do + get :index + save_fixture(html_for("body"), "aspects_index") + end + it "generates a jasmine fixture with a prefill" do + get :index, :prefill => "reshare things" + save_fixture(html_for("body"), "aspects_index_prefill") + end context 'filtering' do before do @posts = [] diff --git a/spec/javascripts/publisher-spec.js b/spec/javascripts/publisher-spec.js index 82e7c9bc8..203390b9c 100644 --- a/spec/javascripts/publisher-spec.js +++ b/spec/javascripts/publisher-spec.js @@ -5,4 +5,77 @@ describe("Publisher", function() { + describe("initialize", function(){ + it("calls updateHiddenField", function(){ + spec.loadFixture('aspects_index_prefill'); + spyOn(Publisher, 'updateHiddenField'); + Publisher.initialize(); + expect(Publisher.updateHiddenField).toHaveBeenCalled(); + }); + + it("attaches updateHiddenField to the change handler on fake_message", function(){ + spec.loadFixture('aspects_index_prefill'); + spyOn(Publisher, 'updateHiddenField'); + Publisher.initialize(); + Publisher.form().find('#status_message_fake_message').change(); + expect(Publisher.updateHiddenField.mostRecentCall.args[0].type).toBe('change'); + }); + + it("calls close when it does not have text", function(){ + spec.loadFixture('aspects_index'); + spyOn(Publisher, 'close'); + Publisher.initialize(); + expect(Publisher.close).toHaveBeenCalled(); + }); + + it("does not call close when there is prefilled text", function(){ + spec.loadFixture('aspects_index_prefill'); + spyOn(Publisher, 'close'); + Publisher.initialize(); + expect(Publisher.close).wasNotCalled(); + }); + }); + describe("open", function() { + beforeEach(function() { + spec.loadFixture('aspects_index'); + Publisher.initialize(); + }); + it("removes the closed class", function() { + expect(Publisher.form().hasClass('closed')).toBeTruthy(); + Publisher.open(); + expect(Publisher.form().hasClass('closed')).toBeFalsy(); + }); + it("shows the options_and_submit div", function() { + expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0); + Publisher.open(); + expect(Publisher.form().find(".options_and_submit:visible").length).toBe(1); + }); + }); + describe("close", function() { + beforeEach(function() { + spec.loadFixture('aspects_index_prefill'); + Publisher.initialize(); + }); + it("adds the closed class", function() { + expect(Publisher.form().hasClass('closed')).toBeFalsy(); + Publisher.close(); + expect(Publisher.form().hasClass('closed')).toBeTruthy(); + }); + it("hides the options_and_submit div", function() { + expect(Publisher.form().find(".options_and_submit:visible").length).toBe(1); + Publisher.close(); + expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0); + }); + }); + describe("updateHiddenField", function(){ + beforeEach(function(){ + spec.loadFixture('aspects_index_prefill'); + }); + + it("copies the value of fake_message to message",function(){ + Publisher.updateHiddenField(); + expect(Publisher.form().find('#status_message_message').val()).toBe( + Publisher.form().find('#status_message_fake_message').val()); + }); + }); }); diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index dc0352947..f142bd8f1 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -29,6 +29,7 @@ src_files: - public/javascripts/aspect-contacts.js - public/javascripts/web-socket-receiver.js - public/javascripts/view.js + - public/javascripts/publisher.js - public/javascripts/stream.js - public/javascripts/validation.js - public/javascripts/rails.js