Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions app/components/arclight/breadcrumb_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ def initialize(document:, count: nil, offset: 0)
end

def call
breadcrumb_links = components.drop(@offset)
return unless breadcrumb_links.any?

if @count && breadcrumb_links.length > @count
breadcrumb_links = breadcrumb_links.first(@count)
breadcrumb_links << tag.li('&hellip;'.html_safe, class: 'breadcrumb-item')
end
tag.ol class: 'breadcrumb' do
safe_join(breadcrumb_links)
end
Expand All @@ -36,5 +32,19 @@ def components
def build_repository_link
render Arclight::RepositoryBreadcrumbComponent.new(document: @document)
end

private

def breadcrumb_links
@breadcrumb_links ||= limit_breadcrumb_links(components.drop(@offset))
end

def limit_breadcrumb_links(links)
return links unless @count && links.length > @count

limited_links = links.first(@count)
limited_links << tag.li('&hellip;'.html_safe, class: 'breadcrumb-item')
limited_links
end
end
end
8 changes: 8 additions & 0 deletions spec/components/arclight/breadcrumb_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
end
end

context 'with an offset that removes all links' do
let(:attr) { { offset: 4 } }

it 'does not render an empty ordered list' do
expect(rendered).to have_no_selector 'ol'
end
end

it 'renders breadcrumb links' do
expect(rendered).to have_css 'li', text: 'my repository'
expect(rendered).to have_link 'DEF', href: '/catalog/abc123_def'
Expand Down