Skip to content

Commit

Permalink
Merge pull request #215 from alphagov/speeches
Browse files Browse the repository at this point in the history
Render the speeches format
  • Loading branch information
gpeng committed Jan 3, 2017
2 parents 3ea139e + 99f3f8f commit eb6bf78
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 21 deletions.
Binary file removed app/assets/images/placeholder.jpg
Binary file not shown.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Expand Up @@ -37,3 +37,4 @@
@import "views/fatality-notice";
@import "views/statistical-data-set";
@import "views/consultation";
@import "views/speech";
6 changes: 6 additions & 0 deletions app/assets/stylesheets/views/_speech.scss
@@ -0,0 +1,6 @@
.speech {
@include sidebar-with-body;
@include description;
@include history-notice;
@include withdrawal-notice;
}
2 changes: 1 addition & 1 deletion app/presenters/linkable.rb
Expand Up @@ -2,7 +2,7 @@ module Linkable
include ActionView::Helpers::UrlHelper

def from
organisations_ordered_by_importance + links_group(%w{worldwide_organisations ministers})
organisations_ordered_by_importance + links_group(%w{worldwide_organisations ministers speaker})
end

def part_of
Expand Down
51 changes: 51 additions & 0 deletions app/presenters/speech_presenter.rb
@@ -0,0 +1,51 @@
class SpeechPresenter < ContentItemPresenter
include Linkable
include Political
include Updatable

def body
content_item["details"]["body"]
end

def image
content_item["details"]["image"]
end

def delivery_type
if document_type == 'authored_article'
'Written on'
else
'Delivered on'
end
end

def delivered_on_metadata
"#{delivered_on}#{speech_type_explanation}"
end

def location
content_item["details"]["location"]
end

def from
super.tap do |f|
f.push(speaker_without_profile) if speaker_without_profile
end
end

private

def delivered_on
delivered_on_date = content_item["details"]["delivered_on"]
content_tag(:time, display_date(delivered_on_date), datetime: delivered_on_date)
end

def speech_type_explanation
explanation = content_item["details"]["speech_type_explanation"]
" (#{explanation})" if explanation
end

def speaker_without_profile
content_item["details"]["speaker_without_profile"]
end
end
42 changes: 42 additions & 0 deletions app/views/content_items/speech.html.erb
@@ -0,0 +1,42 @@
<%= content_for :page_class, @content_item.format.dasherize %>
<%= content_for :title, @content_item.page_title %>
<%= content_for :meta_description, @content_item.description %>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/title',
context: t("content_item.format.#{@content_item.document_type}", count: 1),
title: @content_item.title,
average_title_length: 'long' %>
</div>
</div>

<%= render 'shared/withdrawal_notice', content_item: @content_item %>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/metadata',
from: @content_item.from,
first_published: @content_item.published,
last_updated: @content_item.updated,
part_of: @content_item.part_of,
see_updates_link: true,
other: {
@content_item.delivery_type => @content_item.delivered_on_metadata,
"Location" => @content_item.location
}
%>
</div>
</div>

<%= render 'shared/history_notice', content_item: @content_item %>
<%= render 'shared/description', description: @content_item.description %>
<%= render 'shared/sidebar_with_body', content_item: @content_item %>
<%= render 'govuk_component/document_footer',
from: @content_item.from,
published: @content_item.published,
updated: @content_item.updated,
history: @content_item.history,
part_of: @content_item.part_of
%>
4 changes: 0 additions & 4 deletions app/views/shared/_sidebar_image.html.erb
Expand Up @@ -3,8 +3,4 @@
<img src="<%= image["url"] %>" alt="<%= image["alt_text"] %>">
<% if image["caption"].present? %><figcaption><%= image["caption"] %></figcaption><% end %>
</figure>
<% else %>
<div class="sidebar-image">
<%= image_tag 'placeholder.jpg', alt: '' %>
</div>
<% end %>
10 changes: 6 additions & 4 deletions app/views/shared/_sidebar_with_body.html.erb
@@ -1,8 +1,10 @@
<div class="grid-row sidebar-with-body">
<div class="column-third">
<%= render 'shared/sidebar_image', image: content_item.image %>
</div>
<div class="column-two-thirds">
<% if content_item.image %>
<div class="column-third">
<%= render 'shared/sidebar_image', image: content_item.image %>
</div>
<% end %>
<div class="column-two-thirds <%= 'offset-one-third' unless content_item.image %>">
<%= render 'govuk_component/govspeak',
content: content_item.body,
direction: page_text_direction %>
Expand Down
11 changes: 0 additions & 11 deletions test/controllers/content_items_controller_test.rb
Expand Up @@ -75,17 +75,6 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_response :forbidden
end

test 'content item without images is rendered with a placeholder image' do
content_item_without_images = govuk_content_schema_example('case_study', 'case_study')
content_item_without_images['details'].delete('image')
content_store_has_item(content_item_without_images['base_path'], content_item_without_images)

get :show, params: { path: path_for(content_item_without_images) }

assert_response :success
assert_select '.sidebar-image img[src*="/government-frontend/placeholder"]', count: 1
end

def path_for(content_item)
content_item['base_path'].sub(/^\//, '')
end
Expand Down
47 changes: 47 additions & 0 deletions test/integration/speech_test.rb
@@ -0,0 +1,47 @@
require 'test_helper'

class SpeechTest < ActionDispatch::IntegrationTest
test "renders title, description and body" do
setup_and_visit_content_item('speech')

assert_has_component_title(@content_item["title"])
assert page.has_text?(@content_item["description"])
assert_has_component_govspeak(@content_item["details"]["body"])
end

test "renders metadata and document footer, including speaker" do
setup_and_visit_content_item('speech')

assert_has_component_metadata_pair("first_published", "8 March 2016")
link1 = "<a href=\"/government/organisations/department-of-energy-climate-change\">Department of Energy &amp; Climate Change</a>"
link2 = "<a href=\"/government/people/andrea-leadsom\">The Rt Hon Andrea Leadsom MP</a>"
assert_has_component_metadata_pair("from", [link1, link2])
assert_has_component_document_footer_pair("from", [link1, link2])

assert_has_component_metadata_pair("Location", @content_item["details"]["location"])
assert_has_component_metadata_pair(
"Delivered on",
'<time datetime="2016-02-02T00:00:00+00:00">2 February 2016</time> (Original script, may differ from delivered version)'
)
end

test "renders part of in metadata and document footer" do
setup_and_visit_content_item('speech-transcript')

link1 = "<a href=\"/government/policies/government-transparency-and-accountability\">Government transparency and accountability</a>"
link2 = "<a href=\"/government/policies/tax-evasion-and-avoidance\">Tax evasion and avoidance</a>"
link3 = "<a href=\"/government/topical-events/anti-corruption-summit-london-2016\">Anti-Corruption Summit: London 2016</a>"
assert_has_component_metadata_pair("part_of", [link1, link2, link3])
assert_has_component_document_footer_pair("part_of", [link1, link2, link3])
end

test "renders speaker without a profile as text in metadata" do
setup_and_visit_content_item('speech-speaker-without-profile')

link1 = "<a href=\"/government/organisations/prime-ministers-office-10-downing-street\">Prime Minister&#39;s Office, 10 Downing Street</a>"
link2 = "<a href=\"/government/organisations/cabinet-office\">Cabinet Office</a>"
speaker = "Her Majesty the Queen"
assert_has_component_metadata_pair("from", [link1, link2, speaker])
assert_has_component_document_footer_pair("from", [link1, link2, speaker])
end
end
96 changes: 96 additions & 0 deletions test/presenters/speech_presenter_test.rb
@@ -0,0 +1,96 @@
require 'presenter_test_helper'

class SpeechPresenterTest
class SpeechTestCase < PresenterTestCase
def format_name
"speech"
end
end

class PresentedSpeech < SpeechTestCase
test 'presents the format' do
assert_equal schema_item['schema_name'], presented_item.format
end

test '#published returns a formatted date of the day the content item became public' do
assert_equal "8 March 2016", presented_item.published
end

test 'presents a description' do
assert_equal schema_item['description'], presented_item.description
end

test 'presents a speech location' do
assert_equal schema_item['details']['location'], presented_item.location
end

test 'presents how speech was delivered' do
assert_equal 'Delivered on', presented_item.delivery_type
end

test 'presents a delivered on date with speech type explanation for the metadata component' do
assert_equal '<time datetime="2016-02-02T00:00:00+00:00">2 February 2016</time> (Original script, may differ from delivered version)', presented_item.delivered_on_metadata
end

test 'presents the body' do
expected_body = schema_item['details']['body']

assert_equal expected_body, presented_item.body
end

test 'from includes speaker' do
assert presented_item.from.include?("<a href=\"/government/people/andrea-leadsom\">The Rt Hon Andrea Leadsom MP</a>")
end
end

class TranscriptPresentedSpeech < SpeechTestCase
def example_schema_name
'speech-transcript'
end

test 'presents a delivered on date with speech type explanation for the metadata component' do
assert_equal '<time datetime="2016-02-02T00:00:00+00:00">2 February 2016</time> (Original script, may differ from delivered version)', presented_item.delivered_on_metadata
end
end

class WrittenStatementParliamentPresentedSpeech < SpeechTestCase
def example_schema_name
'speech-written-statement-parliament'
end

test 'presents the speech as being delivered' do
assert_equal 'Delivered on', presented_item(example_schema_name).delivery_type
end

test 'presents a delivered on date without an explanation' do
assert_equal '<time datetime="2016-12-20T15:00:00+00:00">20 December 2016</time>', presented_item(example_schema_name).delivered_on_metadata
end
end

class AuthoredArticlePresentedSpeech < SpeechTestCase
def example_schema_name
'speech-authored-article'
end

test 'presents the speech as being written' do
assert_equal 'Written on', presented_item(example_schema_name).delivery_type
end

test 'presents a delivered on date without an explanation' do
assert_equal '<time datetime="2016-04-05T00:00:00+01:00">5 April 2016</time>', presented_item(example_schema_name).delivered_on_metadata
end
end

class SpeakerWithoutProfilePresentedSpeech < SpeechTestCase
def example_schema_name
'speech-speaker-without-profile'
end

test 'includes speaker without profile in from_with_speaker' do
assert_equal [
"<a href=\"/government/organisations/prime-ministers-office-10-downing-street\">Prime Minister&#39;s Office, 10 Downing Street</a>",
"<a href=\"/government/organisations/cabinet-office\">Cabinet Office</a>",
"Her Majesty the Queen"], presented_item(example_schema_name).from
end
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -62,7 +62,7 @@ def assert_has_component_title(title)

def assert_has_component_govspeak(content, index: 1)
within_component_govspeak(index: index) do
assert_equal content, JSON.parse(page.text).fetch("content")
assert_equal content.gsub(' ', ' '), JSON.parse(page.text).fetch("content")
end
end

Expand Down

0 comments on commit eb6bf78

Please sign in to comment.