Skip to content

Commit

Permalink
Add a skeleton viewer for the new designs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jan 31, 2025
1 parent 87e41e4 commit e445728
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/was_seed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* TODO add styles */
7 changes: 7 additions & 0 deletions app/components/was_seed_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= render ::CompanionWindowsComponent.new(viewer:, stimulus_controller: 'file-auth fullscreen') do |component| %>
<% component.with_body do %>
<div class="sul-embed-body" style="width: 100%">
<%= render ::ContentNotAvailableComponent.new %>
</div>
<% end %>
<% end %>
14 changes: 14 additions & 0 deletions app/components/was_seed_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Embed
class WasSeedComponent < ViewComponent::Base
def initialize(viewer:)
@viewer = viewer
end

attr_reader :viewer

delegate :purl_object, to: :viewer
delegate :druid, to: :purl_object
end
end
1 change: 1 addition & 0 deletions app/javascript/webarchive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: Add code here
2 changes: 2 additions & 0 deletions app/viewers/embed/viewer/common_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CommonViewer

attr_reader :purl_object, :embed_request

delegate :new_viewer?, to: :embed_request

def initialize(embed_request)
@embed_request = embed_request
@purl_object = embed_request.purl_object
Expand Down
6 changes: 3 additions & 3 deletions app/viewers/embed/viewer/was_seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class WasSeed < CommonViewer
delegate :druid, to: :@purl_object

def component
Legacy::WasSeedComponent
new_viewer? ? WasSeedComponent : Legacy::WasSeedComponent
end

def importmap
'legacy_webarchive'
new_viewer? ? 'webarchive' : 'legacy_webarchive'
end

def stylesheet
'legacy_was_seed.css'
new_viewer? ? 'was_seed.css' : 'legacy_was_seed.css'
end

def capture_list
Expand Down
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pin "media", preload: true
pin "legacy_webarchive", preload: true
pin "webarchive", preload: true
pin "legacy_file", preload: true
pin "document", preload: true
pin "legacy_3d", preload: true
Expand Down
5 changes: 5 additions & 0 deletions lib/embed/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def hide_search?
params[:hide_search] == 'true'
end

# This is a temporary method that allows us to test new viewers before making them the default
def new_viewer?
params[:new_viewer] == 'true'
end

def min_files_to_search
params[:min_files_to_search]
end
Expand Down
36 changes: 36 additions & 0 deletions spec/components/was_seed_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Embed::PdfComponent, type: :component do
include PurlFixtures

let(:url) { 'https://purl.stanford.edu/sq929fn8035' }
let(:embed_request) { Embed::Request.new(url:) }
let(:viewer) { Embed::ViewerFactory.new(embed_request).viewer }

before do
stub_request(:get, 'https://purl.stanford.edu/sq929fn8035.json')
.to_return(status: 200, body: pdf_public_json, headers: {})
end

it 'renders the full screen button by default' do
rendered_ng_doc_fragment = render_inline(described_class.new(viewer:))
expect(rendered_ng_doc_fragment.xpath('.//button[@id="full-screen-button" and @aria-label="Full screen"]').count).to eq(1)
end

context 'when the browser is chromium based' do
let(:companion_windows_component) { CompanionWindowsComponent.new(viewer:, stimulus_controller: 'file-auth') }

before do
allow(CompanionWindowsComponent).to receive(:new).with(viewer:, stimulus_controller: 'file-auth fullscreen').and_return(companion_windows_component)
allow(companion_windows_component).to receive(:requested_by_chromium?).and_return(true)
end

it 'does not render the full screen button' do
rendered_ng_doc_fragment = render_inline(described_class.new(viewer:))
expect(rendered_ng_doc_fragment.xpath('.//button[@id="full-screen-button"]').count).to eq(0)
expect(rendered_ng_doc_fragment.xpath('.//button[@aria-label="Full screen"]').count).to eq(0)
end
end
end

0 comments on commit e445728

Please sign in to comment.