samhuri.net/test/projects/plugin_test.rb
Sami Samhuri 9a0b182879
Publish a Gemini site and link to it from the website (#36)
* Publish on gemini in addition to the web

* Publish gemini feeds, add link from web, tweak things
2026-02-14 17:18:09 -08:00

91 lines
2.8 KiB
Ruby

require "test_helper"
require "tmpdir"
class Pressa::Projects::PluginTest < Minitest::Test
def site
@site ||= Pressa::Site.new(
author: "Sami Samhuri",
email: "sami@samhuri.net",
title: "samhuri.net",
description: "blog",
url: "https://samhuri.net"
)
end
def project
@project ||= Pressa::Projects::Project.new(
name: "demo",
title: "Demo",
description: "Demo project",
url: "https://github.com/samsonjs/demo"
)
end
def test_setup_is_a_no_op
plugin = Pressa::Projects::Plugin.new(projects: [project])
assert_nil(plugin.setup(site:, source_path: "/tmp/unused"))
end
def test_render_writes_projects_index_and_project_page
plugin = Pressa::Projects::Plugin.new(
projects: [project],
scripts: [Pressa::Script.new(src: "js/projects.js", defer: false)],
styles: [Pressa::Stylesheet.new(href: "css/projects.css")]
)
Dir.mktmpdir do |dir|
plugin.render(site:, target_path: dir)
index_path = File.join(dir, "projects/index.html")
project_path = File.join(dir, "projects/demo/index.html")
assert(File.exist?(index_path))
assert(File.exist?(project_path))
index_html = File.read(index_path)
details_html = File.read(project_path)
assert_includes(index_html, "Projects")
assert_includes(index_html, "Demo")
assert_includes(details_html, "Demo project")
assert_includes(details_html, "js/projects.js")
assert_includes(details_html, "css/projects.css")
end
end
def test_gemini_plugin_renders_index_and_project_pages
gemini_site = Pressa::Site.new(
author: "Sami Samhuri",
email: "sami@samhuri.net",
title: "samhuri.net",
description: "blog",
url: "https://samhuri.net",
output_format: "gemini",
output_options: Pressa::GeminiOutputOptions.new
)
plugin = Pressa::Projects::GeminiPlugin.new(projects: [project])
Dir.mktmpdir do |dir|
plugin.render(site: gemini_site, target_path: dir)
index_path = File.join(dir, "projects/index.gmi")
details_path = File.join(dir, "projects/demo/index.gmi")
assert(File.exist?(index_path))
assert(File.exist?(details_path))
index_text = File.read(index_path)
details_text = File.read(details_path)
assert_includes(index_text, "## Demo")
assert_includes(index_text, "Demo project")
assert_includes(index_text, "=> https://github.com/samsonjs/demo")
refute_includes(index_text, "=> /projects/demo/")
assert_includes(details_text, "=> https://github.com/samsonjs/demo")
assert_includes(details_text, "=> /projects/ Back to projects")
refute_includes(details_text, "Project link")
refute_includes(details_text, "Read on the web")
end
end
end