discourse/spec/system/lightbox_spec.rb
David Battersby b671166ab1
FEATURE: Experimental Photoswipe Lightbox (#35109)
Our current implementation of lightbox uses Magnific Popup, which is now
deprecated and will only receive critical/security bug fixes. Magnific
also relies on jQuery, which we would like to remove where possible
throughout our codebase.

After looking at various options, the general consensus was that
PhotoSwipe was a close match to what we need.

Regular image types that are supported with our current lightbox (jpg,
png etc) will work with their existing cooked markup (no need to rebake
posts). This PR also adds support for SVG images and markup from various
theme components (ie. Discourse Mermaid).

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2025-10-16 12:24:11 +04:00

71 lines
2.1 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
describe "Lightbox | Photoswipe", type: :system do
fab!(:topic)
fab!(:current_user, :admin)
fab!(:upload_1) { Fabricate(:image_upload, width: 2400, height: 3600) }
fab!(:post) { Fabricate(:post, topic: topic, raw: "![first image](#{upload_1.url})") }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:lightbox) { PageObjects::Components::PhotoSwipe.new }
let(:cpp) { CookedPostProcessor.new(post, disable_dominant_color: true) }
before do
SiteSetting.experimental_lightbox = true
SiteSetting.create_thumbnails = true
sign_in(current_user)
end
context "with single image" do
before do
cpp.post_process
post.update(cooked: cpp.html)
end
it "has the correct lightbox elements" do
topic_page.visit_topic(topic)
find("#post_1 a.lightbox").click
expect(lightbox).to be_visible
expect(lightbox).to have_no_counter
expect(lightbox).to have_caption_title("first image")
expect(lightbox).to have_caption_details("2400×3600 1.21 KB")
expect(lightbox).to have_no_next_button
expect(lightbox).to have_no_prev_button
expect(lightbox).to have_download_button
expect(lightbox).to have_original_image_button
end
end
context "with multiple images" do
fab!(:upload_2) { Fabricate(:large_image_upload, width: 2000, height: 1000) }
before do
post.update(raw: "![first image](#{upload_1.url}) ![second image](#{upload_2.url})")
cpp.post_process
post.update(cooked: cpp.html)
end
it "has the correct lightbox elements" do
topic_page.visit_topic(topic)
find("#post_1 .lightbox-wrapper:nth-of-type(2) .lightbox").click
expect(lightbox).to be_visible
expect(lightbox).to have_counter("2 / 2")
expect(lightbox).to have_caption_title("second image")
expect(lightbox).to have_caption_details("2000×1000 1.21 KB")
expect(lightbox).to have_next_button
expect(lightbox).to have_prev_button
expect(lightbox).to have_download_button
expect(lightbox).to have_original_image_button
end
end
end