Skip to content

Commit

Permalink
Add Update Important Note functionality
Browse files Browse the repository at this point in the history
- Add cancel link and important note information.
- Add hidden field tag for note type.
- Conditionally render _important_note partial if note exists
- Include original important note text in update important note text area
  • Loading branch information
ellohez authored and PeterHattyar committed Feb 25, 2025
1 parent dcfa5c9 commit 9c7f484
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ def add_edition_note
render "secondary_nav_tabs/add_edition_note"
end

def update_important_note
render "secondary_nav_tabs/update_important_note"
end

def destroy
@resource.destroy!
flash[:success] = "Edition deleted"
Expand Down
6 changes: 6 additions & 0 deletions app/views/editions/_important_note.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= render "govuk_publishing_components/components/notice", {
description_govspeak: sanitize("<p class='govuk-body govuk-!-font-weight-bold govuk-!-text-break-word'>#{h(@edition.important_note&.comment)}</p>") +
sanitize("<p class='govuk-body-m'>#{h(User.find_by(id: @edition.important_note&.requester_id)&.name)} added an important note on
#{h(@edition.important_note&.created_at&.strftime("%d %B %Y"))}</p>"),
show_banner_title: true
} %>
6 changes: 6 additions & 0 deletions app/views/editions/secondary_nav_tabs/_history.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
margin_bottom: 3,
href: history_add_edition_note_edition_path,
}),
(render "govuk_publishing_components/components/button", {
text: "Update important note",
margin_bottom: 3,
secondary_solid: true,
href: history_update_important_note_edition_path,
}),
],
} %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<% @edition = @resource %>
<% content_for :title_context, @edition.title %>
<% content_for :page_title, "Update important note" %>
<% content_for :title, "Update important note" %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<p class="govuk-body">Add important notes that anyone who works on this edition needs to see, eg “(Doesn’t) need fact check, don’t publish.”.
Each edition can have only one important note at a time.</p>

<%= form_for(:note, :url=> notes_path) do |f| %>
<%= hidden_field_tag :edition_id, resource.id %>
<%= hidden_field_tag "note[type]", Action::IMPORTANT_NOTE %>

<%= render "govuk_publishing_components/components/textarea", {
label: {
heading_size: "m",
text: "Important note",
},
name: "note[comment]",
rows: 14,
value: @edition.important_note&.comment,
} %>

<div class="govuk-button-group">
<%= render "govuk_publishing_components/components/button", {
text: "Save",
} %>
<%= link_to("Cancel", history_edition_path, class: "govuk-link govuk-link--no-visited-state") %>
</div>
<% end %>
</div>
</div>
12 changes: 10 additions & 2 deletions app/views/editions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds editions__edit__summary">
<%= render "govuk_publishing_components/components/summary_list", {
items: document_summary_items(@resource),
<%= render "govuk_publishing_components/components/summary_list", {
items: document_summary_items(@resource),
} %>
</div>

<div>
<%= render "govuk_publishing_components/components/notice", {
title: @edition.important_note.comment,
description_govspeak: sanitize("<p>#{User.find_by(id: @edition.important_note.requester_id).name} added an important note on #{@edition.important_note.created_at.strftime("%d %B %Y")}</p>"),
show_banner_title: true
} %>
</div>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
get "metadata"
get "history"
get "history/add_edition_note", to: "editions#add_edition_note", as: "history/add_edition_note"
get "history/update_important_note", to: "editions#update_important_note", as: "history/update_important_note"
get "admin"
post "duplicate"
get "related_external_links"
Expand Down
21 changes: 21 additions & 0 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ class NotesControllerTest < ActionController::TestCase
end
end

context "when an Important note is provided" do
should "confirm the note was successfully recorded" do
post :create,
params: {
edition_id: @edition.id,
note: {
type: "important_note",
comment: @note_text,
},
}

@edition.reload

assert_equal(@note_text, @edition.important_note.comment)
assert_redirected_to history_edition_path(@edition)
assert_includes flash[:success], "Note recorded"
end
end

# TODO: Test that a blank note is saved and message is "Note resolved"

context "Welsh editors" do
setup do
login_as_welsh_editor
Expand Down
62 changes: 62 additions & 0 deletions test/integration/edition_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class EditionEditTest < IntegrationTest
assert_selector(".govuk-summary-list__value", text: @draft_edition.assignee)
end
end

should "display the important note if an important note exists" do
setup do
@note_text = "This is really really urgent!"
create_important_note_for_edition(@published_edition, @note_text)
end

assert page.has_text?("Important")
assert page.has_text?(@note_text)
end
end

context "edit assignee page" do
Expand Down Expand Up @@ -133,6 +143,16 @@ class EditionEditTest < IntegrationTest

assert_current_path history_add_edition_note_edition_path(@draft_edition.id)
end

should "show an 'Update important note' button" do
assert page.has_link?("Update important note")
end

should "navigate to the 'Update important note' page when the button is clicked" do
click_link("Update important note")

assert_current_path history_update_important_note_edition_path(@draft_edition.id)
end
end

context "Add edition note page" do
Expand Down Expand Up @@ -161,6 +181,39 @@ class EditionEditTest < IntegrationTest
end
end

context "Update important note page" do
setup do
visit_draft_edition
click_link("History and notes")
click_link("Update important note")
end

should "render the 'Update important note' page" do
within :css, ".gem-c-heading" do
assert page.has_css?("h1", text: "Update important note")
assert page.has_css?(".gem-c-heading__context", text: @draft_edition.title)
end

assert page.has_text?("Add important notes that anyone who works on this edition needs to see, eg “(Doesn’t) need fact check, don’t publish.”.")
assert page.has_text?("Each edition can have only one important note at a time.")

within :css, ".gem-c-textarea" do
assert page.has_css?("label", text: "Important note")
assert page.has_css?("textarea")
end

assert page.has_button?("Save")
assert page.has_link?("Cancel")
end

should "pre-populate with the existing note" do
create_important_note_for_edition(@draft_edition, "An updated note")
click_link("Update important note")

assert page.has_field?("Important note", with: "An updated note")
end
end

context "unpublish tab" do
context "user does not have required permissions" do
setup do
Expand Down Expand Up @@ -905,4 +958,13 @@ def visit_old_edition_of_published_edition
)
visit edition_path(published_edition)
end

def create_important_note_for_edition(edition, note_text)
FactoryBot.create(
:action,
request_type: Action::IMPORTANT_NOTE,
edition: edition,
comment: note_text,
)
end
end

0 comments on commit 9c7f484

Please sign in to comment.