Skip to content

Commit

Permalink
Show page should link directly to aeon when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
sandbergja committed May 12, 2023
1 parent ceecb00 commit a78ac70
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
21 changes: 21 additions & 0 deletions app/components/aeon_request_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

# ViewComponent that displays an aeon request button on the show page
class AeonRequestButtonComponent < RequestButtonComponent
def initialize(document:, location:)
@document = document
@location = location
end

def label
'Reading Room Request'
end

def tooltip
'Request to view in Reading Room'
end

def url
Requests::AeonUrl.new(document: @document).to_s
end
end
4 changes: 2 additions & 2 deletions app/services/physical_holdings_markup_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ def request_placeholder(adapter, holding_id, location_rules, holding)
link = if !location_rules.nil? && /^scsb.+/ =~ location_rules['code']
if scsb_supervised_items?(holding)
# All SCSB supervised items go through Aeon
RequestButtonComponent.new(doc_id:, location: location_rules, force_aeon: true).render_in(view_base)
AeonRequestButtonComponent.new(document: adapter.document, location: location_rules).render_in(view_base)
else
RequestButtonComponent.new(doc_id:, location: location_rules).render_in(view_base)
end
elsif !adapter.alma_holding?(holding_id)
RequestButtonComponent.new(doc_id:, location: location_rules, holding_id:, force_aeon: true).render_in(view_base)
AeonRequestButtonComponent.new(document: adapter.document, location: location_rules).render_in(view_base)
elsif self.class.temporary_holding_id?(holding_id)
holding_identifier = self.class.temporary_location_holding_id_first(holding)
RequestButtonComponent.new(doc_id:, holding_id: holding_identifier, location: location_rules).render_in(view_base)
Expand Down
31 changes: 31 additions & 0 deletions spec/components/aeon_request_button_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AeonRequestButtonComponent, type: :component do
before do
stub_holding_locations
end
let(:holding) do
{ "22740186070006421" => { "items" => [{ "holding_id" => "22740186070006421", "id" => "23740186060006421", "barcode" => "24680" }] } }
end
let(:location) do
{ aeon_location: false, 'library' => { 'code' => 'eastasian' } }
end
let(:document) do
SolrDocument.new({ id: '1234', holdings_1display: holding.to_json.to_s })
end
subject { render_inline(described_class.new(document:, location:)) }
it "renders a link with the appropriate classes" do
expect(subject.css('a').attribute('class').to_s).to eq('request btn btn-xs btn-primary')
end
it 'renders the typical title tooltip' do
expect(subject.css('a').attribute('title').text).to eq('Request to view in Reading Room')
end
it 'renders the typical request text' do
expect(subject.css('a').text).to eq('Reading Room Request')
end
it 'includes aeon=false in the link url' do
expect(subject.css('a').attribute('href').text).to include('https://lib-aeon.princeton.edu/aeon/aeon.dll/OpenURL?')
end
end
4 changes: 2 additions & 2 deletions spec/features/login_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

it 'does not require authentication', js: true do
visit "/catalog/coin-1167"
expect(page).to have_link('Reading Room Request', href: '/requests/coin-1167?aeon=true&mfhd=numismatics')
expect(page).to have_link('Reading Room Request', href: Regexp.new('https://lib-aeon\.princeton\.edu/aeon/aeon\.dll/OpenURL.*Coin.1167'))
click_link('Reading Room Request')
expect(page.current_url).to include(Requests::Config[:aeon_base])
end
Expand All @@ -167,7 +167,7 @@
end
it 'does not require authentication', js: true do
visit "/catalog/dsp01tq57ns24j"
expect(page).to have_link('Reading Room Request', href: '/requests/dsp01tq57ns24j?aeon=true&mfhd=thesis')
expect(page).to have_link('Reading Room Request', href: Regexp.new('https://lib-aeon\.princeton\.edu/aeon/aeon\.dll/OpenURL.*dsp01tq57ns24j'))
click_link('Reading Room Request')
expect(page.current_url).to include(Requests::Config[:aeon_base])
end
Expand Down
16 changes: 12 additions & 4 deletions spec/services/physical_holdings_markup_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@

before do
allow(adapter).to receive(:alma_holding?).and_return(false)
allow_any_instance_of(SolrDocument).to receive(:to_ctx).and_return(OpenURL::ContextObject.new)
allow(document).to receive(:[]).and_return('data')
allow(document).to receive(:to_ctx).and_return(OpenURL::ContextObject.new)
allow(document).to receive(:holdings_all_display).and_return({ 'my_id' => holding })
allow(adapter).to receive(:document).and_return(document)
allow(holding).to receive(:dig).and_return("coin-3750")
end
# this should be hitting the third condition, but does not seem to be
it 'generates the request link for the host record' do
Expand All @@ -213,7 +216,8 @@
expect(request_placeholder_markup).to include 'data-holding-id="numismatics"'
expect(request_placeholder_markup).to include '<a '
expect(request_placeholder_markup).to include 'title="Request to view in Reading Room"'
expect(request_placeholder_markup).to include 'href="/requests/coin-3750?aeon=true&amp;mfhd=numismatics"'
expect(request_placeholder_markup).to include 'href="https://lib-aeon.princeton.edu/aeon/aeon.dll/OpenURL'
expect(request_placeholder_markup).to include 'Coin+3750'
end
end

Expand Down Expand Up @@ -265,6 +269,10 @@
end

before do
allow_any_instance_of(SolrDocument).to receive(:to_ctx).and_return(OpenURL::ContextObject.new)
allow(document).to receive(:[]).and_return('data')
allow(document).to receive(:to_ctx).and_return(OpenURL::ContextObject.new)
allow(document).to receive(:holdings_all_display).and_return({ 'my_id' => holding })
allow(adapter).to receive(:document).and_return(document)
allow(holding).to receive(:dig).and_return("SCSB-6593031")
end
Expand All @@ -278,8 +286,8 @@
expect(request_placeholder_markup).to include 'title="Request to view in Reading Room"'
# The general scsbnypl location is *not* an aeon location, but if the holding use_statement is "Supervised Use",
# it goes through aeon.
expect(request_placeholder_markup).to include 'data-aeon="false"'
expect(request_placeholder_markup).to include 'href="/requests/SCSB-6593031?aeon=true"'
expect(request_placeholder_markup).to include 'href="https://lib-aeon.princeton.edu/aeon/aeon.dll/OpenURL'
expect(request_placeholder_markup).to include 'ItemNumber=33433115858387'
end
end

Expand Down

0 comments on commit a78ac70

Please sign in to comment.