Skip to content

Commit

Permalink
Merge pull request #2127 from alphagov/consolidation-show-editors-on-…
Browse files Browse the repository at this point in the history
…publish-confirmation

List draft sections on publish confirmation page
  • Loading branch information
ryanb-gds authored Aug 15, 2023
2 parents 4963de7 + 7bcbad3 commit 2462778
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//= require govuk_publishing_components/dependencies
//= require govuk_publishing_components/lib
//= require govuk_publishing_components/components/button
//= require govuk_publishing_components/components/layout-header
//= require govuk_publishing_components/components/skip-link
//= require govuk_publishing_components/components/table
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import "govuk_publishing_components/components/layout-footer";
@import "govuk_publishing_components/components/layout-header";
@import "govuk_publishing_components/components/skip-link";
@import "govuk_publishing_components/components/table";
@import "govuk_publishing_components/components/title";

@import "views/whats_new";
10 changes: 10 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ def allow_publish?(manual, slug_unique)
manual.draft? && manual.sections.any? && current_user_can_publish? && slug_unique
end

def last_updated_text(section)
text = "Updated #{time_ago_in_words(section.updated_at)} ago"

if section.draft? && section.last_updated_by
text << " by #{section.last_updated_by}"
end

text
end

def publish_text(manual, slug_unique)
if manual.state == "published"
text = "<p>There are no changes to publish.</p>"
Expand Down
34 changes: 32 additions & 2 deletions app/views/manuals/confirm_publish.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% draft_sections = manual.sections.select(&:draft?) %>

<% content_for :page_title, manual.title %>
<% content_for :title, manual.title %>

Expand All @@ -24,8 +26,36 @@
title: "Publish #{manual.title}"
} %>

<p class="govuk-body govuk-!-margin-bottom-7">You are about to publish "<%= manual.title %>". All the sections which
are in draft status will be published.</p>
<p class="govuk-body">You are about to publish "<%= manual.title %>".
<%= if draft_sections.any? then " All the following sections, which are in draft status, will be published." end %></p>

<% if draft_sections.any? %>
<p class="govuk-body"></p>
<%= render "govuk_publishing_components/components/table", {
first_cell_is_header: true,
head: [
{
text: "Draft"
},
{
text: "Details"
}
],
rows: draft_sections.map do |section|
[
{
text: tag.span("DRAFT", class: "govuk-tag govuk-tag--s govuk-tag--blue") <<
tag.span(section.title, class: "govuk-!-static-margin-2")
},
{
text: last_updated_text(section)
}
]
end
} %>
<% end %>

<p class="govuk-body">Are you sure you want to publish this manual?</p>

<%= form_tag(publish_manual_path(manual), method: :post) do %>
<div class="govuk-button-group govuk-!-margin-bottom-6">
Expand Down
2 changes: 1 addition & 1 deletion app/views/manuals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<% end %>
<%= link_to(section.title, manual_section_path(manual, section), class: 'document-title') %>
<ul class="metadata">
<li class="text-muted">Updated <%= time_ago_in_words(section.updated_at) %> ago<%= if section.draft? and section.last_updated_by then " by #{section.last_updated_by}" end%></li>
<li class="text-muted"><%= last_updated_text(section) %></li>
</ul>
</li>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions features/publishing-a-manual.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Feature: Publishing a manual
Given I am logged in as an editor

Scenario: Publish a manual
Given a draft manual exists with some sections
Given a draft manual exists with a section titled "my test section"
When I click the publish manual button
Then I am asked to confirm the publishing
Then I am asked to confirm the publishing of a section titled "my test section"
When I confirm publishing the manual
Then the manual and all its sections are published
And I should see a link to the live manual
Expand Down
27 changes: 26 additions & 1 deletion features/step_definitions/manual_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@
WebMock::RequestRegistry.instance.reset!
end

Given(/^a draft manual exists with a section titled "(.*?)"$/) do |section_title|
@manual_slug = "guidance/example-manual-title"
@manual_title = "Example Manual Title"

@manual_fields = {
title: "Example Manual Title",
summary: "Nullam quis risus eget urna mollis ornare vel eu leo.",
}

create_manual(@manual_fields)

@attributes_for_sections = create_sections_for_manual(
manual_fields: @manual_fields,
section_titles: [section_title],
count: 2,
)

@manual = most_recently_created_manual
@sections = @manual.sections.to_a
@section = @sections.first

WebMock::RequestRegistry.instance.reset!
end

Given(/^a draft manual exists belonging to "(.*?)"$/) do |organisation_slug|
@manual_slug = "guidance/example-manual-title"
@manual_title = "Example Manual Title"
Expand Down Expand Up @@ -281,8 +305,9 @@
click_on "Publish manual"
end

Then(/^I am asked to confirm the publishing$/) do
Then(/^I am asked to confirm the publishing of a section titled "(.*?)"$/) do |section_title|
expect(page).to have_content("Publish #{@manual.title}")
expect(page).to have_content(section_title)
expect(page).to have_button("Publish")
end

Expand Down
8 changes: 6 additions & 2 deletions features/support/manual_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,13 @@ def check_manual_has_organisation_slug(attributes, organisation_slug)
expect(page.body).to have_content(organisation_slug)
end

def create_sections_for_manual(count:, manual_fields:)
def create_sections_for_manual(count:, manual_fields:, section_titles: [])
attributes_for_sections = (1..count).map do |n|
title = "Section #{n}"
title = if n <= section_titles.length
section_titles[n - 1]
else
"Section #{n}"
end

{
title:,
Expand Down
38 changes: 38 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,42 @@ def current_user_can_publish? = false
end
end
end

describe "#last_updated_text" do
let(:section) { instance_double(Section, updated_at: Time.zone.now) }

context "when section is not in draft state" do
before do
allow(section).to receive(:draft?).and_return(false)
end

it "returns text without author" do
text = last_updated_text(section)

expect(text).to eq("Updated less than a minute ago")
end
end

context "when section is in draft state" do
before do
allow(section).to receive(:draft?).and_return(true)
end

it "returns text including author, when the author is known" do
allow(section).to receive(:last_updated_by).and_return("Test User")

text = last_updated_text(section)

expect(text).to eq("Updated less than a minute ago by Test User")
end

it "returns text without author, when the author is not known" do
allow(section).to receive(:last_updated_by).and_return(nil)

text = last_updated_text(section)

expect(text).to eq("Updated less than a minute ago")
end
end
end
end

0 comments on commit 2462778

Please sign in to comment.