From fcb14bc9100decd4fab70b42915e6d0f9a2d3dd4 Mon Sep 17 00:00:00 2001 From: Justin Littman Date: Fri, 17 Jan 2025 14:41:30 -0500 Subject: [PATCH] Conditionally display DOI on dashboard. closes #404 --- .../dashboard/show/works_list_component.rb | 12 ++++- .../show/works_list_component_spec.rb | 52 +++++++++++-------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/app/components/dashboard/show/works_list_component.rb b/app/components/dashboard/show/works_list_component.rb index 594efc0f..93884309 100644 --- a/app/components/dashboard/show/works_list_component.rb +++ b/app/components/dashboard/show/works_list_component.rb @@ -32,7 +32,7 @@ def values_for(work) @status_map[work.id].status_message, work.user.name, work.object_updated_at ? I18n.l(work.object_updated_at, format: '%b %d, %Y') : nil, - work.druid ? link_to(nil, Sdr::Purl.from_druid(druid: work.druid)) : nil + persistent_link_for(work) ] end @@ -43,6 +43,16 @@ def link_for(work) work_path(druid: work.druid) end + + def persistent_link_for(work) + if work.druid.nil? + nil + elsif work.doi_assigned? + link_to(nil, Doi.url(druid: work.druid)) + else + link_to(nil, Sdr::Purl.from_druid(druid: work.druid)) + end + end end end end diff --git a/spec/components/dashboard/show/works_list_component_spec.rb b/spec/components/dashboard/show/works_list_component_spec.rb index f2ebcf7b..f0e5fa52 100644 --- a/spec/components/dashboard/show/works_list_component_spec.rb +++ b/spec/components/dashboard/show/works_list_component_spec.rb @@ -5,40 +5,46 @@ RSpec.describe Dashboard::Show::WorksListComponent, type: :component do let(:work) do create(:work, user: current_user, collection:, druid: druid_fixture, - object_updated_at: Time.zone.parse('2024-12-3')) + object_updated_at: Time.zone.parse('2024-12-3'), doi_assigned: false) end let(:work_without_druid) { create(:work, user: current_user, collection:) } + let(:work_with_doi) { create(:work, :with_druid, user: current_user, collection:) } let(:collection) { create(:collection) } let(:current_user) { create(:user) } let(:version_status) { instance_double(Dor::Services::Client::ObjectVersion::VersionStatus, open?: true, version: 1) } let(:status_map) do { work.id => VersionStatus.new(status: version_status), - work_without_druid.id => VersionStatus::NilStatus.new + work_without_druid.id => VersionStatus::NilStatus.new, + work_with_doi.id => VersionStatus::NilStatus.new } end - it 'renders the works list table with rows' do - render_inline(described_class.new(collection:, status_map:)) + context 'when DOI not assigned' do + it 'renders the works list table with rows' do + render_inline(described_class.new(collection:, status_map:)) - table = page.find('table') - expect(table).to have_css('th', text: 'Recent deposits in collection') - expect(table).to have_css('th', text: 'Deposit status') - expect(table).to have_css('th', text: 'Owner') - expect(table).to have_css('th', text: 'Last modified') - expect(table).to have_css('th', text: 'Persistent link') - table_body = table.find('tbody') - expect(table_body).to have_css('tr', count: 2) - first_row = table_body.find('tr:nth-of-type(1)') - expect(first_row).to have_css('td:nth-of-type(1)', text: work.title) - expect(first_row).to have_link(work.title, href: "/works/#{work.druid}") - expect(first_row).to have_css('td:nth-of-type(2)', text: 'Draft - Not deposited') - expect(first_row).to have_css('td:nth-of-type(4)', text: 'Dec 03, 2024') - expect(first_row).to have_css('td:nth-of-type(5)', text: Sdr::Purl.from_druid(druid: work.druid)) - second_row = table_body.find('tr:nth-of-type(2)') - expect(second_row).to have_css('td:nth-of-type(1)', text: work_without_druid.title) - expect(second_row).to have_link(work_without_druid.title, href: "/works/wait/#{work_without_druid.id}") - expect(second_row).to have_css('td:nth-of-type(2)', text: 'Saving') - expect(second_row).to have_css('td:nth-of-type(5)', text: '') # No PURL + table = page.find('table') + expect(table).to have_css('th', text: 'Recent deposits in collection') + expect(table).to have_css('th', text: 'Deposit status') + expect(table).to have_css('th', text: 'Owner') + expect(table).to have_css('th', text: 'Last modified') + expect(table).to have_css('th', text: 'Link for sharing') + table_body = table.find('tbody') + expect(table_body).to have_css('tr', count: 3) + first_row = table_body.find('tr:nth-of-type(1)') + expect(first_row).to have_css('td:nth-of-type(1)', text: work.title) + expect(first_row).to have_link(work.title, href: "/works/#{work.druid}") + expect(first_row).to have_css('td:nth-of-type(2)', text: 'Draft - Not deposited') + expect(first_row).to have_css('td:nth-of-type(4)', text: 'Dec 03, 2024') + expect(first_row).to have_css('td:nth-of-type(5)', text: Sdr::Purl.from_druid(druid: work.druid)) + second_row = table_body.find('tr:nth-of-type(2)') + expect(second_row).to have_css('td:nth-of-type(1)', text: work_without_druid.title) + expect(second_row).to have_link(work_without_druid.title, href: "/works/wait/#{work_without_druid.id}") + expect(second_row).to have_css('td:nth-of-type(2)', text: 'Saving') + expect(second_row).to have_css('td:nth-of-type(5)', text: '') # No PURL + third_row = table_body.find('tr:nth-of-type(3)') + expect(third_row).to have_css('td:nth-of-type(5)', text: Doi.url(druid: work_with_doi.druid)) + end end end