Skip to content

Commit

Permalink
Merge pull request #4186 from alphagov/fix-homepage_presenter-test
Browse files Browse the repository at this point in the history
Convert homepage_presenter test to spec
  • Loading branch information
KludgeKML authored Jul 31, 2024
2 parents c8518a7 + bc0c55e commit 7d0b5e7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 58 deletions.
59 changes: 59 additions & 0 deletions spec/unit/presenters/homepage_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
RSpec.describe HomepagePresenter do
let(:content_item) do
{
"links" => {
"popular_links" => [
{
"details" => {
"link_items" => [
{
"title" => "Some title",
"url" => "/some/path",
},
],
},
},
],
},
}
end

let(:subject) { described_class.new(content_item) }

context "#links" do
it "returns links" do
expect(subject.links).to eq(content_item["links"])
end
end

context "#popular_links" do
context "when popular links in the content item" do
it "memoizes popular links" do
expected_popular_links = subject.popular_links
content_item["links"].delete("popular_links")

expect(subject.popular_links).to eq(expected_popular_links)
end

it "returns popular links from the content item" do
expected_popular_links = content_item
.dig("links", "popular_links", 0, "details", "link_items")
.collect(&:with_indifferent_access)

expect(subject.popular_links).to eq(expected_popular_links)
end
end

context "when popular links not in the content item" do
before do
content_item["links"].delete("popular_links")
end

it "returns popular links from the locale file" do
expected_popular_links = I18n.t("homepage.index.popular_links")
.collect(&:with_indifferent_access)
expect(subject.popular_links).to eq(expected_popular_links)
end
end
end
end
58 changes: 0 additions & 58 deletions test/unit/presenters/homepage_presenter_test.rb

This file was deleted.

0 comments on commit 7d0b5e7

Please sign in to comment.