Skip to content

Commit

Permalink
Adding image option to empty_state
Browse files Browse the repository at this point in the history
  • Loading branch information
erinesullivan committed Nov 2, 2023
1 parent 4f36939 commit 14340c9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"sidebar": "false",
"slug": "none",
"empty_state": {
"heading": "The page you were looking for could not be found"
"heading": "The page you were looking for could not be found",
"image": "<img src=\"/not-found-v2.png\" alt=\"Three airplanes searching with spotlights\" />"
}
}
]
10 changes: 10 additions & 0 deletions lib/entities/empty_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ def heading_tag
"h3"
end
end

def image
if @empty_state&.key?("image")
@empty_state["image"]
elsif @parent_empty_state&.image
@parent_empty_state.image
else
"<img src=\"/not-found.png\" alt=\"Pile of books\" />"
end
end
end
21 changes: 20 additions & 1 deletion spec/lib/entities/empty_state_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
describe Entities::Page::EmptyState do
let(:default_heading) { "You have no items." }
let(:default_message) { "See <a href=\"https://www.lib.umich.edu/find-borrow-request\">what you can borrow from the library</a>." }
let(:default_image) { "<img src=\"/not-found.png\" alt=\"Pile of books\" />" }

before(:each) do
@empty_state = {"heading" => "This is a heading", "message" => "This is a message."}
@empty_state = {"heading" => "This is a heading", "message" => "This is a message.", "image" => "This is an image."}
@parent_empty_state = nil
end
subject do
Expand Down Expand Up @@ -54,4 +55,22 @@
expect(subject.heading_tag).to eq("h3")
end
end
context "#image" do
it "handles given empty state" do
expect(subject.image).to eq(@empty_state["image"])
end
it "handles nil" do
@empty_state = nil
expect(subject.image).to eq(default_image)
end
it "if nil, uses parent if available" do
@empty_state = nil
@parent_empty_state = described_class.new({"image" => "Parent Image"}, nil)
expect(subject.image).to eq(@parent_empty_state.image)
end
it "uses default if missing" do
@empty_state.delete("image")
expect(subject.image).to eq(default_image)
end
end
end
2 changes: 1 addition & 1 deletion views/empty_state.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</div>
<div class="empty-state-image">
<img src="/not-found.png" alt="Pile of books" />
<%=empty_state.image%>
</div>
</section>

0 comments on commit 14340c9

Please sign in to comment.