2023-06-12 19:59:54 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe "Topic page", type: :system do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:topic)
|
2024-03-08 22:54:10 +08:00
|
|
|
fab!(:admin)
|
2023-06-12 19:59:54 +08:00
|
|
|
|
|
|
|
before { Fabricate(:post, topic: topic, cooked: <<~HTML) }
|
|
|
|
<h2 dir="ltr" id="toc-h2-testing" data-d-toc="toc-h2-testing" class="d-toc-post-heading">
|
|
|
|
<a name="toc-h2-testing" class="anchor" href="#toc-h2-testing">x</a>
|
|
|
|
Testing
|
|
|
|
</h2>
|
|
|
|
HTML
|
|
|
|
|
|
|
|
it "allows TOC anchor navigation" do
|
|
|
|
visit("/t/#{topic.slug}/#{topic.id}")
|
|
|
|
|
2023-06-13 17:05:19 +08:00
|
|
|
find("#toc-h2-testing .anchor", visible: :all).click
|
2023-06-12 19:59:54 +08:00
|
|
|
|
2023-06-13 17:05:19 +08:00
|
|
|
try_until_success do
|
2023-06-12 19:59:54 +08:00
|
|
|
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}")
|
|
|
|
|
2023-06-13 17:05:19 +08:00
|
|
|
find("#toc-h2-testing .anchor", visible: :all).click
|
2023-06-12 19:59:54 +08:00
|
|
|
|
2023-06-13 17:05:19 +08:00
|
|
|
try_until_success do
|
2023-06-12 19:59:54 +08:00
|
|
|
expect(current_url).to match("/forum/t/#{topic.slug}/#{topic.id}#toc-h2-testing")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-09-28 01:05:27 +08:00
|
|
|
|
|
|
|
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
|
2023-11-20 21:26:46 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-03-08 22:54:10 +08:00
|
|
|
sign_in admin
|
2023-11-20 21:26:46 +08:00
|
|
|
end
|
|
|
|
|
2024-02-29 19:24:37 +08:00
|
|
|
it "displays the gap to admins, and allows them to expand it" do
|
2023-11-20 21:26:46 +08:00
|
|
|
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
|
2024-03-08 22:54:10 +08:00
|
|
|
|
|
|
|
it "supports shift+a kbd shortcut to toggle admin menu" do
|
|
|
|
sign_in admin
|
|
|
|
|
|
|
|
visit("/t/#{topic.slug}/#{topic.id}")
|
|
|
|
|
2024-05-08 15:08:42 +08:00
|
|
|
expect(".toggle-admin-menu").to be_present
|
2024-03-08 22:54:10 +08:00
|
|
|
|
|
|
|
send_keys([:shift, "a"])
|
|
|
|
|
2024-05-08 15:08:42 +08:00
|
|
|
expect(page).to have_css(".topic-admin-menu-content")
|
2024-03-08 22:54:10 +08:00
|
|
|
|
|
|
|
send_keys([:shift, "a"])
|
|
|
|
|
2024-05-08 15:08:42 +08:00
|
|
|
expect(page).to have_no_css(".topic-admin-menu-content")
|
2024-03-08 22:54:10 +08:00
|
|
|
end
|
2024-08-27 02:39:30 +08:00
|
|
|
|
|
|
|
context "with End keyboard shortcut" do
|
|
|
|
fab!(:posts) { Fabricate.times(25, :post, topic: topic) }
|
|
|
|
|
|
|
|
it "loads last post" do
|
|
|
|
visit "/t/#{topic.slug}/#{topic.id}/1"
|
|
|
|
|
|
|
|
send_keys(:end)
|
|
|
|
|
|
|
|
expect(find("#post_#{topic.highest_post_number}")).to be_visible
|
|
|
|
end
|
|
|
|
end
|
2023-06-12 19:59:54 +08:00
|
|
|
end
|