0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/plugins/discourse-graphviz/spec/integration/graphviz_cooking_spec.rb
David Taylor be74f5ff1c
FEATURE: Modernize Graphviz implementation (#40720)
This commit updates the graphviz plugin implementation to match the
official Discourse mermaid theme-component. This moves the rendering to
be 100% client-side and 100% SVG, with a builtin fullscreen view. The
change improves image quality and simplifies the implementation.
Graphviz diagrams will now adopt a fixed 16:9 size in posts, to avoid
any scroll jumps.
2026-06-11 11:42:23 +01:00

31 lines
1,013 B
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "Graphviz cooking" do
before { SiteSetting.discourse_graphviz_enabled = true }
it "emits a placeholder with the engine and escaped source for the client to render" do
post = Fabricate(:post, raw: <<~MD)
[graphviz engine=neato]
digraph G { a -> b }
[/graphviz]
MD
expect(post.cooked).to include("graphviz is-loading")
expect(post.cooked).to include("neato")
expect(post.cooked).to include("digraph G { a -&gt; b }")
end
it "defaults to the dot engine for unknown engines" do
post = Fabricate(:post, raw: "[graphviz engine=bogus]\ndigraph { a }\n[/graphviz]")
expect(post.cooked).to include("dot")
expect(post.cooked).not_to include("bogus")
end
it "does not render when the plugin is disabled" do
SiteSetting.discourse_graphviz_enabled = false
post = Fabricate(:post, raw: "[graphviz]\ndigraph { a }\n[/graphviz]")
expect(post.cooked).not_to include("class=\"graphviz")
end
end