Skip to content

Commit

Permalink
Merge pull request #9630 from alphagov/content-modelling/679-return-t…
Browse files Browse the repository at this point in the history
…he-number-of-instances-on-a-page

Content modelling/679 return the number of instances on a page
  • Loading branch information
pezholio authored Nov 20, 2024
2 parents 55aea3a + 92e4e63 commit d04280a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ it out for now-->
href: sort_link("document_type"),
sort_direction: sort_direction("document_type"),
},
{
text: "Instances",
href: sort_link("instances"),
sort_direction: sort_direction("instances"),
},
{
text: "Unique pageviews",
href: sort_link("unique_pageviews"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def rows
{
text: content_item.document_type.humanize,
},
{
text: content_item.instances,
},
{
text: content_item.unique_pageviews ? number_to_human(content_item.unique_pageviews, format: "%n%u", precision: 3, significant: true, units: { thousand: "k", million: "m", billion: "b" }) : nil,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class HostContentItem < Data.define(
:last_edited_by_editor_id,
:last_edited_at,
:unique_pageviews,
:instances,
)

def last_edited_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def items
last_edited_by_editor_id: item["last_edited_by_editor_id"],
last_edited_at: item["last_edited_at"],
unique_pageviews: item["unique_pageviews"],
instances: item["instances"],
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableCompon
"last_edited_at" => Time.zone.now.to_s,
"publishing_organisation" => publishing_organisation,
"unique_pageviews" => unique_pageviews,
"instances" => 1,
)
end
let(:host_content_items) do
Expand Down Expand Up @@ -194,7 +195,7 @@ def self.it_returns_unknown_user
),
)

assert_selector "a.app-table__sort-link[href*='##{ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableComponent::TABLE_ID}']", count: 5
assert_selector "a.app-table__sort-link[href*='##{ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableComponent::TABLE_ID}']", count: 6
end

it "shows all the headers unordered by default" do
Expand All @@ -207,14 +208,15 @@ 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=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 ".govuk-table__header--active a", text: "Unique pageviews"
end

%w[title document_type unique_pageviews primary_publishing_organisation_title last_edited_at].each do |order|
%w[title document_type unique_pageviews primary_publishing_organisation_title last_edited_at instances].each do |order|
it "shows the link as selected when #{order} is in ascending order" do
render_inline(
described_class.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
last_edited_by_editor_id { SecureRandom.uuid }
last_edited_at { 2.days.ago.to_s }
unique_pageviews { 123 }
instances { 1 }

initialize_with do
new(title:,
Expand All @@ -17,7 +18,8 @@
publishing_app:,
last_edited_by_editor_id:,
last_edited_at:,
unique_pageviews:)
unique_pageviews:,
instances:)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ContentBlockManager::GetHostContentItemsTest < ActiveSupport::TestCase
"last_edited_by_editor_id" => SecureRandom.uuid,
"last_edited_at" => "2023-01-01T08:00:00.000Z",
"unique_pageviews" => 123,
"instances" => 1,
"primary_publishing_organisation" => {
"content_id" => SecureRandom.uuid,
"title" => "bar",
Expand Down Expand Up @@ -108,6 +109,7 @@ class ContentBlockManager::GetHostContentItemsTest < ActiveSupport::TestCase
assert_equal result[0].last_edited_by_editor_id, response_body["results"][0]["last_edited_by_editor_id"]
assert_equal result[0].last_edited_at, Time.zone.parse(response_body["results"][0]["last_edited_at"])
assert_equal result[0].unique_pageviews, response_body["results"][0]["unique_pageviews"]
assert_equal result[0].instances, response_body["results"][0]["instances"]

assert_equal result[0].publishing_organisation, expected_publishing_organisation
end
Expand Down

0 comments on commit d04280a

Please sign in to comment.