# frozen_string_literal: true
describe "Topic page", type: :system do
fab!(:topic)
before { Fabricate(:post, topic: topic, cooked: <<~HTML) }
x
Testing
HTML
it "allows TOC anchor navigation" do
visit("/t/#{topic.slug}/#{topic.id}")
find("#toc-h2-testing .anchor", visible: :all).click
try_until_success do
expect(current_url).to match("/t/#{topic.slug}/#{topic.id}#toc-h2-testing")
end
end
context "with a subfolder setup" do
before { set_subfolder "/forum" }
it "allows TOC anchor navigation" do
visit("/forum/t/#{topic.slug}/#{topic.id}")
find("#toc-h2-testing .anchor", visible: :all).click
try_until_success do
expect(current_url).to match("/forum/t/#{topic.slug}/#{topic.id}#toc-h2-testing")
end
end
end
context "with a post containing a code block" do
before { Fabricate(:post, topic: topic, raw: <<~RAW) }
this a code block
```
echo "hello world"
```
RAW
it "includes the copy button" do
visit("/t/#{topic.slug}/#{topic.id}")
expect(".codeblock-button-wrapper").to be_present
end
end
context "with a gap" do
before do
post2 = Fabricate(:post, topic: topic, cooked: "post2")
post3 = Fabricate(:post, topic: topic, cooked: "post3")
post4 = Fabricate(:post, topic: topic, cooked: "post4")
PostDestroyer.new(Discourse.system_user, post2).destroy
PostDestroyer.new(Discourse.system_user, post3).destroy
sign_in Fabricate(:admin)
end
it "displays the gap to admins, and alows them to expand it" do
visit "/t/#{topic.slug}/#{topic.id}"
expect(page).to have_css(".topic-post", count: 2)
find(".post-stream .gap").click()
expect(page).to have_css(".topic-post", count: 4)
end
end
end