diff --git a/config/navigation.json b/config/navigation.json index d37d08c1..2d2a7d83 100644 --- a/config/navigation.json +++ b/config/navigation.json @@ -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": "\"Three" } } ] diff --git a/lib/entities/empty_state.rb b/lib/entities/empty_state.rb index 8a59ede5..64e7538a 100644 --- a/lib/entities/empty_state.rb +++ b/lib/entities/empty_state.rb @@ -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 + "\"Pile" + end + end end diff --git a/spec/lib/entities/empty_state_spec.rb b/spec/lib/entities/empty_state_spec.rb index 9c3e2c5d..692ac7a7 100644 --- a/spec/lib/entities/empty_state_spec.rb +++ b/spec/lib/entities/empty_state_spec.rb @@ -1,9 +1,10 @@ describe Entities::Page::EmptyState do let(:default_heading) { "You have no items." } let(:default_message) { "See what you can borrow from the library." } + let(:default_image) { "\"Pile" } 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 @@ -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 diff --git a/views/empty_state.erb b/views/empty_state.erb index 75d47237..afe37828 100644 --- a/views/empty_state.erb +++ b/views/empty_state.erb @@ -11,6 +11,6 @@
- Pile of books + <%=empty_state.image%>