0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/spec/system/nested_category_default_spec.rb
Mark VanLandingham 8d107223be
DEV: Remove ?flat=1 query param for nested topics (#41205)
This PR started as simply fixing clicking the title in the .d-header
when you're scroll down. That is fixed here, but it exposed that we
still had some "toggle to flat" related logic that is no longer needed.
Cleaned up.
2026-06-26 08:31:43 -05:00

91 lines
3.2 KiB
Ruby
Vendored

# frozen_string_literal: true
require_relative "../support/nested_replies_helpers"
RSpec.describe "Nested view category default" do
include NestedRepliesHelpers
fab!(:admin)
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:category)
fab!(:nested_category) { Fabricate(:category, name: "Nested Category") }
fab!(:topic) { Fabricate(:topic, user: user, category: nested_category) }
fab!(:op) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
fab!(:reply) { Fabricate(:post, topic: topic, user: Fabricate(:user), raw: "A reply") }
let(:nested_view) { PageObjects::Pages::NestedView.new }
let(:category_page) { PageObjects::Pages::Category.new }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:form) { PageObjects::Components::FormKit.new(".form-kit") }
before do
SiteSetting.nested_replies_enabled = true
nested_category.category_setting.update!(nested_replies_default: true)
Fabricate(:nested_topic, topic: topic)
end
describe "category settings UI" do
before { sign_in(admin) }
it "allows admin to enable nested view default for a category" do
unchecked_category = Fabricate(:category, name: "Unchecked Category")
category_page.visit_settings(unchecked_category)
form.field("category_setting.nested_replies_default").toggle
category_page.save_settings
unchecked_category.reload
expect(unchecked_category.nested_replies_default).to eq(true)
end
it "shows checkbox as checked when category has nested default enabled" do
category_page.visit_settings(nested_category)
expect(form.field("category_setting.nested_replies_default")).to be_checked
end
end
describe "topic routing" do
before { sign_in(user) }
it "renders nested view when visiting a topic URL directly" do
page.visit("/t/#{topic.slug}/#{topic.id}")
expect(page).to have_current_path(%r{/t/#{topic.slug}/#{topic.id}})
expect(nested_view).to have_nested_view
end
it "renders nested view when clicking a topic from the category page" do
page.visit("/c/#{nested_category.slug}/#{nested_category.id}")
find(".topic-list-item .raw-topic-link[data-topic-id='#{topic.id}']").click
expect(page).to have_current_path(%r{/t/#{topic.slug}/#{topic.id}})
expect(nested_view).to have_nested_view
end
it "takes the user to the top of a nested topic from a scrolled list" do
category_page.visit(nested_category)
expect(topic_list).to have_topic(topic)
topic_list.scroll_page_down
expect(topic_list).to be_scrolled_down
topic_list.visit_topic(topic)
expect(page).to have_current_path(%r{/t/#{topic.slug}/#{topic.id}})
expect(nested_view).to have_nested_view
try_until_success { expect(page.evaluate_script("window.scrollY")).to eq(0) }
end
it "does not redirect topics in categories without nested default" do
normal_topic = Fabricate(:topic, user: user, category: category)
Fabricate(:post, topic: normal_topic, user: user, post_number: 1)
page.visit("/t/#{normal_topic.slug}/#{normal_topic.id}")
expect(page).to have_current_path(%r{/t/#{normal_topic.slug}/#{normal_topic.id}})
expect(nested_view).to have_no_nested_view
end
end
end