From 1b4567648fe0c35212fda36a8b499d834fa20dc4 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Mon, 23 Jan 2017 11:40:34 -0600 Subject: [PATCH] Display edit button when checking boxes on shared works tab Patched in the code that Scholarsphere was using on its sort_and_per_page partial Fixes #2419 --- .../javascripts/sufia/dashboard_actions.js | 2 +- app/views/my/_sort_and_per_page.html.erb | 16 ++++----- .../my/_sort_and_per_page.html.erb_spec.rb | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 spec/views/my/_sort_and_per_page.html.erb_spec.rb diff --git a/app/assets/javascripts/sufia/dashboard_actions.js b/app/assets/javascripts/sufia/dashboard_actions.js index 7b19cd9b6a..9e3882c670 100644 --- a/app/assets/javascripts/sufia/dashboard_actions.js +++ b/app/assets/javascripts/sufia/dashboard_actions.js @@ -18,7 +18,7 @@ Blacklight.onLoad(function() { } } - // show/hide more information on the dashboard when clicking + // show/hide more information on the dashboard when clicking // plus/minus $('.glyphicon-chevron-right').on('click', function() { show_details(this); diff --git a/app/views/my/_sort_and_per_page.html.erb b/app/views/my/_sort_and_per_page.html.erb index d0b91379c3..7a850d0936 100644 --- a/app/views/my/_sort_and_per_page.html.erb +++ b/app/views/my/_sort_and_per_page.html.erb @@ -3,17 +3,17 @@ <%= render 'collections/form_for_select_collection', user_collections: @user_collections %> - <% if on_my_works? %> -
- <% session[:batch_edit_state] = "on" %> -
- <%= batch_edit_continue "Edit Selected" %> -
+
+ <% session[:batch_edit_state] = "on" %> +
+ <%= batch_edit_continue "Edit Selected" %> +
+ <% if on_my_works? %> <%= batch_delete %> <%= button_tag "Add to Collection", class: 'btn btn-primary submits-batches submits-batches-add', data: { toggle: "modal", target: "#collection-list-container" } %> -
- <% end %> + <% end %> +
<% if @response.response['numFound'] > 1 && !sort_fields.empty? %> diff --git a/spec/views/my/_sort_and_per_page.html.erb_spec.rb b/spec/views/my/_sort_and_per_page.html.erb_spec.rb new file mode 100644 index 0000000000..d861c164f5 --- /dev/null +++ b/spec/views/my/_sort_and_per_page.html.erb_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +RSpec.describe 'my/_sort_and_per_page.html.erb', type: :view do + let(:mock_response) { double(response: { 'numFound' => 7 }) } + let(:sort_fields) { double(empty?: true) } + + before do + @response = mock_response + allow(view).to receive(:sort_fields).and_return(sort_fields) + end + + context "on my works page" do + before do + allow(view).to receive(:on_my_works?).and_return(true) + render + end + it "has buttons" do + expect(rendered).to have_selector('button', text: 'Add to Collection') + expect(rendered).to have_selector('input[value="Edit Selected"]') + end + end + + context "not on my works page (i.e. Works shared with me)" do + before do + allow(view).to receive(:on_my_works?).and_return(false) + render + end + it "has buttons" do + expect(rendered).not_to have_selector('button', text: 'Add to Collection') + expect(rendered).to have_selector('input[value="Edit Selected"]') + end + end +end