-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert downlaod collapse to a view component with a spec
- Loading branch information
Showing
5 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/components/catalog/downloads_collapse_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<%# Renders the options of the downloads dropdown button %> | ||
|
||
<% if @document.multi_direct_downloads.present? %> | ||
<% @document.multi_direct_downloads.each do |download| %> | ||
<%= download_link_file(download[0], @document.id, download[1]) %> | ||
<% end %> | ||
<% end %> | ||
<% if @document.direct_download.present? %> | ||
<% if @document.direct_download[:download].is_a? Array %> | ||
<% @document.direct_download[:download].each do |download| %> | ||
<%= download_link_file(download['label'], @document.id, download['url']) %> | ||
<% end %> | ||
<% end %> | ||
<% if @document.direct_download[:download].is_a? String %> | ||
<%= download_link_file(download_text(@document.file_format), @document.id, @document.direct_download[:download], @document.restricted? ? "_blank" : nil) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if @document.hgl_download.present? %> | ||
<%= download_link_hgl(download_text(@document.download_types.first[0]), @document) %> | ||
<% end %> | ||
|
||
<% if @document.iiif_download.present? %> | ||
<%= download_link_iiif %> | ||
<% end %> | ||
|
||
<% if @document.download_types.present? %> | ||
<% @document.download_types.each do |type| %> | ||
<% next if type.first == :kmz %> | ||
<%= download_link_generated(type.first, @document) %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Catalog | ||
class DownloadsCollapseComponent < ViewComponent::Base | ||
def initialize(document:) | ||
@document = document | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
spec/components/catalog/downloads_collapse_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Catalog::DownloadsCollapseComponent, type: :component do | ||
let(:document) { instance_double(SolrDocument, id: 123) } | ||
|
||
before do | ||
allow(document).to receive_messages( | ||
multi_direct_downloads: [], | ||
file_format: 'Shapefile', | ||
direct_download: { download: 'https://example.com/download' }, | ||
restricted?: restricted, | ||
hgl_download: false, | ||
iiif_download: false, | ||
download_types: [] | ||
) | ||
end | ||
|
||
context 'when the download is restricted' do | ||
let(:restricted) { true } | ||
|
||
it 'renders restricted links with a target of _blank' do | ||
render_inline(described_class.new(document:)) | ||
|
||
expect(page).to have_link('Original Shapefile', href: 'https://example.com/download', target: '_blank') | ||
end | ||
end | ||
|
||
context 'when the download is not restricted' do | ||
let(:restricted) { false } | ||
|
||
it 'renders the download link with no target' do | ||
render_inline(described_class.new(document:)) | ||
|
||
expect(page).to have_link('Original Shapefile', href: 'https://example.com/download', target: nil) | ||
end | ||
end | ||
end |