Skip to content

Commit

Permalink
Show contents list when first item has an image
Browse files Browse the repository at this point in the history
  • Loading branch information
emmabeynon committed Jan 24, 2018
1 parent a93ae17 commit d8cc89d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/presenters/content_item/contents_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def show_content_list?
return false unless contents_items.count > 1
contents_items.count > 2 ||
first_item_has_long_table? ||
first_item_has_image? ||
first_item_has_long_content?
end

Expand Down Expand Up @@ -67,8 +68,14 @@ def find_table
end
end

def first_item_has_image?
element = first_item.next_element

until element.name == 'h2'
if element.name == 'div' && element['class'] == 'img'
return true
else
current_element = current_element.next_element
element = element.next_element
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/presenters/content_item/contents_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,16 @@ def body
end
refute @contents_list.show_content_list?
end

test "#show_content_list? returns true if image is present in the first item" do
class << @contents_list
def body
"<h2 id='one'>One</h2>
<div class='img'><img src='www.gov.uk/img.png'></div>
<h2 id='two'>Two</h2>
<p>#{Faker::Lorem.sentence}</p>"
end
end
assert @contents_list.show_content_list?
end
end

0 comments on commit d8cc89d

Please sign in to comment.