Skip to content

Commit

Permalink
Merge pull request #85 from alphagov/statistics-announcment-with-rele…
Browse files Browse the repository at this point in the history
…ase-date-change

Support Statistics announcements with changed date
  • Loading branch information
fofr committed Feb 1, 2016
2 parents 5c87a2e + 7421ab3 commit ffec9eb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/views/_statistics_announcement.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
.cancellation-notice {
@include notice;
}

.release-date-change-notice {
h2 {
font-weight: bold;
margin-bottom: $gutter-half;
}
}
}
12 changes: 12 additions & 0 deletions app/presenters/statistics_announcement_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def release_date_and_status
release_date
end

def previous_release_date
content_item["details"]["previous_display_date"]
end

def release_date_changed?
content_item["details"].include?("previous_display_date")
end

def other_metadata
if cancelled?
{
Expand Down Expand Up @@ -50,6 +58,10 @@ def cancellation_reason
content_item["details"]["cancellation_reason"]
end

def release_date_change_reason
content_item["details"]["latest_change_note"]
end

private

def state
Expand Down
16 changes: 15 additions & 1 deletion app/views/content_items/statistics_announcement.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% end %>
</div>

<div class="grid-row">
<div class="grid-row primary-metadata">
<div class="column-two-thirds">
<%= render 'govuk_component/metadata',
other: @content_item.other_metadata,
Expand All @@ -34,3 +34,17 @@
</div>
<% end %>
<%= render 'shared/description', description: @content_item.description %>

<% if @content_item.release_date_changed? %>
<div class="grid-row">
<div class="column-two-thirds release-date-change-notice">
<h2>The release date has been changed</h2>
<%= render 'govuk_component/metadata',
other: {
"Previous date" => @content_item.previous_release_date,
"Reason for change" => @content_item.release_date_change_reason,
}
%>
</div>
</div>
<% end %>
17 changes: 17 additions & 0 deletions test/integration/statistics_announcement_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@ class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest
assert_has_component_metadata_pair("Proposed release", "20 January 2016 9:30am")
assert_has_component_metadata_pair("Cancellation date", "17 January 2016 2:19pm")
end

test "statistics with a changed release date" do
setup_and_visit_content_item('release_date_changed')

assert_has_component_title(@content_item["title"])
assert page.has_text?(@content_item["description"])

within '.primary-metadata' do
assert_has_component_metadata_pair("Release date", "20 January 2016 9:30am (confirmed)")
end

within '.release-date-change-notice' do
assert page.has_text?("The release date has been changed")
assert_has_component_metadata_pair("Previous date", "19 January 2016 9:30am")
assert_has_component_metadata_pair("Reason for change", @content_item["details"]["latest_change_note"])
end
end
end
13 changes: 13 additions & 0 deletions test/presenters/statistics_announcement_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class StatisticsAnnouncementPresenterTest < ActiveSupport::TestCase
assert_equal '20 January 2016 9:30am', statistics_announcement.release_date
end

test 'presents previous_release_date' do
assert_equal '19 January 2016 9:30am', statistics_announcement_date_changed.previous_release_date
end

test 'presents release_date_and_status when confirmed' do
assert_equal '20 January 2016 9:30am (confirmed)', statistics_announcement.release_date_and_status
end
Expand Down Expand Up @@ -58,6 +62,11 @@ class StatisticsAnnouncementPresenterTest < ActiveSupport::TestCase
assert statistics_announcement_national.national_statistics?
end

test 'knows if the release date has changed' do
assert statistics_announcement_date_changed.release_date_changed?
assert_not statistics_announcement_national.release_date_changed?
end

def statistics_announcement_cancelled
statistics_announcement('cancelled_official_statistics')
end
Expand All @@ -70,6 +79,10 @@ def statistics_announcement_national
statistics_announcement('national_statistics')
end

def statistics_announcement_date_changed
statistics_announcement('release_date_changed')
end

def statistics_announcement(type = 'official_statistics')
content_item = govuk_content_schema_example('statistics_announcement', type)
StatisticsAnnouncementPresenter.new(content_item)
Expand Down

0 comments on commit ffec9eb

Please sign in to comment.