Skip to content

Commit

Permalink
Merge pull request #9580 from alphagov/content-modelling/676-link-pre…
Browse files Browse the repository at this point in the history
…views-to-draft-store

Link to draft host document for content block preview
  • Loading branch information
Harriethw authored Nov 5, 2024
2 parents d1fe5e2 + b04d8b6 commit cc029dc
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frozen_string_literal: true

class ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableComponent < ViewComponent::Base
def initialize(caption:, host_content_items:)
def initialize(caption:, host_content_items:, is_preview: false)
@caption = caption
@host_content_items = host_content_items
@is_preview = is_preview
end

private
Expand Down Expand Up @@ -43,8 +44,24 @@ def users
@users ||= User.where(uid: host_content_items.map(&:last_edited_by_editor_id))
end

def frontend_path(content_item)
if @is_preview
Plek.external_url_for("draft-origin") + content_item.base_path
else
Plek.external_url_for("government-frontend") + content_item.base_path
end
end

def content_link_text(content_item)
sanitize [
content_item.title,
tag.span("(opens in new tab)", class: "govuk-visually-hidden"),
].join(" ")
end

def content_link(content_item)
link_to(content_item.title, Plek.website_root + content_item.base_path, class: "govuk-link")
link_to(content_link_text(content_item),
frontend_path(content_item), class: "govuk-link", target: "_blank", rel: "noopener")
end

def organisation_link(content_item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div class="govuk-grid-column-full">
<%= render(
ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableComponent.new(
is_preview: true,
caption: "Content it appears in",
host_content_items: @host_content_items,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ Feature: Edit a content object
And I visit the Content Block Manager home page
Then I should still see the live edition on the homepage

Scenario: GDS editor can preview a host document
When I revisit the edit page
And I fill out the form
Then I am shown where the changes will take place
And the host documents link to the draft content store
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
"content_id" => SecureRandom.uuid,
"last_edited_by_editor_id" => SecureRandom.uuid,
"last_edited_at" => 2.days.ago.to_s,
"host_content_id" => "abc12345",
"primary_publishing_organisation" => {
"content_id" => SecureRandom.uuid,
"title" => "Organisation #{i}",
Expand Down Expand Up @@ -453,6 +454,16 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
end
end

And("the host documents link to the draft content store") do
@dependent_content.each do |item|
expect(page).to have_selector("a.govuk-link[href='#{Plek.external_url_for('draft-origin') + item['base_path']}']", text: item["title"])
end
end

When("I click on the first host document") do
click_on @dependent_content.first["title"]
end

When(/^I save and continue$/) do
click_save_and_continue
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def self.it_returns_unknown_user

assert_selector "tbody .govuk-table__row", count: 1

assert_selector "tbody .govuk-table__cell", text: host_content_item.title
assert_selector ".govuk-link" do |link|
assert_equal "#{host_content_item.title} (opens in new tab)", link.text
assert_equal Plek.external_url_for("government-frontend") + host_content_item.base_path, link[:href]
assert_equal "noopener", link[:rel]
assert_equal "_blank", link[:target]
end
assert_selector "tbody .govuk-table__cell", text: host_content_item.document_type.humanize
assert_selector "tbody .govuk-table__cell", text: "1.2m"
assert_selector "tbody .govuk-table__cell", text: host_content_item.publishing_organisation["title"]
Expand Down Expand Up @@ -152,5 +157,19 @@ def self.it_returns_unknown_user
assert_selector "tbody .govuk-table__cell", text: "Not set"
end
end

context "when previewing" do
it "returns the draft content store link" do
render_inline(
described_class.new(
is_preview: true,
caption:,
host_content_items:,
),
)

assert_selector "a[href='#{Plek.external_url_for('draft-origin') + host_content_item.base_path}']", text: host_content_item.title
end
end
end
end

0 comments on commit cc029dc

Please sign in to comment.