Skip to content
Open
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
4 changes: 2 additions & 2 deletions app/components/admin/editions/show/preview_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

<% if versioning_completed %>
<p class="govuk-body">
<%= preview_link(primary_locale_link_text, local_edition.public_url(draft: true)) %>
<%= preview_link(primary_locale_link_text, local_edition.public_url({ draft: true }.merge(cachebust_url_options))) %>
</p>

<% if available_in_multiple_languages %>
<% translation_preview_links = local_edition.non_primary_translation_locales.map do |locale|
preview_link(
"Preview on website - #{locale.native_and_english_language_name} (opens in new tab)",
local_edition.public_url(locale: locale.code, draft: true),
local_edition.public_url({ locale: locale.code, draft: true }.merge(cachebust_url_options)),
)
end %>
<%= render "govuk_publishing_components/components/details", {
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/edition_update_slug_steps.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Then(/^I can see the preview URL of the publication "([^"]*)" contains "([^"]*)"$/) do |title, new_slug|
visit admin_edition_path(Publication.latest_edition.find_by!(title:))
expect(page).to have_link "Preview on website (opens in new tab)", href: "https://draft-origin.test.gov.uk/government/publications/#{new_slug}"
expect(page).to have_link "Preview on website (opens in new tab)", href: %r{\Ahttps://draft-origin\.test\.gov\.uk/government/publications/#{Regexp.escape(new_slug)}\?cachebust=\d+\z}
end

Then(/^I cannot see the option to keep the current page URL$/) do
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/policy_steps.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Then(/^I should see a link to the preview version of the publication "([^"]*)"$/) do |publication_title|
publication = Publication.find_by!(title: publication_title)
visit admin_edition_path(publication)
expected_preview_url = "https://draft-origin.test.gov.uk/government/publications/#{publication.slug}"
expected_preview_url = %r{\Ahttps://draft-origin\.test\.gov\.uk/government/publications/#{Regexp.escape(publication.slug)}\?cachebust=\d+\z}

expect(expected_preview_url).to eq(find("a[target='_blank']")[:href])
expect(find("a[target='_blank']")[:href]).to match(expected_preview_url)
end
13 changes: 8 additions & 5 deletions test/components/admin/editions/show/preview_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@ class Admin::Editions::Show::PreviewComponentTest < ViewComponent::TestCase

test "renders a link with tracking to preview the document when the edition is english only" do
edition = build_stubbed(:publication, document: @document)
Admin::Editions::Show::PreviewComponent.any_instance.stubs(:cachebust_url_options).returns(cachebust: 123)

render_inline(Admin::Editions::Show::PreviewComponent.new(edition:))
assert_selector "a[href='#{edition.public_url(draft: true)}']", text: "Preview on website (opens in new tab)"
assert_selector "a[href='#{edition.public_url(draft: true, cachebust: 123)}']", text: "Preview on website (opens in new tab)"
end

test "renders a link with tracking to preview the document when the edition is a foreign language only edition" do
edition = build_stubbed(:publication, document: @document, primary_locale: :fr)
Admin::Editions::Show::PreviewComponent.any_instance.stubs(:cachebust_url_options).returns(cachebust: 123)

render_inline(Admin::Editions::Show::PreviewComponent.new(edition:))
assert_selector "a[href='#{edition.public_url(draft: true)}']", text: "Preview on website (opens in new tab)"
assert_selector "a[href='#{edition.public_url(draft: true, cachebust: 123)}']", text: "Preview on website (opens in new tab)"
end

test "renders a link with tracking to preview the document for each translation when there are multiple translations" do
edition = create(:publication, translated_into: %i[fr es], document: @document)
Admin::Editions::Show::PreviewComponent.any_instance.stubs(:cachebust_url_options).returns(cachebust: 123)

render_inline(Admin::Editions::Show::PreviewComponent.new(edition:))
assert_selector "a[href='#{edition.public_url(draft: true)}']", text: "Preview on website - English (opens in new tab)"
assert_selector "a[href='#{edition.public_url(locale: 'fr', draft: true)}']", visible: false, text: "Preview on website - French (Français) (opens in new tab)"
assert_selector "a[href='#{edition.public_url(locale: 'es', draft: true)}']", visible: false, text: "Preview on website - Spanish (Español) (opens in new tab)"
assert_selector "a[href='#{edition.public_url(draft: true, cachebust: 123)}']", text: "Preview on website - English (opens in new tab)"
assert_selector "a[href='#{edition.public_url(locale: 'fr', draft: true, cachebust: 123)}']", visible: false, text: "Preview on website - French (Français) (opens in new tab)"
assert_selector "a[href='#{edition.public_url(locale: 'es', draft: true, cachebust: 123)}']", visible: false, text: "Preview on website - Spanish (Español) (opens in new tab)"
end

test "renders sharable preview functionality when edition is a pre-publication state" do
Expand Down
2 changes: 1 addition & 1 deletion test/support/css_selectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def link_to_public_version_selector(document)
end

def link_to_preview_version_selector(document)
"a[href='#{document.public_url(draft: true)}']"
"a[href^='#{document.public_url(draft: true)}?cachebust=']"
end

def policy_group_selector
Expand Down