Skip to content

Commit eb80731

Browse files
committed
Generate draft origin preview links on compare page
The token helper methods are used to generate a draft origin preview link for the Request. If the link cannot be generated due to the required fields not being present, no link is displayed.
1 parent 2bbc302 commit eb80731

File tree

4 files changed

+73
-24
lines changed

4 files changed

+73
-24
lines changed

app/controllers/fact_check_comparison_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def compare
1111
@differ = Nokodiff.diff(before, after)
1212
@article_title = @request.source_title
1313
@deadline = @request.deadline.to_date.to_s
14-
@draft_url = "/"
14+
@draft_url = draft_origin_preview_url(@request)
1515

1616
render "fact_check_comparison"
1717
end

app/views/application/fact_check_comparison.html.erb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,35 @@
2323
</div>
2424
<div class="govuk-grid-column-one-third options-sidebar">
2525
<div class="sidebar-components">
26+
<% if @draft_url %>
27+
<%= render "govuk_publishing_components/components/heading", {
28+
text: t("fact_check_comparison.preview_heading"),
29+
heading_level: 3,
30+
font_size: "s",
31+
padding: true,
32+
} %>
33+
<p class="govuk-body"><%= link_to t("fact_check_comparison.preview_link"), @draft_url, class: "govuk-link--no-visited-state govuk-link", target: :_blank, rel: :noopener %></p>
34+
<hr class="govuk-section-break govuk-section-break govuk-section-break--visible govuk-!-margin-top-6 govuk-!-margin-bottom-3" />
35+
<% end %>
2636
<%= render "govuk_publishing_components/components/heading", {
27-
text: t("fact_check_comparison.preview_heading"),
37+
text: t("fact_check_comparison.guidance_heading"),
2838
heading_level: 3,
2939
font_size: "s",
3040
padding: true,
3141
} %>
32-
<p class="govuk-body"><%= link_to t("fact_check_comparison.preview_link"), @draft_url, class: "govuk-link--no-visited-state govuk-link" %></p>
42+
<%= render "govuk_publishing_components/components/list", {
43+
visible_counters: true,
44+
items: [
45+
t("fact_check_comparison.guidance_deleted"),
46+
t("fact_check_comparison.guidance_added"),
47+
],
48+
} %>
49+
<p class="govuk-body">
50+
<%= link_to t("fact_check_comparison.guidance_link"),
51+
"https://gov.uk/government/publications/how-content-requests-from-government-get-published/fact-checking-content-on-govuk",
52+
class: "govuk-link--no-visited-state govuk-link", target: :_blank, rel: :noopener
53+
%>
54+
</p>
3355
</div>
34-
<hr class="govuk-section-break govuk-section-break govuk-section-break--visible govuk-!-margin-top-6 govuk-!-margin-bottom-3" />
35-
<%= render "govuk_publishing_components/components/heading", {
36-
text: t("fact_check_comparison.guidance_heading"),
37-
heading_level: 3,
38-
font_size: "s",
39-
padding: true,
40-
} %>
41-
<%= render "govuk_publishing_components/components/list", {
42-
visible_counters: true,
43-
items: [
44-
t("fact_check_comparison.guidance_deleted"),
45-
t("fact_check_comparison.guidance_added"),
46-
],
47-
} %>
48-
<p class="govuk-body">
49-
<%= link_to t("fact_check_comparison.guidance_link"),
50-
"https://gov.uk/government/publications/how-content-requests-from-government-get-published/fact-checking-content-on-govuk",
51-
class: "govuk-link--no-visited-state govuk-link", target: :_blank, rel: :noopener
52-
%>
53-
</p>
5456
</div>
5557
</div>

spec/requests/fact_check_comparison_controller_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@
2525
expect(response.body).to include(I18n.t("fact_check_comparison.guidance_link"))
2626
end
2727

28+
it "includes a draft origin preview link with a JWT token" do
29+
get compare_path(source_app: request.source_app, source_id: request.source_id)
30+
31+
expect(response.body).to include("draft-origin.dev.gov.uk/#{request.draft_slug}")
32+
expect(response.body).to include("token=")
33+
end
34+
35+
context "when draft origin fields are not present" do
36+
let(:request) do
37+
create(
38+
:request,
39+
draft_content_id: nil,
40+
draft_auth_bypass_id: nil,
41+
draft_slug: nil,
42+
previous_content: { "body" => "<div>Old content</div>" },
43+
current_content: { "body" => "<div>New content</div>" },
44+
)
45+
end
46+
47+
it "does not render the preview section" do
48+
get compare_path(source_app: request.source_app, source_id: request.source_id)
49+
50+
expect(response).to have_http_status(:ok)
51+
expect(response.body).not_to include(I18n.t("fact_check_comparison.preview_heading"))
52+
expect(response.body).not_to include(I18n.t("fact_check_comparison.preview_link"))
53+
end
54+
end
55+
2856
it "renders the diff with formatting" do
2957
get compare_path(source_app: request.source_app, source_id: request.source_id)
3058

spec/system/fact_check_comparison_spec.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,33 @@
3535
expect(page).to have_text(I18n.t("fact_check_response.heading"))
3636
end
3737

38-
it "displays the guidance sidebar" do
38+
it "displays the draft origin preview link" do
3939
visit compare_path(source_app: request.source_app, source_id: request.source_id)
4040

4141
expect(page).to have_text(I18n.t("fact_check_comparison.preview_heading"))
42+
expect(page).to have_link(I18n.t("fact_check_comparison.preview_link"))
43+
end
44+
45+
it "displays the guidance sidebar" do
46+
visit compare_path(source_app: request.source_app, source_id: request.source_id)
47+
4248
expect(page).to have_text(I18n.t("fact_check_comparison.guidance_heading"))
4349
expect(page).to have_text(I18n.t("fact_check_comparison.guidance_deleted"))
4450
expect(page).to have_text(I18n.t("fact_check_comparison.guidance_added"))
4551
expect(page).to have_link(I18n.t("fact_check_comparison.guidance_link"))
4652
end
53+
54+
context "when no draft preview link can be generated" do
55+
before do
56+
allow_any_instance_of(TokenHelper).to receive(:draft_origin_preview_url).and_return(nil)
57+
end
58+
59+
it "does not render the preview section or link" do
60+
visit compare_path(source_app: request.source_app, source_id: request.source_id)
61+
62+
expect(page).not_to have_text(I18n.t("fact_check_comparison.preview_heading"))
63+
expect(page).not_to have_link(I18n.t("fact_check_comparison.preview_link"))
64+
end
65+
end
4766
end
4867
end

0 commit comments

Comments
 (0)