Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from alphagov/speeches
Render the speeches format
- Loading branch information
Showing
12 changed files
with
251 additions
and
21 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.speech { | ||
@include sidebar-with-body; | ||
@include description; | ||
@include history-notice; | ||
@include withdrawal-notice; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 & 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'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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters