Skip to content

Commit

Permalink
Merge pull request #9691 from alphagov/content-modelling/699-update-v…
Browse files Browse the repository at this point in the history
…iew-page

(699) Update view page
  • Loading branch information
pezholio authored Dec 4, 2024
2 parents 735f221 + 55b3be4 commit 5d9f300
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@import "components/timeline-component";

@import "views/content_block_manager_header";
@import "views/content_block_manager_show";
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@

.timeline__latest {
@include govuk-font($size: 19, $weight: bold);
background: #ffdd00;
color: govuk-colour("white");
background: govuk-colour("blue");
padding: 0.25rem 0.5rem;
font-size: 1rem !important;
line-height: 1.25 !important;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.support-request-wrapper {
display: flex;

.govuk-button--secondary {
margin-left: auto;
margin-top: govuk-spacing(6);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def items
title_item,
*details_items,
organisation_item,
last_updated_item,
status_item,
(instructions_item if content_block_document.latest_edition.instructions_to_publishers.present?),
embed_code_item,
].compact
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2 class="govuk-heading-l">Previous updates</h2>
<h2 class="govuk-heading-l">Change history</h2>

<div class="timeline">
<% items.each_with_index do |item, i| %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def items
content_block_versions.reject { |version| version.state.nil? }.map do |version|
{
title: title(version),
byline: User.find_by_id(version.whodunnit)&.name || "unknown user",
byline: User.find_by_id(version.whodunnit)&.then { |user| helpers.linked_author(user, { class: "govuk-link" }) } || "unknown user",
date: time_html(version.created_at),
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it out for now-->
sort_direction: sort_direction("title"),
},
{
text: "Document Type",
text: "Type",
href: sort_link("document_type"),
sort_direction: sort_direction("document_type"),
},
Expand All @@ -23,17 +23,17 @@ it out for now-->
sort_direction: sort_direction("instances"),
},
{
text: "Unique pageviews",
text: "Views (30 days)",
href: sort_link("unique_pageviews"),
sort_direction: sort_direction("unique_pageviews"),
},
{
text: "Publishing organisation",
text: "Lead organisation",
href: sort_link("primary_publishing_organisation_title"),
sort_direction: sort_direction("primary_publishing_organisation_title"),
},
{
text: "Updated",
text: "Last updated",
href: sort_link("last_edited_at"),
sort_direction: sort_direction("last_edited_at"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ def items
*details_items,
organisation_item,
instructions_item,
last_updated_item,
status_item,
embed_code_item,
state_item,
scheduled_item,
].compact
end

Expand Down Expand Up @@ -69,31 +67,26 @@ def details_items
end
end

def last_updated_item
{
field: "Last updated",
value: last_updated_value,
}
def status_item
if content_block_document.latest_edition.state == "scheduled"
{
field: "Status",
value: scheduled_value,
}
else
{
field: "Status",
value: last_updated_value,
}
end
end

def last_updated_value
"#{time_ago_in_words(content_block_document.latest_edition.updated_at)} ago by #{content_block_document.latest_edition.creator.name}"
"Published #{time_ago_in_words(content_block_document.latest_edition.updated_at)} ago by #{content_block_document.latest_edition.creator.name}"
end

def state_item
{
field: "State",
value: content_block_document.latest_edition.state.titleize,
}
end

def scheduled_item
if content_block_document.latest_edition.state == "scheduled"
{
field: "Scheduled for publication at",
value: I18n.l(content_block_document.latest_edition.scheduled_publication, format: :long_ordinal),
}
end
def scheduled_value
"Scheduled for publication at #{I18n.l(content_block_document.latest_edition.scheduled_publication, format: :long_ordinal)}"
end

def edit_action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<% content_for :context, product_name %>
<% content_for :title, "Manage #{add_indefinite_article @content_block_document.block_type.humanize}" %>
<% content_for :context, "View #{@content_block_document.block_type.humanize.downcase}" %>
<% content_for :title, @content_block_document.title %>
<% content_for :back_link do %>
<%= render "govuk_publishing_components/components/back_link", {
href: content_block_manager.content_block_manager_content_block_documents_path,
} %>
<% end %>
<% content_for :title_side do %>
<div class="support-request-wrapper">
<%= render "govuk_publishing_components/components/button", {
text: "Raise a support request",
href: support_url,
secondary_solid: true,
} %>
</div>
<% end %>

<%=
render(
Expand All @@ -29,7 +38,7 @@
<div class="govuk-grid-column-full">
<%= render(
ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableComponent.new(
caption: "Content appears in",
caption: "List of locations",
host_content_items: @host_content_items,
current_page: @page,
order: @order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
end

Then("I should see the details for the email address content block") do
assert_text "Manage an Email address"
assert_text "View email address"

should_show_summary_list_for_email_address_content_block(
@content_block.document.title,
Expand Down Expand Up @@ -367,7 +367,7 @@ def should_show_summary_list_for_email_address_content_block(document_title, ema
expect(page).to have_selector(".govuk-summary-list__key", text: "Instructions to publishers")
expect(page).to have_selector(".govuk-summary-list__value", text: instructions_to_publishers)
end
expect(page).to have_selector(".govuk-summary-list__key", text: "Last updated")
expect(page).to have_selector(".govuk-summary-list__key", text: "Status")
expect(page).to have_selector(".govuk-summary-list__value", text: @user.name)
end

Expand Down Expand Up @@ -465,7 +465,7 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
end

Then(/^I should see the dependent content listed$/) do
assert_text "Content appears in"
assert_text "List of locations"

@dependent_content.each do |item|
assert_text item["title"]
Expand Down Expand Up @@ -625,12 +625,12 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_

Then("published state of the object is shown") do
visit content_block_manager.content_block_manager_content_block_document_path(@content_block.document)
expect(page).to have_selector(".govuk-summary-list__key", text: "State")
expect(page).to have_selector(".govuk-summary-list__key", text: "Status")
expect(page).to have_selector(".govuk-summary-list__value", text: "Published")
end

Then("I should see the scheduled date on the object") do
expect(page).to have_selector(".govuk-summary-list__key", text: "Scheduled for publication at")
expect(page).to have_selector(".govuk-summary-list__key", text: "Status")
expect(page).to have_selector(".govuk-summary-list__value", text: I18n.l(@future_date, format: :long_ordinal).squish)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class ContentBlockManager::ContentBlock::Document::Index::SummaryCardComponentTe
assert_no_selector ".govuk-summary-list__key", text: "Instructions to publishers"
assert_no_selector ".govuk-summary-list__value", text: "None"

assert_selector ".govuk-summary-list__key", text: "Last updated"
assert_selector ".govuk-summary-list__value", text: "1 day ago by #{content_block_edition.creator.name}"
assert_selector ".govuk-summary-list__key", text: "Status"
assert_selector ".govuk-summary-list__value", text: "Published 1 day ago by #{content_block_edition.creator.name}"

assert_selector ".govuk-summary-list__row[data-module='copy-embed-code']", text: "Embed code"
assert_selector ".govuk-summary-list__row[data-embed-code='#{content_block_document.embed_code}']", text: "Embed code"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require "test_helper"

class ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineComponentTest < ViewComponent::TestCase
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
include ApplicationHelper

test "renders a timeline component with events in correct order" do
@user = create(:user)
@version_1 = create(
Expand Down Expand Up @@ -28,12 +32,12 @@ class ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineCompone
assert_selector ".timeline__item", count: 2

assert_equal "Email address scheduled", page.all(".timeline__title")[0].text
assert_equal "by #{@user.name}", page.all(".timeline__byline")[0].text
assert_equal "by #{linked_author(@user, { class: 'govuk-link' })}", page.all(".timeline__byline")[0].native.inner_html
assert_equal I18n.l(@version_3.created_at, format: :long_ordinal),
page.all("time[datetime='#{@version_3.created_at.iso8601}']")[1].text

assert_equal "Email address published", page.all(".timeline__title")[1].text
assert_equal "by #{@user.name}", page.all(".timeline__byline")[1].text
assert_equal "by #{linked_author(@user, { class: 'govuk-link' })}", page.all(".timeline__byline")[1].native.inner_html
assert_equal I18n.l(@version_2.created_at, format: :long_ordinal),
page.all("time[datetime='#{@version_2.created_at.iso8601}']")[1].text
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ def self.it_returns_unknown_user
)

assert_selector "a.app-table__sort-link[href*='order=title']", text: "Title"
assert_selector "a.app-table__sort-link[href*='order=document_type']", text: "Document Type"
assert_selector "a.app-table__sort-link[href*='order=document_type']", text: "Type"
assert_selector "a.app-table__sort-link[href*='order=instances']", text: "Instances"
assert_selector "a.app-table__sort-link[href*='order=unique_pageviews']", text: "Unique pageviews"
assert_selector "a.app-table__sort-link[href*='order=primary_publishing_organisation_title']", text: "Publishing organisation"
assert_selector "a.app-table__sort-link[href*='order=last_edited_at']", text: "Updated"
assert_selector "a.app-table__sort-link[href*='order=unique_pageviews']", text: "Views (30 days)"
assert_selector "a.app-table__sort-link[href*='order=primary_publishing_organisation_title']", text: "Lead organisation"
assert_selector "a.app-table__sort-link[href*='order=last_edited_at']", text: "Last updated"

assert_selector ".govuk-table__header--active a", text: "Unique pageviews"
assert_selector ".govuk-table__header--active a", text: "Views (30 days)"
end

%w[title document_type unique_pageviews primary_publishing_organisation_title last_edited_at instances].each do |order|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ContentBlockManager::ContentBlock::Document::Show::SummaryListComponentTes
it "renders a published content block correctly" do
render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryListComponent.new(content_block_document:))

assert_selector ".govuk-summary-list__row", count: 9
assert_selector ".govuk-summary-list__row", count: 8
assert_selector ".govuk-summary-list__actions", count: 1

assert_selector ".govuk-summary-list__key", text: "Email address details"
Expand All @@ -39,8 +39,8 @@ class ContentBlockManager::ContentBlock::Document::Show::SummaryListComponentTes
assert_selector ".govuk-summary-list__key", text: "Lead organisation"
assert_selector ".govuk-summary-list__value", text: "Department for Example"

assert_selector ".govuk-summary-list__key", text: "Last updated"
assert_selector ".govuk-summary-list__value", text: "1 day ago by #{content_block_edition.creator.name}"
assert_selector ".govuk-summary-list__key", text: "Status"
assert_selector ".govuk-summary-list__value", text: "Published 1 day ago by #{content_block_edition.creator.name}"

assert_selector ".govuk-summary-list__key", text: "Instructions to publishers"
assert_selector ".govuk-summary-list__value", text: "None"
Expand All @@ -49,20 +49,17 @@ class ContentBlockManager::ContentBlock::Document::Show::SummaryListComponentTes
assert_selector ".govuk-summary-list__row[data-embed-code='#{content_block_document.embed_code}']", text: "Embed code"
assert_selector ".govuk-summary-list__key", text: "Embed code"
assert_selector ".govuk-summary-list__value", text: content_block_document.embed_code

assert_selector ".govuk-summary-list__key", text: "State"
assert_selector ".govuk-summary-list__value", text: content_block_edition.state.titleize
end

it "renders a scheduled content block correctly" do
content_block_document.latest_edition.state = "scheduled"

render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryListComponent.new(content_block_document:))

assert_selector ".govuk-summary-list__row", count: 10
assert_selector ".govuk-summary-list__row", count: 8

assert_selector ".govuk-summary-list__key", text: "Scheduled for publication at"
assert_selector ".govuk-summary-list__value", text: I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)
assert_selector ".govuk-summary-list__key", text: "Status"
assert_selector ".govuk-summary-list__value", text: "Scheduled for publication at #{I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)}"
end

describe "when there are instructions to publishers" do
Expand Down

0 comments on commit 5d9f300

Please sign in to comment.