Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/views/admin/editions/_page_address_controls.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
<%= render "govuk_publishing_components/components/hint", {
text: "The title of this document has changed since the page URL was generated. Check the box below to keep the existing URL, or leave it unchecked to update the URL for this page to match the new title when you publish this edition.",
} %>
<%= hidden_field(:edition, :slug_override, value: "") %>
<%= hidden_field(:edition, :slug_override, value: ((edition.document.live_edition.slug != edition.slug_from_title) && edition.document.live_edition.slug)) %>

<%= render "govuk_publishing_components/components/checkboxes", {
name: "edition[slug_override]",
items: [
{
label: "Keep the current page URL",
value: edition.document.live_edition.slug,
checked: edition.slug_override.present?,
label: "Keep the freshly generated title-based URL",
value: "",
checked: (edition.document.live_edition.slug != edition.slug_from_title) && edition.slug_override == "",
},
],
} %>
Expand Down
150 changes: 138 additions & 12 deletions features/edition-update-slug.feature
Original file line number Diff line number Diff line change
@@ -1,18 +1,144 @@
Feature: Edition update slug
Scenario: Writer updates the title of a document
# @javascript
# The live editions slug_override is nil / no inherited override
Scenario: Writer keeps live slug when updating the title of a document
Given I am a writer
And a published publication "You will never guess" exists
When I edit the publication "You will never guess"
And I change the title to "Ten facts that will shock you"
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I choose to keep the live slug
When I click save
Then I see an unchecked checkbox for opting in to the title based slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "Ten facts that will shock you" contains "ten-facts-that-will-shock-you"
Then I can see the preview URL of the publication "New title" contains "previously-published"

@javascript
Scenario: Writer updates the title of a document and opts out of slug update
# @javascript
# The live editions slug_override is nil / no inherited override
Scenario: Writer chooses to use title-based slug when updating the title of a document
Given I am a writer
And a published publication "You will never guess" exists
When I edit the publication "You will never guess"
And I change the title to "Ten facts that will shock you"
And I opt out of updating the slug
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I opt in to use the title based slug
When I click save
Then I see a checked checkbox for opting in to the title based slug
When I save the edition and go to the document summary
Then I can see the preview URL of the publication "New title" contains "new-title"

# @javascript
# The live editions slug_override is nil or blank, but from previous user choice.
Scenario: Writer redrafts and saves a published edition with title based slug
Given I am a writer
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I opt in to use the title based slug
And I save the edition and go to the document summary
Then I force publish the publication "New title"
When I edit the publication "New title"
Then I see an unchecked checkbox for opting in to the title based slug
When I click save
Then I see an unchecked checkbox for opting in to the title based slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "New title" contains "new-title"

# @javascript
# The live editions slug_override is nil or blank, but from previous user choice.
Scenario: Writer redrafts and publishes a published edition with title based slug - and changes title, opting to use title based slug
Given I am a writer
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I opt in to use the title based slug
And I save the edition and go to the document summary
Then I force publish the publication "New title"
When I edit the publication "New title"
Then I see an unchecked checkbox for opting in to the title based slug
# Then I see no checkbox to opt in to the title based slug - if js
And I change the title to "Changed title"
And I opt in to use the title based slug
When I click save
Then I see a checked checkbox for opting in to the title based slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "Changed title" contains "changed-title"

# @javascript
# The live editions slug_override is nil or blank, but from previous user choice.
Scenario: Writer redrafts and views a published edition with title based slug - and changes title, opting to use live slug
Given I am a writer
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I opt in to use the title based slug
And I save the edition and go to the document summary
Then I force publish the publication "New title"
When I edit the publication "New title"
Then I see an unchecked checkbox for opting in to the title based slug
# Then I see no checkbox to opt in to the title based slug - if js
And I change the title to "Changed title"
And I choose to keep the live slug
When I click save
Then I see an unchecked checkbox for opting in to the title based slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "Changed title" contains "new-title"

# @javascript
# The live editions slug_override is set to a custom slug, not title based
Scenario: Writer redrafts and saves a published edition with custom slug
Given I am a writer
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I choose to keep the live slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "New title" contains "previously-published"
Then I force publish the publication "New title"
When I edit the publication "New title"
# Then I see no checkbox to opt in to the title based slug - if js
Then I see an unchecked checkbox for opting in to the title based slug
When I click save
Then I see an unchecked checkbox for opting in to the title based slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "New title" contains "previously-published"

# @javascript
# The live editions slug_override is set to a custom slug, not title based
Scenario: Writer redrafts and saves a published edition with custom slug - and changes title, opting to keep live slug
Given I am a writer
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I choose to keep the live slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "New title" contains "previously-published"
Then I force publish the publication "New title"
When I edit the publication "New title"
# Then I see no checkbox to opt in to the title based slug - if js
Then I see an unchecked checkbox for opting in to the title based slug
Then I change the title to "Changed title"
And I choose to keep the live slug
When I click save
Then I see an unchecked checkbox for opting in to the title based slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "Changed title" contains "previously-published"

# @javascript
# The live editions slug_override is set to a custom slug, not title based
Scenario: Writer redrafts and saves a published edition with custom slug - and changes title, opting to keep title based slug
Given I am a writer
And a published publication "Previously published" exists
When I edit the publication "Previously published"
And I change the title to "New title"
And I choose to keep the live slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "New title" contains "previously-published"
Then I force publish the publication "New title"
When I edit the publication "New title"
# Then I see no checkbox to opt in to the title based slug - if js
Then I see an unchecked checkbox for opting in to the title based slug
Then I change the title to "Changed title"
And I opt in to use the title based slug
When I click save
Then I see a checked checkbox for opting in to the title based slug
And I save the edition and go to the document summary
Then I can see the preview URL of the publication "Ten facts that will shock you" contains "you-will-never-guess"
Then I can see the preview URL of the publication "Changed title" contains "changed-title"
19 changes: 15 additions & 4 deletions features/step_definitions/publication_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,23 @@
fill_in "Title", with: new_title
end

When("I opt out of updating the slug") do
check "Keep the current page URL"
When("I opt in to use the title based slug") do
check "Keep the freshly generated title-based URL"
end

Then("I cannot opt out of updating the slug") do
expect(page).not_to have_selector("label", text: "Keep the current page URL")
When("I choose to keep the live slug") do
end

And("I see an unchecked checkbox for opting in to the title based slug") do
expect(page).to have_field("edition[slug_override]", checked: false)
end

And("I see a checked checkbox for opting in to the title based slug") do
expect(page).to have_field("edition[slug_override]", checked: true)
end

Then("I see the \"Live address\" including \"previously-published\"") do
# TODO
end

When("I save the edition and go to the document summary") do
Expand Down
Loading