31 lines
1.5 KiB
Ruby
31 lines
1.5 KiB
Ruby
require 'liquid'
|
|
require 'nokogiri'
|
|
require_relative '../../_plugins/gallery_items'
|
|
require_relative '../../_plugins/lazy_images'
|
|
|
|
class GalleryRenderer
|
|
include GalleryItems
|
|
include LazyImages
|
|
end
|
|
|
|
renderer = GalleryRenderer.new
|
|
batch = '<div id="photo-batch"></div>' +
|
|
'<p><img src="/img/arts/uploads/batch/00.jpg" alt="first"></p>' +
|
|
'<p><img src="/img/arts/uploads/batch/01.jpg" alt="second"></p>' +
|
|
'<span class="image-details">A & B<br>Caption</span>'
|
|
items = renderer.gallery_items(renderer.lazy_images(batch))
|
|
raise 'Expected one item per uploaded photo' unless items.length == 2
|
|
items.each_with_index do |item, index|
|
|
html = Nokogiri::HTML::DocumentFragment.parse(item)
|
|
raise 'Each item must contain one photo' unless html.css('img').length == 1
|
|
raise 'Photo order changed' unless html.at_css('img')['src'].end_with?("0#{index}.jpg")
|
|
raise 'Lazy loading lost' unless html.at_css('img')['loading'] == 'lazy'
|
|
raise 'Caption lost' unless html.at_css('.image-details').text == 'A & BCaption'
|
|
raise 'Anchor must occur on the first photo only' unless html.css('#photo-batch').length == (index.zero? ? 1 : 0)
|
|
end
|
|
single = '<p><img src="/img/arts/uploads/batch/00.jpg"></p>'
|
|
raise 'Single photo changed' unless renderer.gallery_items(single) == [single]
|
|
legacy = '<p><img src="/img/old.jpg"></p><p>Existing artwork content</p>'
|
|
raise 'Legacy artwork changed' unless renderer.gallery_items(legacy) == [legacy]
|
|
puts 'Gallery item regression checks passed'
|