mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 02:19:55 +08:00
Horizon renders its new topic button into the `before-sidebar-sections` outlet, which is rendered for whatever panel is current. The button is panel-agnostic by construction, and the only thing keeping it off the admin sidebar was a string comparison against the current URL. Any other panel that claims the sidebar slips past that check, and none of them have a URL prefix worth matching. `isForcingSidebar` looks like the shared signal but is not one: a panel can swap the current panel without setting it. `showMainPanel` is what every takeover has in common. This is latent on main today rather than a visible regression, because the other in-repo takeovers claim the panel while the sidebar is disabled anyway. It stops being latent with #42058, which moves the styleguide navigation into a sidebar panel: the sidebar stays enabled there, the path is not `/admin`, and the forum's new topic button renders on top of the styleguide's own navigation. Admin behavior is unchanged. `AdminRoute#activate` calls `maybeForceAdminSidebar` with `onlyIfAlreadyActive: false`, so the panel is forced unconditionally on every admin route despite the method name. ### Tests A rendering test asserts both directions on an ordinary forum URL: rendered while the forum panel owns the sidebar, hidden while another panel does. Reverting the component leaves it rendered in the second case.
82 lines
2.4 KiB
Ruby
Vendored
82 lines
2.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Sidebar New Topic Button" do
|
|
before { upload_theme }
|
|
fab!(:group)
|
|
fab!(:user) { Fabricate(:user, trust_level: 3, groups: [group]) }
|
|
fab!(:category)
|
|
fab!(:private_category) do
|
|
c = Fabricate(:category_with_definition)
|
|
c.set_permissions(group => :readonly)
|
|
c.save
|
|
c
|
|
end
|
|
|
|
context "for signed in users" do
|
|
before { sign_in(user) }
|
|
|
|
it "renders the new topic button in the sidebar" do
|
|
visit("/latest")
|
|
expect(page).to have_css(".sidebar-new-topic-button__wrapper")
|
|
expect(page).to have_css(".sidebar-new-topic-button:not(.disabled)")
|
|
end
|
|
|
|
it "opens the composer when clicked" do
|
|
visit("/")
|
|
find(".sidebar-new-topic-button").click
|
|
expect(page).to have_css("#reply-title")
|
|
end
|
|
|
|
it "shows draft menu when drafts exist" do
|
|
Draft.create!(user: user, draft_key: "topic_1", data: {})
|
|
|
|
visit("/")
|
|
expect(page).to have_css(".sidebar-new-topic-button__wrapper .topic-drafts-menu-trigger")
|
|
end
|
|
|
|
it "opens the composer with the tag pre-filled when on a tag page" do
|
|
tag = Fabricate(:tag)
|
|
Fabricate(:topic, tags: [tag])
|
|
|
|
visit("/tag/#{tag.slug}/#{tag.id}")
|
|
find(".sidebar-new-topic-button").click
|
|
|
|
expect(page).to have_css("#reply-title")
|
|
|
|
tag_chooser = PageObjects::Components::SelectKit.new(".mini-tag-chooser")
|
|
expect(tag_chooser).to have_selected_name(tag.name)
|
|
end
|
|
|
|
it "does not disable button when visiting read-only category" do
|
|
visit("/c/#{private_category.slug}/#{private_category.id}")
|
|
|
|
expect(page).to have_no_css(".sidebar-new-topic-button[disabled]")
|
|
|
|
visit("/c/#{category.slug}/#{category.id}")
|
|
|
|
expect(page).to have_no_css(".sidebar-new-topic-button[disabled]")
|
|
end
|
|
end
|
|
|
|
context "when another panel has taken over the sidebar" do
|
|
fab!(:admin)
|
|
|
|
before { sign_in(admin) }
|
|
|
|
it "hides the button in the admin sidebar and brings it back on the way out" do
|
|
visit("/admin")
|
|
expect(page).to have_no_css(".sidebar-new-topic-button__wrapper")
|
|
|
|
visit("/latest")
|
|
expect(page).to have_css(".sidebar-new-topic-button__wrapper")
|
|
end
|
|
end
|
|
|
|
context "for anon" do
|
|
it "does not render the sidebar button for anons" do
|
|
visit("/latest")
|
|
expect(page).not_to have_css(".sidebar-new-topic-button__wrapper")
|
|
expect(page).not_to have_css(".sidebar-new-topic-button:not(.disabled)")
|
|
end
|
|
end
|
|
end
|