Skip to content

Commit

Permalink
add spec for rights_statement_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs authored and adam malantonio committed Feb 4, 2019
1 parent 97fd50e commit b224da3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/rights_statement_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module RightsStatementHelper
# @param uri [String] uri of the rights statement
# @param label [String] label for the statement
# @return [String]
def rights_statement_icon(uri, label)
def rights_statement_icon(uri, label = '')
label = uri if label.blank?
image_path = rs_icon_path_for(uri)
link_content =
Expand Down
58 changes: 58 additions & 0 deletions spec/helpers/rights_statement_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true
RSpec.describe RightsStatementHelper do
describe '#rights_statement_icon_path_for' do
subject(:node) { Capybara::Node::Simple.new(icon) }

let(:rights_service) { Hyrax.config.rights_statement_service_class.new }
let(:icon) { helper.rights_statement_icon(uri, label) }

shared_examples 'an icon link for the rights_statement' do
let(:image) { helper.image_path("rights-icons/#{key}.svg") }

it { is_expected.to have_css 'a img' }
it { is_expected.to have_link(nil, href: uri) }

it "uses the label as the image's alt-text" do
expect(node.find('img')['alt']).to eq label
end

it 'opens the link in a new window' do
expect(node.find('a')['target']).to eq '_blank'
end
end

{
'http://creativecommons.org/licenses/by/3.0/us/' => 'cc-by',
'http://creativecommons.org/licenses/by-sa/3.0/us/' => 'cc-by-sa',
'http://creativecommons.org/licenses/by-nc/3.0/us/' => 'cc-by-nc',
'http://creativecommons.org/licenses/by-nd/3.0/us/' => 'cc-by-nd',
'http://creativecommons.org/licenses/by-nc-nd/3.0/us/' => 'cc-by-nc-nd',
'http://creativecommons.org/licenses/by-nc-sa/3.0/us/' => 'cc-by-nc-sa',
'http://rightsstatements.org/vocab/InC-NC/1.0/' => 'rs-inc-nc',
'http://rightsstatements.org/vocab/InC-RUU/1.0/' => 'rs-inc-ruu',
'http://rightsstatements.org/vocab/NoC-CR/1.0/' => 'rs-noc-cr',
'http://rightsstatements.org/vocab/NoC-US/1.0/' => 'rs-noc-us',
'http://rightsstatements.org/vocab/UND/1.0/' => 'rs-und',
'http://rightsstatements.org/vocab/NKC/1.0/' => 'rs-nkc',
'http://creativecommons.org/publicdomain/zero/1.0/' => 'pd-zero',
'http://creativecommons.org/publicdomain/mark/1.0/' => 'pd-mark'
}.each_pair do |license, svg_key|
context license do
let(:uri) { license }
let(:label) { rights_service.label(uri) }
let(:key) { svg_key }

it_behaves_like 'an icon link for the rights_statement'
end
end

context 'when a URI is not expected' do
let(:uri) { 'http://lafayette.edu' }
let(:label) { nil }

it { is_expected.not_to have_css 'a img' }
it { is_expected.to have_css 'a span.fa.fa-external-link' }
it { is_expected.to have_link(uri, href: uri) }
end
end
end

0 comments on commit b224da3

Please sign in to comment.