FEATURE: allow external links in custom sidebar sections (#20503)

Originally, only Discourse site links were available. After feedback, it was decided to extend this feature to external URLs.

/t/93491
This commit is contained in:
Krzysztof Kotlarek
2023-03-07 11:47:18 +11:00
committed by GitHub
parent b4528b9e27
commit a16ea24461
13 changed files with 153 additions and 31 deletions

View File

@@ -54,8 +54,13 @@ RSpec.describe SidebarSectionsController do
params: {
title: "custom section",
links: [
{ icon: "link", name: "categories", value: "/categories" },
{
icon: "link",
name: "categories",
value: "http://#{Discourse.current_hostname}/categories",
},
{ icon: "address-book", name: "tags", value: "/tags" },
{ icon: "external-link-alt", name: "Discourse", value: "https://discourse.org" },
],
}
@@ -68,13 +73,19 @@ RSpec.describe SidebarSectionsController do
expect(sidebar_section.user).to eq(user)
expect(sidebar_section.public).to be false
expect(UserHistory.count).to eq(0)
expect(sidebar_section.sidebar_urls.count).to eq(2)
expect(sidebar_section.sidebar_urls.count).to eq(3)
expect(sidebar_section.sidebar_urls.first.icon).to eq("link")
expect(sidebar_section.sidebar_urls.first.name).to eq("categories")
expect(sidebar_section.sidebar_urls.first.value).to eq("/categories")
expect(sidebar_section.sidebar_urls.first.external).to be false
expect(sidebar_section.sidebar_urls.second.icon).to eq("address-book")
expect(sidebar_section.sidebar_urls.second.name).to eq("tags")
expect(sidebar_section.sidebar_urls.second.value).to eq("/tags")
expect(sidebar_section.sidebar_urls.second.external).to be false
expect(sidebar_section.sidebar_urls.third.icon).to eq("external-link-alt")
expect(sidebar_section.sidebar_urls.third.name).to eq("Discourse")
expect(sidebar_section.sidebar_urls.third.value).to eq("https://discourse.org")
expect(sidebar_section.sidebar_urls.third.external).to be true
end
it "does not allow regular user to create public section" do

View File

@@ -21,7 +21,7 @@ describe "Custom sidebar sections", type: :system, js: true do
expect(section_modal).to be_visible
expect(section_modal).to have_disabled_save
expect(find("#discourse-modal-title")).to have_content("Add custom section")
expect(sidebar.custom_section_modal_title).to have_content("Add custom section")
section_modal.fill_name("My section")
@@ -31,7 +31,29 @@ describe "Custom sidebar sections", type: :system, js: true do
section_modal.save
expect(page).to have_button("My section")
expect(page).to have_link("Sidebar Tags")
expect(sidebar).to have_link("Sidebar Tags")
end
it "allows the user to create custom section with external link" do
visit("/latest")
sidebar.open_new_custom_section
expect(section_modal).to be_visible
expect(section_modal).to have_disabled_save
expect(sidebar.custom_section_modal_title).to have_content("Add custom section")
section_modal.fill_name("My section")
section_modal.fill_link("Discourse Homepage", "htt")
expect(section_modal).to have_disabled_save
section_modal.fill_link("Discourse Homepage", "https://discourse.org")
expect(section_modal).to have_enabled_save
section_modal.save
expect(page).to have_button("My section")
expect(sidebar).to have_link("Discourse Homepage", href: "https://discourse.org")
end
it "allows the user to edit custom section" do
@@ -53,7 +75,8 @@ describe "Custom sidebar sections", type: :system, js: true do
section_modal.save
expect(page).to have_button("Edited section")
expect(page).to have_link("Edited Tags")
expect(sidebar).to have_link("Edited Tag")
expect(page).not_to have_link("Sidebar Categories")
end
@@ -100,7 +123,7 @@ describe "Custom sidebar sections", type: :system, js: true do
section_modal.save
expect(page).to have_button("Public section")
expect(page).to have_link("Sidebar Tags")
expect(sidebar).to have_link("Sidebar Tags")
expect(page).to have_css(".sidebar-section-public-section .d-icon-globe")
sidebar.edit_custom_section("Public section")

View File

@@ -23,6 +23,16 @@ module PageObjects
find(".sidebar-section-#{name.parameterize}").hover
find(".sidebar-section-#{name.parameterize} button.sidebar-section-header-button").click
end
def has_link?(name, href: nil)
attributes = {}
attributes[:href] = href if href
page.has_link?(name, attributes)
end
def custom_section_modal_title
find("#discourse-modal-title")
end
end
end
end