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 d9bdc47
Show file tree
Hide file tree
Showing 9 changed files with 107 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 %>
12 changes: 12 additions & 0 deletions app/components/was_seed_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

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

attr_reader :viewer

delegate :purl_object, to: :viewer
delegate :druid, to: :purl_object
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
75 changes: 75 additions & 0 deletions spec/components/was_seed_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe WasSeedComponent, type: :component do
include WasTimeMapFixtures

let(:embed_request) do
Embed::Request.new(url: 'http://purl.stanford.edu/abc123', new_viewer: 'true')
end
let(:viewer) { Embed::Viewer::WasSeed.new(embed_request) }
let(:purl) { build(:purl, :was_seed) }

before do
allow(Embed::Purl).to receive(:find).and_return(purl)
end

context 'with current timemap behavior' do
let(:fake_connection) do
instance_double(Faraday::Connection, get: instance_double(Faraday::Response, body: timemap, success?: true))
end

before do
allow_any_instance_of(Embed::WasTimeMap).to receive(:redirectable_connection).and_return(fake_connection)
expect(fake_connection).to receive(:get).once
render_inline(described_class.new(viewer:))
end

it 'displays Was Seed viewer body' do
# visible false because we display:none the container until we've loaded the CSS.
expect(page).to have_css '.sul-embed-was-seed', visible: :all
expect(page).to have_css '.sul-embed-was-seed-list', visible: :all, count: 1
expect(page).to have_css '.sul-embed-was-seed-list-item', visible: :all, count: 7
end

context 'with hidden title' do
let(:embed_request) do
Embed::Request.new(url: 'http://purl.stanford.edu/abc123', hide_title: 'true')
end

it do
expect(page).to have_no_css '.sul-embed-header', visible: :all
end
end
end

context 'with new timemap behavior' do
let(:fake_connection) do
instance_double(Faraday::Connection, get: instance_double(Faraday::Response, body: timemap_new, success?: true))
end

before do
allow_any_instance_of(Embed::WasTimeMap).to receive(:redirectable_connection).and_return(fake_connection)
expect(fake_connection).to receive(:get).once
render_inline(described_class.new(viewer:))
end

it 'displays Was Seed viewer body' do
# visible false because we display:none the container until we've loaded the CSS.
expect(page).to have_css '.sul-embed-was-seed', visible: :all
expect(page).to have_css '.sul-embed-was-seed-list', visible: :all, count: 1
expect(page).to have_css '.sul-embed-was-seed-list-item', visible: :all, count: 7
end

context 'with hidden title' do
let(:embed_request) do
Embed::Request.new(url: 'http://purl.stanford.edu/abc123', hide_title: 'true')
end

it do
expect(page).to have_no_css '.sul-embed-header', visible: :all
end
end
end
end

0 comments on commit d9bdc47

Please sign in to comment.