2021-05-26 17:41:35 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Onebox::Engine::GithubFolderOnebox do
|
2021-05-26 17:41:35 +08:00
|
|
|
context 'without fragments' do
|
|
|
|
before do
|
2021-07-19 23:25:44 +08:00
|
|
|
@link = "https://github.com/discourse/discourse/tree/main/spec/fixtures"
|
|
|
|
@uri = "https://github.com/discourse/discourse/tree/main/spec/fixtures"
|
2021-05-26 17:41:35 +08:00
|
|
|
|
|
|
|
stub_request(:get, @uri).to_return(status: 200, body: onebox_response(described_class.onebox_name))
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
include_context "with engines"
|
2021-05-26 17:41:35 +08:00
|
|
|
it_behaves_like "an engine"
|
|
|
|
|
|
|
|
describe "#to_html" do
|
|
|
|
it "includes link to folder with truncated display path" do
|
2021-07-20 00:41:48 +08:00
|
|
|
expect(html).to include('<a href="https://github.com/discourse/discourse/tree/main/spec/fixtures" target="_blank" rel="noopener">main/spec/fixtures</a>')
|
2021-05-26 17:41:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes repository name" do
|
|
|
|
expect(html).to include("discourse/discourse")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes logo" do
|
|
|
|
expect(html).to include("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with fragments' do
|
|
|
|
before do
|
|
|
|
@link = "https://github.com/discourse/discourse#setting-up-discourse"
|
|
|
|
@uri = "https://github.com/discourse/discourse"
|
|
|
|
stub_request(:get, @uri).to_return(status: 200, body: onebox_response("githubfolder-discourse-root"))
|
|
|
|
@onebox = described_class.new(@link)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "extracts subtitles when linking to docs" do
|
|
|
|
expect(@onebox.to_html).to include("<a href=\"https://github.com/discourse/discourse#setting-up-discourse\" target=\"_blank\" rel=\"noopener\">discourse/discourse - Setting up Discourse</a>")
|
|
|
|
end
|
|
|
|
end
|
2022-01-18 01:32:07 +08:00
|
|
|
|
|
|
|
context 'with rdoc fragments' do
|
|
|
|
before do
|
|
|
|
@link = "https://github.com/ruby/rdoc#description-"
|
|
|
|
@uri = "https://github.com/ruby/rdoc"
|
|
|
|
stub_request(:get, @uri).to_return(status: 200, body: onebox_response("githubfolder-rdoc-root"))
|
|
|
|
@onebox = described_class.new(@link)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "extracts subtitles when linking to docs" do
|
|
|
|
expect(@onebox.to_html).to include("<a href=\"https://github.com/ruby/rdoc#description-\" target=\"_blank\" rel=\"noopener\">GitHub - ruby/rdoc: RDoc produces HTML and online documentation for Ruby... - Description¶ ↑</a>")
|
|
|
|
end
|
|
|
|
end
|
2021-05-26 17:41:35 +08:00
|
|
|
end
|