Skip to content

Commit

Permalink
Merge pull request #1611 from samvera/fix_feature_tests
Browse files Browse the repository at this point in the history
Fix failing feature and veiw tests caused by capybara-maleficent update to 2.0
  • Loading branch information
elrayle authored Sep 1, 2017
2 parents dfc41db + f650377 commit 1186361
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 159 deletions.
16 changes: 1 addition & 15 deletions app/views/hyrax/dashboard/collections/_collection_title.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@
<%= presenter.permission_badge %>
<%= presenter.collection_type_badge %>

<span class="sr-only h2"><%= t('hyrax.collection.actions.header') %></span>
<% if can? :destroy, presenter.solr_document %>
<%= link_to t('hyrax.collection.actions.delete.label'),
dashboard_collection_path(presenter),
title: t('hyrax.collection.actions.delete.desc'),
class: 'btn btn-danger pull-right',
data: { confirm: t('hyrax.collection.actions.delete.confirmation'),
method: :delete } %>
<% end %>
<% if can? :edit, presenter.solr_document %>
<%= link_to t('hyrax.collection.actions.edit.label'),
edit_dashboard_collection_path(presenter),
title: t('hyrax.collection.actions.edit.desc'),
class: 'btn btn-default pull-right' %>
<% end %>
<%= render 'show_actions', presenter: presenter %>
<% else %>
<span class="h2"><%= title %></span>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<%= render_visibility_link(collection_presenter.solr_document) %>
</td>
<td class="text-center">
<%= render 'collection_action_menu', id: id %>
<%= render '/hyrax/my/collection_action_menu', id: id %>
</td>
</tr>
<tr id="detail_<%= id %>"> <!-- collection detail"> -->
Expand Down
43 changes: 15 additions & 28 deletions app/views/hyrax/dashboard/collections/_show_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
<h2 class="sr-only"><%= t('hyrax.collection.actions.header') %></h2>
<div class="actions-controls-collections">
<% if can? :edit, presenter.solr_document %>
<%= link_to t('hyrax.collection.actions.edit.label'),
edit_dashboard_collection_path(presenter),
title: t('hyrax.collection.actions.edit.desc'),
class: 'btn btn-default' %>
<%= link_to t('hyrax.collection.actions.add_works.label'),
hyrax.my_works_path(add_works_to_collection: presenter.id),
title: t('hyrax.collection.actions.add_works.desc'),
class: 'btn btn-default' %>
<% if presenter.collection_type_is_nestable? %>
<%= link_to t('hyrax.collection.actions.nest_collections.label'),
hyrax.dashboard_new_nest_collection_within_path(child_id: presenter.id),
title: t('hyrax.collection.actions.nest_collections.desc'),
class: 'btn btn-default' %>
<% end %>
<%end %>

<% if can? :destroy, presenter.solr_document %>
<%= link_to t('hyrax.collection.actions.delete.label'),
collection_path(presenter),
title: t('hyrax.collection.actions.delete.desc'),
class: 'btn btn-danger',
data: { confirm: t('hyrax.collection.actions.delete.confirmation'),
method: :delete } %>
<% end %>
</div>
<span class="sr-only h2"><%= t('hyrax.collection.actions.header') %></span>
<% if can? :destroy, presenter.solr_document %>
<%= link_to t('hyrax.collection.actions.delete.label'),
hyrax.dashboard_collection_path(presenter),
title: t('hyrax.collection.actions.delete.desc'),
class: 'btn btn-danger pull-right',
data: { confirm: t('hyrax.collection.actions.delete.confirmation'),
method: :delete } %>
<% end %>
<% if can? :edit, presenter.solr_document %>
<%= link_to t('hyrax.collection.actions.edit.label'),
hyrax.edit_dashboard_collection_path(presenter),
title: t('hyrax.collection.actions.edit.desc'),
class: 'btn btn-default pull-right' %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2 class="sr-only"><%= t('hyrax.collection.actions.header') %></h2>
<div class="actions-controls-collections">
<% if can? :edit, presenter.solr_document # TODO: Shouldn't this be :deposit -- dependency on participants %>
<%= link_to t('hyrax.collection.actions.add_works.label'),
hyrax.my_works_path(add_works_to_collection: presenter.id),
title: t('hyrax.collection.actions.add_works.desc'),
class: 'btn btn-default pull-right' %>
<% if presenter.collection_type_is_nestable? %>
<%= link_to t('hyrax.collection.actions.nest_collections.label'),
hyrax.dashboard_new_nest_collection_within_path(child_id: presenter.id),
title: t('hyrax.collection.actions.nest_collections.desc'),
class: 'btn btn-default' %>
<% end %>
<% end %>
</div>
7 changes: 2 additions & 5 deletions app/views/hyrax/dashboard/collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@
<% else %>
<%= t('.item_count') %> (<%= @presenter.total_items %>)
<% end %>
<%= link_to t('hyrax.collection.actions.add_works.label'),
hyrax.my_works_path(add_works_to_collection: @presenter.id),
title: t('hyrax.collection.actions.add_works.desc'),
class: 'btn btn-default pull-right' %>
</h2>
<%= render 'show_add_items_actions', presenter: @presenter %>
</div>
</div>

<div class="col-xs-6 col-md-5 col-lg-6 pull-right">
Expand Down
149 changes: 89 additions & 60 deletions spec/features/dashboard/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
describe 'Your Collections tab' do
context 'when non-admin user' do
before do
user
admin_user
collection1
collection2
collection3
sign_in user
visit '/dashboard/my/collections'
end
Expand All @@ -24,14 +29,19 @@
end

it "lists only user's collections" do
expect(page).to have_link(collection1.title)
expect(page).to have_link(collection2.title)
expect(page).not_to have_link(collection3.title)
expect(page).to have_link(collection1.title.first)
expect(page).to have_link(collection2.title.first)
expect(page).not_to have_link(collection3.title.first)
end
end

context 'when admin user' do
before do
user
admin_user
collection1
collection2
collection3
sign_in admin_user
visit '/dashboard/my/collections'
end
Expand All @@ -46,25 +56,30 @@
end

it "lists only admin_user's collections" do
expect(page).not_to have_link(collection1.title)
expect(page).not_to have_link(collection2.title)
expect(page).to have_link(collection3.title)
expect(page).not_to have_link(collection1.title.first)
expect(page).not_to have_link(collection2.title.first)
expect(page).to have_link(collection3.title.first)
end
end
end

describe 'All Collections tab (for admin users only)' do
before do
user
admin_user
collection1
collection2
collection3
sign_in admin_user
visit '/dashboard/my/collections'
end

it 'lists all collections for all users' do
expect(page).to have_link 'All Collection'
click_link 'All Collections'
expect(page).to have_link(collection1.title)
expect(page).to have_link(collection2.title)
expect(page).to have_link(collection3.title)
expect(page).to have_link(collection1.title.first)
expect(page).to have_link(collection2.title.first)
expect(page).to have_link(collection3.title.first)
end
end

Expand Down Expand Up @@ -255,69 +270,83 @@
let!(:work1) { create(:work, title: ["King Louie"], member_of_collections: [collection], user: user) }
let!(:work2) { create(:work, title: ["King Kong"], member_of_collections: [collection], user: user) }

before do
sign_in user
visit '/dashboard/my/collections'
end

it "edits and update collection metadata" do
# URL: /dashboard/collections
expect(page).to have_content(collection.title.first)
within("#document_#{collection.id}") do
find('button.dropdown-toggle').click
click_link('Edit Collection')
context 'from dashboard -> collections action menu' do
before do
sign_in user
visit '/dashboard/my/collections'
end
# URL: /dashboard/collections/collection-id/edit
expect(page).to have_field('collection_title', with: collection.title.first)
expect(page).to have_field('collection_description', with: collection.description.first)
expect(page).to have_content(work1.title.first)
expect(page).to have_content(work2.title.first)

new_title = "Altered Title"
new_description = "Completely new Description text."
creators = ["Dorje Trollo", "Vajrayogini"]
fill_in('Title', with: new_title)
fill_in('Abstract or Summary', with: new_description)
fill_in('Creator', with: creators.first)
within('.panel-footer') do
click_button('Update Collection')
it "edits and update collection metadata" do
# URL: /dashboard/collections
expect(page).to have_content(collection.title.first)
within("#document_#{collection.id}") do
find('button.dropdown-toggle').click
click_link('Edit Collection')
end
# URL: /dashboard/collections/collection-id/edit
expect(page).to have_field('collection_title', with: collection.title.first)
expect(page).to have_field('collection_description', with: collection.description.first)
expect(page).to have_content(work1.title.first)
expect(page).to have_content(work2.title.first)

new_title = "Altered Title"
new_description = "Completely new Description text."
creators = ["Dorje Trollo", "Vajrayogini"]
fill_in('Title', with: new_title)
fill_in('Abstract or Summary', with: new_description)
fill_in('Creator', with: creators.first)
within('.panel-footer') do
click_button('Update Collection')
end
# URL: /dashboard/collections/collection-id
header = find('header')
expect(header).not_to have_content(collection.title.first)
expect(header).not_to have_content(collection.description.first)
expect(header).to have_content(new_title)
expect(page).to have_content(new_description)
expect(page).to have_content(creators.first)
end
# URL: /dashboard/collections/collection-id
header = find('header')
expect(header).not_to have_content(collection.title.first)
expect(header).not_to have_content(collection.description.first)
expect(header).to have_content(new_title)
expect(page).to have_content(new_description)
expect(page).to have_content(creators.first)
end

context 'with discoverable set' do
let(:discoverable_collection_id) { create(:collection, user: user, collection_type_settings: [:discoverable]).id }
let(:not_discoverable_collection_id) { create(:collection, user: user, collection_type_settings: [:not_discoverable]).id }

it 'to true, it shows Discovery tab' do
visit "/dashboard/collections/#{discoverable_collection_id}"
expect(page).to have_link('Discovery', href: '#discovery')
context "tabs" do
before do
sign_in user
end

it 'to false, it hides Discovery tab' do
visit "/dashboard/collections/#{not_discoverable_collection_id}"
expect(page).not_to have_link('Discovery', href: '#discovery')
xit 'always includes branding' do # TODO: Pending PR for branding
visit "/dashboard/collections/#{collection.id}/edit"
expect(page).to have_content('Edit Collection')
expect(page).to have_link('Branding', href: '#branding')
end
end

context 'with sharable set' do
let(:sharable_collection_id) { create(:collection, user: user, collection_type_settings: [:sharable]).id }
let(:not_sharable_collection_id) { create(:collection, user: user, collection_type_settings: [:not_sharable]).id }
context 'with discoverable set' do
let(:discoverable_collection_id) { create(:collection, user: user, collection_type_settings: [:discoverable]).id }
let(:not_discoverable_collection_id) { create(:collection, user: user, collection_type_settings: [:not_discoverable]).id }

it 'to true, it shows Discovery tab' do
visit "/dashboard/collections/#{discoverable_collection_id}/edit"
expect(page).to have_link('Discovery', href: '#discovery')
end

it 'to true, it shows Sharable tab' do
visit "/dashboard/collections/#{sharable_collection_id}"
expect(page).to have_link('Sharable', href: '#sharable')
it 'to false, it hides Discovery tab' do
visit "/dashboard/collections/#{not_discoverable_collection_id}/edit"
expect(page).not_to have_link('Discovery', href: '#discovery')
end
end

it 'to false, it hides Sharable tab' do
visit "/dashboard/collections/#{not_sharable_collection_id}"
expect(page).not_to have_link('Sharable', href: '#sharable')
context 'with sharable set' do
let(:sharable_collection_id) { create(:collection, user: user, collection_type_settings: [:sharable]).id }
let(:not_sharable_collection_id) { create(:collection, user: user, collection_type_settings: [:not_sharable]).id }

it 'to true, it shows Sharable tab' do
visit "/dashboard/collections/#{sharable_collection_id}/edit"
expect(page).to have_link('Sharing', href: '#sharing')
end

it 'to false, it hides Sharable tab' do
visit "/dashboard/collections/#{not_sharable_collection_id}/edit"
expect(page).not_to have_link('Sharing', href: '#sharing')
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
expect(rendered).to have_content '4 collection types in this repository'
end

it 'has edit buttons for all' do
expect(rendered).to have_button('Edit', count: 4)
it 'has edit buttons for custom and predefined collection types' do
expect(rendered).to have_link('Edit', count: 4)
end

it 'has delete buttons for non-special collection types' do
expect(rendered).to have_button('Delete', count: 2)
it 'has delete buttons for custom collection types' do
# 2 delete buttons for the custom collection types and 1 for the delete modal
expect(rendered).to have_button('Delete', count: 3)
end
end
Loading

0 comments on commit 1186361

Please sign in to comment.