2022-03-09 13:34:02 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
require "ostruct"
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe "topics/show.html.erb" do
|
2023-11-28 19:08:14 +08:00
|
|
|
fab!(:category)
|
|
|
|
fab!(:topic) { Fabricate(:topic, category: category) }
|
|
|
|
|
|
|
|
it "uses subfolder-safe category url" do
|
|
|
|
set_subfolder "/subpath"
|
|
|
|
topic_view = OpenStruct.new(topic: topic, posts: [])
|
|
|
|
topic_view.stubs(:summary).returns("")
|
|
|
|
view.stubs(:crawler_layout?).returns(false)
|
|
|
|
assign(:topic_view, topic_view)
|
|
|
|
assign(:breadcrumbs, [{ name: category.name, color: category.color }])
|
|
|
|
assign(:tags, [])
|
|
|
|
|
|
|
|
render template: "topics/show", formats: [:html]
|
|
|
|
|
|
|
|
assert_select "a[href='/subpath/c/#{category.slug}/#{category.id}']"
|
|
|
|
end
|
2022-03-09 13:34:02 +08:00
|
|
|
|
|
|
|
it "add nofollow to RSS alternate link for topic" do
|
|
|
|
topic_view = OpenStruct.new(topic: topic, posts: [])
|
|
|
|
topic_view.stubs(:summary).returns("")
|
|
|
|
view.stubs(:crawler_layout?).returns(false)
|
|
|
|
view.stubs(:url_for).returns("https://www.example.com/test.rss")
|
|
|
|
view.instance_variable_set("@topic_view", topic_view)
|
2023-02-22 23:01:32 +08:00
|
|
|
assign(:tags, [])
|
|
|
|
|
2022-03-09 13:34:02 +08:00
|
|
|
render template: "topics/show", formats: [:html]
|
|
|
|
|
|
|
|
expect(view.content_for(:head)).to match(
|
|
|
|
%r{<link rel="alternate nofollow" type="application/rss\+xml" title="[^"]+" href="https://www.example.com/test\.rss" />},
|
|
|
|
)
|
|
|
|
end
|
2023-01-30 15:26:55 +08:00
|
|
|
|
2023-06-14 04:02:21 +08:00
|
|
|
it "adds structured data" do
|
2023-01-30 15:26:55 +08:00
|
|
|
view.stubs(:include_crawler_content?).returns(true)
|
|
|
|
post = Fabricate(:post, topic: topic)
|
|
|
|
TopicLink.create!(
|
|
|
|
topic_id: post.topic_id,
|
|
|
|
post_id: post.id,
|
|
|
|
user_id: post.user_id,
|
|
|
|
url: "https://example.com/",
|
|
|
|
domain: "example.com",
|
|
|
|
link_topic_id: Fabricate(:topic).id,
|
|
|
|
reflection: true,
|
|
|
|
)
|
|
|
|
assign(:topic_view, TopicView.new(topic))
|
|
|
|
assign(:tags, [])
|
|
|
|
|
|
|
|
render template: "topics/show", formats: [:html]
|
|
|
|
|
|
|
|
links_list = Nokogiri::HTML5.fragment(rendered).css(".crawler-linkback-list")
|
|
|
|
first_item = links_list.css('[itemprop="itemListElement"]')
|
|
|
|
expect(first_item.css('[itemprop="position"]')[0]["content"]).to eq("1")
|
|
|
|
expect(first_item.css('[itemprop="url"]')[0]["href"]).to eq("https://example.com/")
|
|
|
|
end
|
2023-04-03 17:06:47 +08:00
|
|
|
|
|
|
|
it "uses comment scheme type for replies" do
|
|
|
|
view.stubs(:crawler_layout?).returns(true)
|
|
|
|
view.stubs(:include_crawler_content?).returns(true)
|
|
|
|
Fabricate(:post, topic: topic)
|
|
|
|
Fabricate(:post, topic: topic)
|
|
|
|
Fabricate(:post, topic: topic)
|
|
|
|
assign(:topic_view, TopicView.new(topic))
|
|
|
|
assign(:tags, [])
|
|
|
|
|
|
|
|
render template: "topics/show", formats: [:html]
|
|
|
|
|
|
|
|
doc = Nokogiri::HTML5.fragment(rendered)
|
|
|
|
topic_schema = doc.css('[itemtype="http://schema.org/DiscussionForumPosting"]')
|
|
|
|
expect(topic_schema.size).to eq(1)
|
|
|
|
expect(topic_schema.css('[itemtype="http://schema.org/Comment"]').size).to eq(2)
|
2023-04-07 02:00:19 +08:00
|
|
|
expect(topic_schema.css('[itemprop="articleSection"]')[0]["content"]).to eq(topic.category.name)
|
2023-04-03 17:06:47 +08:00
|
|
|
end
|
2022-03-09 13:34:02 +08:00
|
|
|
end
|