Skip to content

Commit e464379

Browse files
authored
Merge pull request #16 from alphagov/initial-UI-implementation
Implement UI page for fact check comparison
2 parents 49bc216 + 2a88df4 commit e464379

File tree

8 files changed

+148
-3
lines changed

8 files changed

+148
-3
lines changed

app/assets/stylesheets/application.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ $govuk-page-width: 1140px;
4343
@import 'govuk_publishing_components/components/tag';
4444
@import 'govuk_publishing_components/components/textarea';
4545
@import 'govuk_publishing_components/components/warning-text';
46-
46+
@import "nokodiff";
47+
@import "options_sidebar";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.options-sidebar {
2+
.govuk-button {
3+
width: 100%;
4+
}
5+
6+
@include govuk-media-query($from: "tablet") {
7+
position: sticky;
8+
top: govuk-spacing(3);
9+
10+
.sidebar-components {
11+
border-top: 2px solid $govuk-brand-colour;
12+
}
13+
}
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class FactCheckComparisonController < ApplicationController
2+
require "nokodiff"
3+
require "date"
4+
5+
def compare
6+
before = previous_content
7+
after = current_content
8+
@article_title = "Title"
9+
@date = Date.current.to_s
10+
@differ = Nokodiff.diff(before, after)
11+
@draft_url = "/"
12+
render "fact_check_comparison"
13+
end
14+
15+
def previous_content
16+
"<div>This is a line with no changes</div> <div>This line will change</div>"
17+
end
18+
19+
def current_content
20+
"<div>This is a line with no changes</div> <div>This line has some changes</div>"
21+
end
22+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<% content_for :title_context, @article_title %>
2+
<% content_for :title, t("fact_check_comparison.fact_check_heading") %>
3+
4+
<div class="govuk-grid-row">
5+
<div class="govuk-grid-column-two-thirds">
6+
<%= render "govuk_publishing_components/components/inset_text", {} do %>
7+
<p class="govuk-body"><%= t "fact_check_comparison.respond_by" %> <span class="govuk-body govuk-!-font-weight-bold"><%= @date %></span></p>
8+
<% end %>
9+
<%= render "govuk_publishing_components/components/button", {
10+
text: t("fact_check_comparison.respond_to_button"),
11+
href: "/",
12+
} %>
13+
</div>
14+
</div>
15+
<div class="govuk-grid-row">
16+
<div class="govuk-grid-column-two-thirds">
17+
<div class="govuk-body compare-editions">
18+
<%= @differ %>
19+
</div>
20+
</div>
21+
<div class="govuk-grid-column-one-third options-sidebar">
22+
<div class="sidebar-components">
23+
<%= render "govuk_publishing_components/components/heading", {
24+
text: t("fact_check_comparison.preview_heading"),
25+
heading_level: 3,
26+
font_size: "s",
27+
padding: true,
28+
} %>
29+
<p class="govuk-body"><a href=<%= @draft_url %>class="govuk-link--no-visited-state" rel="noreferrer noopener" target="_blank"><%= t "fact_check_comparison.preview_link" %></a></p>
30+
</div>
31+
<hr class="govuk-section-break govuk-section-break govuk-section-break--visible govuk-!-margin-top-6 govuk-!-margin-bottom-3">
32+
<%= render "govuk_publishing_components/components/heading", {
33+
text: t("fact_check_comparison.guidance_heading"),
34+
heading_level: 3,
35+
font_size: "s",
36+
padding: true,
37+
} %>
38+
<ul class="govuk-list govuk-list--bullet">
39+
<li><%= t("fact_check_comparison.guidance_deleted") %></li>
40+
<li><%= t("fact_check_comparison.guidance_added") %></li>
41+
</ul>
42+
<p class="govuk-body"><a href="https://www.gov.uk/government/publications/how-content-requests-from-government-get-published/fact-checking-content-on-govuk" class="govuk-link--no-visited-state" rel="noreferrer noopener" target="_blank"><%= t("fact_check_comparison.guidance_link") %></a></p>
43+
</div>
44+
</div>

app/views/application/hello_world.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
<h2>
33
Hello World!
44
</h2>
5-
</div>
5+
6+
<h3>
7+
List of implemented pages
8+
</h3>
9+
10+
<a href="/compare"> Fact check comparison </a>
11+
</div>

config/locales/en.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
en:
2-
hello: "Hello world"
2+
hello: "Hello world"
3+
fact_check_comparison:
4+
fact_check_heading: "Fact check the changes"
5+
respond_by: "Respond by"
6+
respond_to_button: "Respond to fact check"
7+
preview_heading: "Preview"
8+
preview_link: "Preview the draft page (opens in new tab)"
9+
guidance_heading: "Guidance"
10+
guidance_deleted: "red highlights and a minus sign (–) show content that’s been deleted"
11+
guidance_added: "green highlights and a plus sign (+) show content that’s been added"
12+
guidance_link: "Fact checking guidance (opens in new tab)"

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
root to: "application#hello_world"
66

7+
get "compare", to: "fact_check_comparison#compare"
8+
79
namespace :api do
810
resources :requests, only: [:create]
911
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "FactCheckComparison", type: :request do
4+
before do
5+
create(:user)
6+
7+
allow_any_instance_of(FactCheckComparisonController).to receive(:previous_content)
8+
.and_return("<div>This is the unchanged line.</div><div>This line will be changed</div>")
9+
10+
allow_any_instance_of(FactCheckComparisonController).to receive(:current_content)
11+
.and_return("<div>This is the unchanged line.</div><div>This line has changes</div>")
12+
end
13+
14+
describe "GET /compare" do
15+
it "renders the expected unchanging assets" do
16+
get compare_path
17+
18+
expect(response).to have_http_status(:ok)
19+
expect(response.body).to include(I18n.t("fact_check_comparison.fact_check_heading"))
20+
expect(response.body).to include(I18n.t("fact_check_comparison.respond_by"))
21+
expect(response.body).to include(I18n.t("fact_check_comparison.respond_to_button"))
22+
expect(response.body).to include(I18n.t("fact_check_comparison.preview_heading"))
23+
expect(response.body).to include(I18n.t("fact_check_comparison.preview_link"))
24+
expect(response.body).to include(I18n.t("fact_check_comparison.guidance_heading"))
25+
expect(response.body).to include(I18n.t("fact_check_comparison.guidance_deleted"))
26+
expect(response.body).to include(I18n.t("fact_check_comparison.guidance_added"))
27+
expect(response.body).to include(I18n.t("fact_check_comparison.guidance_link"))
28+
end
29+
30+
it "renders the diff with formatting" do
31+
get compare_path
32+
33+
parsed = Nokogiri::HTML(response.body)
34+
35+
expect(parsed.at_css("div.compare-editions")&.text).to include("This is the unchanged line.")
36+
37+
expect(parsed.at_css("del")&.text).to include("This line will be changed")
38+
expect(parsed.at_css("del")&.text).not_to include("This is the unchanged line.")
39+
expect(parsed.at_css("del")&.text).not_to include("This line has changes")
40+
41+
expect(parsed.at_css("ins")&.text).to include("This line has changes")
42+
expect(parsed.at_css("ins")&.text).not_to include("This is the unchanged line.")
43+
expect(parsed.at_css("ins")&.text).not_to include("This line will be changed")
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)