Skip to content

Commit

Permalink
Merge pull request #8978 from alphagov/1057-slugless-republish-tasks
Browse files Browse the repository at this point in the history
Add UI for remaining page republishing tasks
  • Loading branch information
brucebolt authored Apr 23, 2024
2 parents 8101afc + 6194d1e commit 83e8f56
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 26 deletions.
26 changes: 18 additions & 8 deletions app/controllers/admin/republishing_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,23 @@ def enforce_permissions!
end

def republishable_pages
historical_accounts_index_presenter = PublishingApi::HistoricalAccountsIndexPresenter.new

[{
title: historical_accounts_index_presenter.content[:title],
public_path: historical_accounts_index_presenter.base_path,
slug: historical_accounts_index_presenter.base_path.split("/").last,
presenter: "PublishingApi::HistoricalAccountsIndexPresenter",
}]
[
"PublishingApi::HistoricalAccountsIndexPresenter",
"PublishingApi::HowGovernmentWorksPresenter",
"PublishingApi::OperationalFieldsIndexPresenter",
"PublishingApi::MinistersIndexPresenter",
"PublishingApi::EmbassiesIndexPresenter",
"PublishingApi::WorldIndexPresenter",
"PublishingApi::OrganisationsIndexPresenter",
].map do |presenter_class_string|
presenter_instance = presenter_class_string.constantize.new

{
title: presenter_instance.content[:title],
public_path: presenter_instance.base_path,
slug: presenter_instance.base_path.split("/").last,
presenter: presenter_class_string,
}
end
end
end
4 changes: 2 additions & 2 deletions app/presenters/publishing_api/embassies_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def links
{ parent: [WORLD_INDEX_CONTENT_ID] }
end

private

def base_path
"/world/embassies"
end

private

def details
{
world_locations: world_locations.map do |embassy|
Expand Down
8 changes: 4 additions & 4 deletions app/presenters/publishing_api/ministers_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def links
}
end

def base_path
"/government/ministers"
end

private

def details
Expand All @@ -60,10 +64,6 @@ def details
end
end

def base_path
"/government/ministers"
end

def reshuffle_in_progress?
SitewideSetting.find_by(key: :minister_reshuffle_mode)&.on || false
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/republishing/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
text: link_to(page[:title], Plek.website_root + page[:public_path], class:"govuk-link"),
},
{
text: link_to(sanitize("Republish #{tag.span('\'' + page[:title] + '\' page', class: 'govuk-visually-hidden')}"),
text: link_to(sanitize("Republish #{tag.span('the \'' + page[:title] + '\' page', class: 'govuk-visually-hidden')}"),
admin_republishing_page_confirm_path(page[:slug]),
id: "republish-" + page[:slug],
class: "govuk-link",
Expand Down
46 changes: 41 additions & 5 deletions features/republishing-content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,47 @@ Feature: Republishing published documents
Background:
Given I am a GDS admin

Scenario: Republish the "Past prime ministers" page
Given a published publication "Past prime ministers" exists
And the "Past prime ministers" page can be republished
When I request a republish of the "Past prime ministers" page
Then I can see the "Past prime ministers" page has been scheduled for republishing
Scenario: Republish the "Past Prime Ministers" page
Given a published publication "Past Prime Ministers" exists
And the "Past Prime Ministers" page can be republished
When I request a republish of the "Past Prime Ministers" page
Then I can see the "Past Prime Ministers" page has been scheduled for republishing

Scenario: Republish the "How government works" page
Given a published publication "How government works" exists
And the "How government works" page can be republished
When I request a republish of the "How government works" page
Then I can see the "How government works" page has been scheduled for republishing

Scenario: Republish the "Fields of operation" page
Given a published publication "Fields of operation" exists
And the "Fields of operation" page can be republished
When I request a republish of the "Fields of operation" page
Then I can see the "Fields of operation" page has been scheduled for republishing

Scenario: Republish the "Ministers" page
Given a published publication "Ministers" exists
And the "Ministers" page can be republished
When I request a republish of the "Ministers" page
Then I can see the "Ministers" page has been scheduled for republishing

Scenario: Republish the "Find a British embassy, high commission or consulate" page
Given a published publication "Find a British embassy, high commission or consulate" exists
And the "Find a British embassy, high commission or consulate" page can be republished
When I request a republish of the "Find a British embassy, high commission or consulate" page
Then I can see the "Find a British embassy, high commission or consulate" page has been scheduled for republishing

Scenario: Republish the "Help and services around the world" page
Given a published publication "Help and services around the world" exists
And the "Help and services around the world" page can be republished
When I request a republish of the "Help and services around the world" page
Then I can see the "Help and services around the world" page has been scheduled for republishing

Scenario: Republish the "Departments, agencies and public bodies" page
Given a published publication "Departments, agencies and public bodies" exists
And the "Departments, agencies and public bodies" page can be republished
When I request a republish of the "Departments, agencies and public bodies" page
Then I can see the "Departments, agencies and public bodies" page has been scheduled for republishing

Scenario: Republish an organisation
Given a published organisation "An Existing Organisation" exists
Expand Down
27 changes: 22 additions & 5 deletions features/step_definitions/republishing_content_steps.rb.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Given(/^the "Past prime ministers" page can be republished$/) do
Given(/^the "([^"]*)" page can be republished$/) do |_page_title|
create(:ministerial_role, name: "Prime Minister", cabinet_member: true)
end

When(/^I request a republish of the "Past prime ministers" page$/) do
When(/^I request a republish of the "([^"]*)" page$/) do |page_title|
visit admin_republishing_index_path
find("#republish-past-prime-ministers").click
find(republishing_link_id_from_page_title(page_title)).click
click_button("Confirm republishing")
end

Then(/^I can see the "Past prime ministers" page has been scheduled for republishing/) do
expect(page).to have_selector(".gem-c-success-alert", text: "The 'Past Prime Ministers' page has been scheduled for republishing")
Then(/^I can see the "([^"]*)" page has been scheduled for republishing/) do |page_title|
expect(page).to have_selector(".gem-c-success-alert", text: "The '#{page_title}' page has been scheduled for republishing")
end

Given(/^a published organisation "An Existing Organisation" exists$/) do
Expand All @@ -31,3 +31,20 @@
Then(/^I can see the "An Existing Organisation" organisation has been scheduled for republishing/) do
expect(page).to have_selector(".gem-c-success-alert", text: "The 'An Existing Organisation' organisation has been scheduled for republishing")
end

def republishing_link_id_from_page_title(page_title)
link_id = "#republish-"

link_id += case page_title
when "Find a British embassy, high commission or consulate"
"embassies"
when "Help and services around the world"
"world"
when "Departments, agencies and public bodies"
"organisations"
else
page_title.downcase.gsub(" ", "-")
end

link_id
end
2 changes: 1 addition & 1 deletion test/functional/admin/republishing_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
get :index

assert_select ".govuk-table:nth-of-type(1) .govuk-table__cell:nth-child(1) a[href='https://www.test.gov.uk/government/history/past-prime-ministers']", text: "Past Prime Ministers"
assert_select ".govuk-table:nth-of-type(1) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/page/past-prime-ministers/confirm']", text: "Republish 'Past Prime Ministers' page"
assert_select ".govuk-table:nth-of-type(1) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/page/past-prime-ministers/confirm']", text: "Republish the 'Past Prime Ministers' page"

assert_select ".govuk-table:nth-of-type(2) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/organisation/find']", text: "Republish an organisation"

Expand Down

0 comments on commit 83e8f56

Please sign in to comment.