From fe0156a18b5eb2220d988f696117a52a8fcf5cf3 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Mon, 21 May 2012 15:14:23 -0700 Subject: [PATCH] cuking out new stream, refactors. --- app/assets/javascripts/app/pages/framer.js | 2 +- app/assets/javascripts/app/pages/profile.js | 1 - app/assets/javascripts/app/pages/stream.js | 6 ++--- app/assets/javascripts/app/views.js | 5 ++-- .../javascripts/app/views/canvas_view.js | 9 +++++--- .../javascripts/app/views/photos_view.js | 4 ++-- .../app/views/{ => post}/canvas_frame.js | 6 +++-- .../app/views/{ => post}/small_frame.js | 4 ++-- .../app/views/post/stream_frame.js | 2 ++ .../javascripts/app/views/stream_view.js | 4 ++-- features/new_hotness/new_stream.feature | 22 ++++++++++++++++++ .../{ => new_hotness}/post_viewer.feature | 0 features/{ => new_hotness}/trumpeter.feature | 2 +- .../new_hotness/new_stream_steps.rb | 23 +++++++++++++++++++ .../new_hotness/new_user_steps.rb | 19 +++++++++++++++ .../{ => new_hotness}/trumpeter_steps.rb | 9 +++++++- features/step_definitions/posts_steps.rb | 1 + features/step_definitions/session_steps.rb | 2 +- features/support/paths.rb | 2 ++ features/support/publishing_cuke_helpers.rb | 8 +++++++ .../app/views/{ => post}/canvas_frame_spec.js | 4 ++-- .../views/{ => post}/small_frame_view_spec.js | 4 ++-- 22 files changed, 114 insertions(+), 25 deletions(-) rename app/assets/javascripts/app/views/{ => post}/canvas_frame.js (93%) rename app/assets/javascripts/app/views/{ => post}/small_frame.js (96%) create mode 100644 app/assets/javascripts/app/views/post/stream_frame.js create mode 100644 features/new_hotness/new_stream.feature rename features/{ => new_hotness}/post_viewer.feature (100%) rename features/{ => new_hotness}/trumpeter.feature (98%) create mode 100644 features/step_definitions/new_hotness/new_stream_steps.rb create mode 100644 features/step_definitions/new_hotness/new_user_steps.rb rename features/step_definitions/{ => new_hotness}/trumpeter_steps.rb (95%) rename spec/javascripts/app/views/{ => post}/canvas_frame_spec.js (88%) rename spec/javascripts/app/views/{ => post}/small_frame_view_spec.js (91%) diff --git a/app/assets/javascripts/app/pages/framer.js b/app/assets/javascripts/app/pages/framer.js index 402c6552e..f50ef5676 100644 --- a/app/assets/javascripts/app/pages/framer.js +++ b/app/assets/javascripts/app/pages/framer.js @@ -24,7 +24,7 @@ app.pages.Framer = app.views.Base.extend({ }, postView : function(){ - return new app.views.SmallFrame({model : this.model}) + return new app.views.Post.SmallFrame({model : this.model}) }, navigateNext : function(){ diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 149ad3f13..1ef123af9 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -1,4 +1,3 @@ -//= require ../views/small_frame //= require ../views/profile_info_view app.pages.Profile = app.views.Base.extend({ diff --git a/app/assets/javascripts/app/pages/stream.js b/app/assets/javascripts/app/pages/stream.js index 78cc8c5d3..477257de5 100644 --- a/app/assets/javascripts/app/pages/stream.js +++ b/app/assets/javascripts/app/pages/stream.js @@ -1,11 +1,11 @@ -app.views.NewStream = app.views.Base.extend(_.extend({}, app.views.infiniteScrollMixin, { +app.views.NewStream = app.views.InfScroll.extend({ initialize: function(){ this.stream = this.model this.collection = this.stream.items - this.postClass = app.views.SmallFrame + this.postClass = app.views.Post.StreamFrame this.setupInfiniteScroll() } -})); +}); app.pages.Stream = app.views.Base.extend({ templateName : "stream", diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index 7491b721b..4c290b105 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -95,7 +95,7 @@ app.views.Base = Backbone.View.extend({ // a #paginate div in the layout // a call to setupInfiniteScroll -app.views.infiniteScrollMixin = { +app.views.InfScroll = app.views.Base.extend({ setupInfiniteScroll : function() { this.postViews = this.postViews || [] @@ -163,4 +163,5 @@ app.views.infiniteScrollMixin = { this.trigger("loadMore") } } -}; +}); + diff --git a/app/assets/javascripts/app/views/canvas_view.js b/app/assets/javascripts/app/views/canvas_view.js index 9ab178228..e3b1e0a6a 100644 --- a/app/assets/javascripts/app/views/canvas_view.js +++ b/app/assets/javascripts/app/views/canvas_view.js @@ -1,8 +1,9 @@ -app.views.Canvas = app.views.Base.extend(_.extend({}, app.views.infiniteScrollMixin, { +app.views.Canvas = app.views.InfScroll.extend({ initialize: function(){ this.stream = this.model this.collection = this.stream.items - this.postClass = app.views.CanvasFrame + this.postClass = app.views.Post.CanvasFrame + this.postViews = [] this.setupInfiniteScroll() this.stream.bind("reLayout", this.reLayout, this) this.stream.bind("fetched", this.triggerRelayoutAfterImagesLoaded, this) @@ -57,10 +58,12 @@ app.views.Canvas = app.views.Base.extend(_.extend({}, app.views.infiniteScrollMi }, triggerRelayoutAfterImagesLoaded : function(){ + //event apparently only fires once this.$el.imagesLoaded(_.bind(this.reLayout, this)) }, reLayout : function(){ + console.log("relaying out") this.$el.isotope("reLayout") } -})); +}); diff --git a/app/assets/javascripts/app/views/photos_view.js b/app/assets/javascripts/app/views/photos_view.js index dff7052d3..7be0a86f2 100644 --- a/app/assets/javascripts/app/views/photos_view.js +++ b/app/assets/javascripts/app/views/photos_view.js @@ -1,4 +1,4 @@ -app.views.Photos = Backbone.View.extend(_.extend({ +app.views.Photos = app.views.InfScroll.extend({ initialize : function(options) { this.stream = this.model; this.collection = this.stream.items; @@ -20,4 +20,4 @@ app.views.Photos = Backbone.View.extend(_.extend({ }); $(this.el).delegate("a.photo-link", "click", this.lightbox.lightboxImageClicked); } -}, app.views.infiniteScrollMixin)); +}); diff --git a/app/assets/javascripts/app/views/canvas_frame.js b/app/assets/javascripts/app/views/post/canvas_frame.js similarity index 93% rename from app/assets/javascripts/app/views/canvas_frame.js rename to app/assets/javascripts/app/views/post/canvas_frame.js index fd471a4e1..e0ed1611c 100644 --- a/app/assets/javascripts/app/views/canvas_frame.js +++ b/app/assets/javascripts/app/views/post/canvas_frame.js @@ -1,7 +1,6 @@ //= require ./small_frame -app.views.CanvasFrame = app.views.SmallFrame.extend({ - +app.views.Post.CanvasFrame = app.views.Post.SmallFrame.extend({ SINGLE_COLUMN_WIDTH : 265, DOUBLE_COLUMN_WIDTH : 560, @@ -32,12 +31,15 @@ app.views.CanvasFrame = app.views.SmallFrame.extend({ }, presenter : function(){ + console.log("here") + return _.extend(this.smallFramePresenter(), { adjustedImageHeight : this.adjustedImageHeight() }) }, favoritePost : function(evt) { + console.log("in favorite post") if(evt) { /* follow links instead of faving the targeted post */ if($(evt.target).is('a')) { return } diff --git a/app/assets/javascripts/app/views/small_frame.js b/app/assets/javascripts/app/views/post/small_frame.js similarity index 96% rename from app/assets/javascripts/app/views/small_frame.js rename to app/assets/javascripts/app/views/post/small_frame.js index 8a5825b26..cef828864 100644 --- a/app/assets/javascripts/app/views/small_frame.js +++ b/app/assets/javascripts/app/views/post/small_frame.js @@ -1,6 +1,6 @@ -//= require "./post_view" +//= require "../post_view" -app.views.SmallFrame = app.views.Post.extend({ +app.views.Post.SmallFrame = app.views.Post.extend({ className : "canvas-frame", templateName : "small-frame/default", // default to fall back to diff --git a/app/assets/javascripts/app/views/post/stream_frame.js b/app/assets/javascripts/app/views/post/stream_frame.js new file mode 100644 index 000000000..2f08d9df3 --- /dev/null +++ b/app/assets/javascripts/app/views/post/stream_frame.js @@ -0,0 +1,2 @@ +app.views.Post.StreamFrame = app.views.Post.SmallFrame.extend({ +}) \ No newline at end of file diff --git a/app/assets/javascripts/app/views/stream_view.js b/app/assets/javascripts/app/views/stream_view.js index e472ba5a5..5ecb6debc 100644 --- a/app/assets/javascripts/app/views/stream_view.js +++ b/app/assets/javascripts/app/views/stream_view.js @@ -1,4 +1,4 @@ -app.views.Stream = Backbone.View.extend(_.extend( app.views.infiniteScrollMixin, { +app.views.Stream = app.views.InfScroll.extend({ initialize: function(options) { this.stream = this.model this.collection = this.stream.items @@ -24,4 +24,4 @@ app.views.Stream = Backbone.View.extend(_.extend( app.views.infiniteScrollMixin, _.map(this.postViews, function(view){ view.render() }) } } -})); +}); diff --git a/features/new_hotness/new_stream.feature b/features/new_hotness/new_stream.feature new file mode 100644 index 000000000..9fc08860e --- /dev/null +++ b/features/new_hotness/new_stream.feature @@ -0,0 +1,22 @@ +@javascript +Feature: Interacting with the stream + Background: + Given I am logged in as a beta user with email "bill@bill.com" + And "bill@bill.com" is an admin + And I make a new publisher post "I like it like that." + And I make a new publisher post "yeah baby." + And I make a new publisher post "I got soul." + When I go to the new stream + + Scenario: Visiting the stream + Then "I got soul." should be frame 1 + Then "yeah baby." should be frame 2 + Then "I like it like that." should be frame 3 + +# Scenario: Clicking on a post show the interactions +# And I wait for 5 seconds +# When I click into the "I got soul." stream frame +# And I make a show page comment "you're such a pip" +# And I go to the new stream +# When I click the "I got soul." stream frame +# Then "you're such a pip" should be a comment for "I got soul." \ No newline at end of file diff --git a/features/post_viewer.feature b/features/new_hotness/post_viewer.feature similarity index 100% rename from features/post_viewer.feature rename to features/new_hotness/post_viewer.feature diff --git a/features/trumpeter.feature b/features/new_hotness/trumpeter.feature similarity index 98% rename from features/trumpeter.feature rename to features/new_hotness/trumpeter.feature index 9dbe06aa5..d75b4f415 100644 --- a/features/trumpeter.feature +++ b/features/new_hotness/trumpeter.feature @@ -40,7 +40,7 @@ Feature: Creating a new post When I write "check out these pictures" And I upload a fixture picture with filename "button.gif" And I upload a fixture picture with filename "button.gif" - And I go through the default composer + And I go through the default framer And I go to "/stream" Then "check out these pictures" should have 2 pictures diff --git a/features/step_definitions/new_hotness/new_stream_steps.rb b/features/step_definitions/new_hotness/new_stream_steps.rb new file mode 100644 index 000000000..bf7a7eb9c --- /dev/null +++ b/features/step_definitions/new_hotness/new_stream_steps.rb @@ -0,0 +1,23 @@ +Then /^"([^"]*)" should be frame (\d+)$/ do |post_text, position| + frame_numbers_content(position).find(".text-content").text.should == post_text +end + +When /^I click the "([^"]*)" stream frame$/ do |post_text| + within "#stream-content" do + find_frame_by_text(post_text).find(".content").click + end +end + +Then /^"([^"]*)" should be a comment for "([^"]*)"$/ do |comment_text, post_text| + post = find_frame_by_text(post_text) + post.find(".comment:contains('#{comment_text}')").should be_present +end + +When /^I click into the "([^"]*)" stream frame$/ do |post_text| + find("#stream-content .content:contains('#{post_text}') .permalink").click + #within "#stream-content" do + # post = find_frame_by_text(post_text) + # link = post.find(".permalink") + # link.click + #end +end \ No newline at end of file diff --git a/features/step_definitions/new_hotness/new_user_steps.rb b/features/step_definitions/new_hotness/new_user_steps.rb new file mode 100644 index 000000000..7f76aa06a --- /dev/null +++ b/features/step_definitions/new_hotness/new_user_steps.rb @@ -0,0 +1,19 @@ +def create_beta_user(opts) + user = create_user(opts) + Role.add_beta(user.person) + user +end + +Given /^I am logged in as a beta user with email "(.*?)"$/ do |email| + @me = create_beta_user(:email => email, :password => 'password', :password_confirmation => 'password') + visit login_page + login_as(@me.username, 'password') +end + +Given /^a beta user "(.*?)"$/ do |email| + create_beta_user(:email => email) +end + +When /^"([^"]*)" is an admin$/ do |email| + Role.add_admin(User.find_by_email(email).person) +end \ No newline at end of file diff --git a/features/step_definitions/trumpeter_steps.rb b/features/step_definitions/new_hotness/trumpeter_steps.rb similarity index 95% rename from features/step_definitions/trumpeter_steps.rb rename to features/step_definitions/new_hotness/trumpeter_steps.rb index faee9b83c..dcf3f7f8d 100644 --- a/features/step_definitions/trumpeter_steps.rb +++ b/features/step_definitions/new_hotness/trumpeter_steps.rb @@ -96,7 +96,14 @@ Then /^"([^"]*)" should have the "([^"]*)" picture$/ do |post_text, file_name| end end -When /^I go through the default composer$/ do +When /^I make a new publisher post "([^"]*)"$/ do |post_text| + visit new_post_path + fill_in 'text', :with => post_text + go_to_framer + finalize_frame +end + +When /^I go through the default framer$/ do go_to_framer finalize_frame end diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index ee7e2854f..a89a21f72 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -32,6 +32,7 @@ Given /^"([^"]*)" has a non public post with text "([^"]*)"$/ do |email, text| user.post(:status_message, :text => text, :public => false, :to => user.aspects) end + When /^The user deletes their first post$/ do @me.posts.first.destroy end diff --git a/features/step_definitions/session_steps.rb b/features/step_definitions/session_steps.rb index 7a5ebb876..81ee12755 100644 --- a/features/step_definitions/session_steps.rb +++ b/features/step_definitions/session_steps.rb @@ -6,7 +6,7 @@ end When /^I try to sign in$/ do @me ||= Factory(:user_with_aspect, :getting_started => false) page.driver.visit(new_integration_sessions_path(:user_id => @me.id)) - step %(I press "Login") + click_button "Login" # To save time as compared to: #step %(I go to the new user session page) #step %(I fill in "Username" with "#{@me.username}") diff --git a/features/support/paths.rb b/features/support/paths.rb index 9f0ad1b56..4320fb2eb 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -29,6 +29,8 @@ module NavigationHelpers edit_user_path when /^my new profile page$/ person_path(@me.person, :ex => true) + when /^the new stream$/ + stream_path(:ex => true) when /^"(\/.*)"/ $1 else diff --git a/features/support/publishing_cuke_helpers.rb b/features/support/publishing_cuke_helpers.rb index 300f4dcad..94e464c64 100644 --- a/features/support/publishing_cuke_helpers.rb +++ b/features/support/publishing_cuke_helpers.rb @@ -37,6 +37,14 @@ module PublishingCukeHelpers stream_element_numbers_content(1).text() end + def frame_numbers_content(position) + find(".canvas-frame:nth-child(#{position}) .content") + end + + def find_frame_by_text(text) + find(".canvas-frame:contains('#{text}')") + end + def stream_element_numbers_content(position) find(".stream_element:nth-child(#{position}) .post-content") end diff --git a/spec/javascripts/app/views/canvas_frame_spec.js b/spec/javascripts/app/views/post/canvas_frame_spec.js similarity index 88% rename from spec/javascripts/app/views/canvas_frame_spec.js rename to spec/javascripts/app/views/post/canvas_frame_spec.js index 7cbfe0d87..440bd5be7 100644 --- a/spec/javascripts/app/views/canvas_frame_spec.js +++ b/spec/javascripts/app/views/post/canvas_frame_spec.js @@ -1,4 +1,4 @@ -describe("app.views.CanvasFrame", function(){ +describe("app.views.Post.CanvasFrame", function(){ beforeEach(function(){ this.model = factory.post({ photos : [ @@ -13,7 +13,7 @@ describe("app.views.CanvasFrame", function(){ ] }) - this.view = new app.views.CanvasFrame({model : this.model}) + this.view = new app.views.Post.CanvasFrame({model : this.model}) }) context("images", function() { diff --git a/spec/javascripts/app/views/small_frame_view_spec.js b/spec/javascripts/app/views/post/small_frame_view_spec.js similarity index 91% rename from spec/javascripts/app/views/small_frame_view_spec.js rename to spec/javascripts/app/views/post/small_frame_view_spec.js index 1ff85c565..d6b83e36d 100644 --- a/spec/javascripts/app/views/small_frame_view_spec.js +++ b/spec/javascripts/app/views/post/small_frame_view_spec.js @@ -1,4 +1,4 @@ -describe("app.views.SmallFrame", function(){ +describe("app.views.Post.SmallFrame", function(){ beforeEach(function(){ this.model = factory.post({ photos : [ @@ -19,7 +19,7 @@ describe("app.views.SmallFrame", function(){ } }) - this.view = new app.views.SmallFrame({model : this.model}) + this.view = new app.views.Post.SmallFrame({model : this.model}) }) it("passes the model down to the oembed view", function(){