Skip to content

Commit

Permalink
Conditionally display DOI on dashboard.
Browse files Browse the repository at this point in the history
closes #404
  • Loading branch information
justinlittman committed Jan 17, 2025
1 parent d1df0cc commit fcb14bc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
12 changes: 11 additions & 1 deletion app/components/dashboard/show/works_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
52 changes: 29 additions & 23 deletions spec/components/dashboard/show/works_list_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fcb14bc

Please sign in to comment.