37 lines
1.9 KiB
Ruby
37 lines
1.9 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]
|
|
|
|
portrait = '<img src="/img/arts/dresden-prague-iran-2024/Prague_000512360030.jpg">'
|
|
landscape = '<img src="/img/arts/uploads/5e085e7d10edc54172e7b5c47d22fe532edec19c879a8d566667d3c3c1bb3d96/00.jpg">'
|
|
raise 'Portrait ratio incorrect' unless renderer.gallery_image_ratio(portrait) < 1
|
|
raise 'Landscape ratio incorrect' unless renderer.gallery_image_ratio(landscape) > 1
|
|
raise 'Video fallback ratio incorrect' unless renderer.gallery_image_ratio('<video></video>') == 1.5
|
|
puts 'Gallery item regression checks passed'
|