From e2692ce364ae3daf33300c6646ac7616e09ca111 Mon Sep 17 00:00:00 2001 From: Justin Littman Date: Mon, 29 Jul 2024 16:48:01 -0400 Subject: [PATCH] Change to user version links in version history list. closes #4548 --- .../version_milestones_component.html.erb | 2 +- .../version_milestones_component.rb | 22 ++++++++++++-- .../version_milestones_component_spec.rb | 29 +++++++++++++++---- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/components/version_milestones_component.html.erb b/app/components/version_milestones_component.html.erb index c20a92499..4f2a8f880 100644 --- a/app/components/version_milestones_component.html.erb +++ b/app/components/version_milestones_component.html.erb @@ -1,6 +1,6 @@ - - <%= title %><% if user_version %> (<%= current_version? ? user_version_label : link_to(user_version_label, user_version_path) %>)<% end %> + <%= title %><% if user_version %> (<%= user_version_link_or_label %>)<% end %> diff --git a/app/components/version_milestones_component.rb b/app/components/version_milestones_component.rb index a0b9443cb..84c9bff77 100644 --- a/app/components/version_milestones_component.rb +++ b/app/components/version_milestones_component.rb @@ -15,12 +15,28 @@ def steps @steps ||= milestones_presenter.steps_for(version) end - def current_version? - version.to_i == milestones_presenter.current_version + def link_user_version? + return false if version.to_i == milestones_presenter.current_version.to_i + return false if user_version == user_versions_presenter.user_version.to_i + + true + end + + def link_to_document? + version.to_i == milestones_presenter.current_version.to_i \ + && user_version == user_versions_presenter.head_user_version&.to_i \ + && user_versions_presenter.user_version.present? + end + + def user_version_link_or_label + return link_to(user_version_label, user_version_path) if link_user_version? + return link_to(user_version_label, solr_document_path(milestones_presenter.druid)) if link_to_document? + + user_version_label end def user_version - @user_version ||= user_versions_presenter.user_version_for(version) + @user_version ||= user_versions_presenter.user_version_for(version)&.to_i end def user_version_path diff --git a/spec/components/version_milestones_component_spec.rb b/spec/components/version_milestones_component_spec.rb index 12776940e..7929179a0 100644 --- a/spec/components/version_milestones_component_spec.rb +++ b/spec/components/version_milestones_component_spec.rb @@ -7,8 +7,6 @@ described_class.new(version: 2, milestones_presenter:, user_versions_presenter:) - # title: '2 (2.0.0) Add collection, set rights to citations', - # steps:) end let(:milestones_presenter) do @@ -18,7 +16,7 @@ current_version:, druid: 'druid:mk420bs7601') end - let(:user_versions_presenter) { instance_double(UserVersionsPresenter, user_version_for: user_version) } + let(:user_versions_presenter) { instance_double(UserVersionsPresenter, user_version_for: user_version, user_version: 1, head_user_version: 3) } let(:user_version) { nil } let(:current_version) { 2 } @@ -51,12 +49,23 @@ end context 'when the accessioned milestone has user version' do - let(:user_version) { 1 } + let(:user_version) { 2 } let(:current_version) { 3 } it 'renders link to user version' do render_inline(instance) - expect(page).to have_link 'Public version 1', href: '/items/druid:mk420bs7601/user_versions/1' + expect(page).to have_link 'Public version 2', href: '/items/druid:mk420bs7601/user_versions/2' + end + end + + context 'when the accessioned milestone has user version and that is the current version being displayed' do + let(:user_version) { 1 } + let(:current_version) { 3 } + + it 'renders the user version but not as a link' do + render_inline(instance) + expect(page).to have_text 'Public version 1' + expect(page).to have_no_link 'Public version 1', href: '/items/druid:mk420bs7601/user_versions/1' end end @@ -69,4 +78,14 @@ expect(page).to have_no_link 'Public version 2', href: '/items/druid:mk420bs7601/user_versions/2' end end + + context 'when the accessioned milestone has user version that is head version' do + let(:user_version) { 3 } + + it 'renders the user version as a link to document path' do + render_inline(instance) + expect(page).to have_text 'Public version 3' + expect(page).to have_no_link 'Public version 3', href: '/items/druid:mk420bs7601' + end + end end