2023-02-02 22:44:40 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-06 21:26:58 -04:00
|
|
|
describe "Custom sidebar sections", type: :system do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:user)
|
|
|
|
fab!(:admin)
|
2023-02-02 22:44:40 -05:00
|
|
|
let(:section_modal) { PageObjects::Modals::SidebarSectionForm.new }
|
2023-07-10 21:40:37 -04:00
|
|
|
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
|
2023-02-02 22:44:40 -05:00
|
|
|
|
2023-06-29 22:25:43 -04:00
|
|
|
before { user.user_option.update!(external_links_in_new_tab: true) }
|
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
shared_examples "creating custom sections" do |relative_root_url|
|
|
|
|
it "allows the user to create custom section" do
|
|
|
|
visit("#{relative_root_url}/latest")
|
2023-05-18 21:31:25 -04:00
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
expect(sidebar).to have_no_add_section_button
|
2023-05-18 21:31:25 -04:00
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
sign_in user
|
|
|
|
visit("#{relative_root_url}/latest")
|
|
|
|
sidebar.click_add_section_button
|
2023-02-02 22:44:40 -05:00
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
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")
|
2023-02-02 22:44:40 -05:00
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
section_modal.fill_name("My section")
|
2023-02-02 22:44:40 -05:00
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
section_modal.fill_link("Sidebar Tags", "/tags")
|
|
|
|
expect(section_modal).to have_enabled_save
|
2023-02-02 22:44:40 -05:00
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
section_modal.save
|
2023-02-02 22:44:40 -05:00
|
|
|
|
2023-07-25 01:57:49 -04:00
|
|
|
expect(sidebar).to have_section("My section")
|
|
|
|
expect(sidebar).to have_section_link("Sidebar Tags")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "creating custom sections"
|
|
|
|
|
|
|
|
context "when subfolder install" do
|
|
|
|
before { set_subfolder "/community" }
|
|
|
|
|
|
|
|
include_examples "creating custom sections", "/community"
|
2023-03-06 19:47:18 -05:00
|
|
|
end
|
|
|
|
|
2023-03-21 00:58:42 -04:00
|
|
|
it "allows the user to create custom section with /my link" do
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-03-21 00:58:42 -04:00
|
|
|
visit("/latest")
|
|
|
|
|
2023-05-23 18:59:19 -04:00
|
|
|
sidebar.click_add_section_button
|
2023-03-21 00:58:42 -04:00
|
|
|
section_modal.fill_name("My section")
|
|
|
|
section_modal.fill_link("My preferences", "/my/preferences")
|
|
|
|
section_modal.save
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
expect(sidebar).to have_section("My section")
|
2023-06-29 22:25:43 -04:00
|
|
|
expect(sidebar).to have_section_link("My preferences", target: "_self")
|
2023-03-21 00:58:42 -04:00
|
|
|
end
|
|
|
|
|
FIX: Simplify sidebar custom link implementation (#26201)
All our link validation, and conversion from url -> route/model/query is expensive and prone to bugs. Instead, if people enter a link, we can just use it as-is.
Originally all this extra logic was added to handle unusual situations like `/safe-mode`, `/my/...`, etc. However, all of these are now handled correctly by our Ember router, so there is no need for it.
Now, we just pass the user-supplied `href` directly to the SectionLink component, and let Ember handle routing to it when clicked.
The only functional change here is that we no longer validate internal links by parsing them with the Ember router. But I'd argue this is fine, because the previous logic would cause both false positives (e.g. `/t/123` would be valid, even if topic 123 doesn't exist), and false negatives (for routes which are server-side only, like the new AI share pages).
2024-03-20 08:55:40 -04:00
|
|
|
it "allows the user to create custom section with `/` path" do
|
2023-09-26 03:14:13 -04:00
|
|
|
SiteSetting.top_menu = "read|posted|latest"
|
|
|
|
|
|
|
|
sign_in user
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
section_modal.fill_name("My section")
|
|
|
|
section_modal.fill_link("Home", "/")
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(sidebar).to have_section("My section")
|
FIX: Simplify sidebar custom link implementation (#26201)
All our link validation, and conversion from url -> route/model/query is expensive and prone to bugs. Instead, if people enter a link, we can just use it as-is.
Originally all this extra logic was added to handle unusual situations like `/safe-mode`, `/my/...`, etc. However, all of these are now handled correctly by our Ember router, so there is no need for it.
Now, we just pass the user-supplied `href` directly to the SectionLink component, and let Ember handle routing to it when clicked.
The only functional change here is that we no longer validate internal links by parsing them with the Ember router. But I'd argue this is fine, because the previous logic would cause both false positives (e.g. `/t/123` would be valid, even if topic 123 doesn't exist), and false negatives (for routes which are server-side only, like the new AI share pages).
2024-03-20 08:55:40 -04:00
|
|
|
expect(sidebar).to have_section_link("Home", href: "/")
|
|
|
|
|
|
|
|
sidebar.click_section_link("Home")
|
|
|
|
expect(page).to have_css("#navigation-bar .active a[href='/read']")
|
2023-09-26 03:14:13 -04:00
|
|
|
end
|
|
|
|
|
2023-05-23 18:59:19 -04:00
|
|
|
it "allows the user to create custom section with /pub link" do
|
|
|
|
sign_in user
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
section_modal.fill_name("My section")
|
|
|
|
section_modal.fill_link("Published Page", "/pub/test")
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(sidebar).to have_section("My section")
|
2023-06-29 22:25:43 -04:00
|
|
|
expect(sidebar).to have_section_link("Published Page", target: "_self")
|
2023-05-23 18:59:19 -04:00
|
|
|
end
|
|
|
|
|
2023-03-06 19:47:18 -05:00
|
|
|
it "allows the user to create custom section with external link" do
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-03-06 19:47:18 -05:00
|
|
|
visit("/latest")
|
2023-05-18 21:31:25 -04:00
|
|
|
sidebar.click_add_section_button
|
2023-03-06 19:47:18 -05:00
|
|
|
|
|
|
|
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", "https://discourse.org")
|
|
|
|
expect(section_modal).to have_enabled_save
|
|
|
|
|
|
|
|
section_modal.save
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
expect(sidebar).to have_section("My section")
|
2023-06-29 22:25:43 -04:00
|
|
|
expect(sidebar).to have_section_link(
|
|
|
|
"Discourse Homepage",
|
|
|
|
href: "https://discourse.org",
|
|
|
|
target: "_blank",
|
|
|
|
)
|
2023-02-02 22:44:40 -05:00
|
|
|
end
|
|
|
|
|
2023-08-23 18:39:30 -04:00
|
|
|
it "allows the user to create custom section with anchor" do
|
|
|
|
sign_in user
|
|
|
|
visit("/latest")
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
|
|
|
|
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("Faq", "/faq#anchor")
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(sidebar).to have_section("My section")
|
FIX: Simplify sidebar custom link implementation (#26201)
All our link validation, and conversion from url -> route/model/query is expensive and prone to bugs. Instead, if people enter a link, we can just use it as-is.
Originally all this extra logic was added to handle unusual situations like `/safe-mode`, `/my/...`, etc. However, all of these are now handled correctly by our Ember router, so there is no need for it.
Now, we just pass the user-supplied `href` directly to the SectionLink component, and let Ember handle routing to it when clicked.
The only functional change here is that we no longer validate internal links by parsing them with the Ember router. But I'd argue this is fine, because the previous logic would cause both false positives (e.g. `/t/123` would be valid, even if topic 123 doesn't exist), and false negatives (for routes which are server-side only, like the new AI share pages).
2024-03-20 08:55:40 -04:00
|
|
|
expect(sidebar).to have_section_link("Faq", target: "_self", href: "/faq#anchor")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows the user to create custom section with query param" do
|
|
|
|
sign_in user
|
|
|
|
visit("/latest")
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
|
|
|
|
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("Faq", "/faq?a=b")
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(sidebar).to have_section("My section")
|
|
|
|
expect(sidebar).to have_section_link("Faq", target: "_self", href: "/faq?a=b")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows the user to create custom section with anchor link" do
|
|
|
|
sign_in user
|
|
|
|
visit("/latest")
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
|
|
|
|
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("Faq", "/faq#someheading")
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(sidebar).to have_section("My section")
|
|
|
|
expect(sidebar).to have_section_link("Faq", target: "_self", href: "/faq#someheading")
|
2023-08-23 18:39:30 -04:00
|
|
|
end
|
|
|
|
|
2024-02-27 19:39:25 -05:00
|
|
|
it "accessibility - when new row is added in custom section, first new input is focused" do
|
|
|
|
sign_in user
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
sidebar.click_add_link_button
|
|
|
|
|
|
|
|
is_focused =
|
|
|
|
page.evaluate_script("document.activeElement.classList.contains('multi-select-header')")
|
|
|
|
|
|
|
|
expect(is_focused).to be true
|
|
|
|
end
|
|
|
|
|
2024-07-18 11:55:28 -04:00
|
|
|
it "accessibility - when customization modal is closed, trigger is refocused" do
|
|
|
|
sign_in user
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
|
|
|
|
find(".modal-close").click
|
|
|
|
|
|
|
|
is_focused = page.evaluate_script("document.activeElement.classList.contains('add-section')")
|
|
|
|
|
|
|
|
expect(is_focused).to be true
|
|
|
|
end
|
|
|
|
|
2023-02-02 22:44:40 -05:00
|
|
|
it "allows the user to edit custom section" do
|
|
|
|
sidebar_section = Fabricate(:sidebar_section, title: "My section", user: user)
|
|
|
|
sidebar_url_1 = Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags")
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url_1)
|
|
|
|
sidebar_url_2 = Fabricate(:sidebar_url, name: "Sidebar Categories", value: "/categories")
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url_2)
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-02-02 22:44:40 -05:00
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
sidebar.edit_custom_section("My section")
|
2023-02-13 18:24:45 -05:00
|
|
|
expect(find("#discourse-modal-title")).to have_content("Edit custom section")
|
|
|
|
|
2023-02-02 22:44:40 -05:00
|
|
|
section_modal.fill_name("Edited section")
|
|
|
|
section_modal.fill_link("Edited Tags", "/tags")
|
|
|
|
section_modal.remove_last_link
|
|
|
|
|
|
|
|
section_modal.save
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
expect(sidebar).to have_section("Edited section")
|
2023-06-16 04:36:34 -04:00
|
|
|
expect(sidebar).to have_section_link("Edited Tags")
|
2023-03-06 19:47:18 -05:00
|
|
|
|
2023-05-04 19:45:53 -04:00
|
|
|
expect(sidebar).to have_no_section_link("Sidebar Categories")
|
2023-02-02 22:44:40 -05:00
|
|
|
end
|
|
|
|
|
2023-03-20 21:23:28 -04:00
|
|
|
it "allows the user to reorder links in custom section" do
|
|
|
|
sidebar_section = Fabricate(:sidebar_section, title: "My section", user: user)
|
2023-07-10 21:40:37 -04:00
|
|
|
|
|
|
|
sidebar_url_1 =
|
|
|
|
Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags").tap do |sidebar_url|
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
sidebar_url_2 =
|
|
|
|
Fabricate(:sidebar_url, name: "Sidebar Categories", value: "/categories").tap do |sidebar_url|
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
sidebar_url_3 =
|
|
|
|
Fabricate(:sidebar_url, name: "Sidebar Latest", value: "/latest").tap do |sidebar_url|
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url)
|
|
|
|
end
|
2023-03-20 21:23:28 -04:00
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-07-10 21:40:37 -04:00
|
|
|
|
2023-03-20 21:23:28 -04:00
|
|
|
visit("/latest")
|
2023-04-12 03:52:10 -04:00
|
|
|
|
2023-05-29 01:20:23 -04:00
|
|
|
expect(sidebar.primary_section_links("my-section")).to eq(
|
2023-07-10 21:40:37 -04:00
|
|
|
["Sidebar Tags", "Sidebar Categories", "Sidebar Latest"],
|
2023-05-29 01:20:23 -04:00
|
|
|
)
|
2023-03-20 21:23:28 -04:00
|
|
|
|
2023-11-01 17:46:45 -04:00
|
|
|
sidebar.edit_custom_section("My section")
|
|
|
|
|
|
|
|
tags_link = find(".draggable[data-link-name='Sidebar Tags']")
|
|
|
|
latest_link = find(".draggable[data-link-name='Sidebar Latest']")
|
2023-07-10 21:40:37 -04:00
|
|
|
tags_link.drag_to(latest_link, html5: true, delay: 0.4)
|
2023-11-01 17:46:45 -04:00
|
|
|
section_modal.save
|
2024-04-08 19:58:30 -04:00
|
|
|
expect(section_modal).to be_closed
|
2023-03-20 21:23:28 -04:00
|
|
|
|
2023-05-29 01:20:23 -04:00
|
|
|
expect(sidebar.primary_section_links("my-section")).to eq(
|
2023-07-10 21:40:37 -04:00
|
|
|
["Sidebar Categories", "Sidebar Tags", "Sidebar Latest"],
|
2023-05-29 01:20:23 -04:00
|
|
|
)
|
2023-03-20 21:23:28 -04:00
|
|
|
end
|
|
|
|
|
2024-10-17 09:28:02 -04:00
|
|
|
it "does not allow to drag on mobile", mobile: true do
|
2024-02-20 17:16:49 -05:00
|
|
|
sidebar_section = Fabricate(:sidebar_section, title: "My section", user: user)
|
|
|
|
|
|
|
|
Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags").tap do |sidebar_url|
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricate(:sidebar_url, name: "Sidebar Categories", value: "/categories").tap do |sidebar_url|
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
sign_in user
|
|
|
|
|
2024-10-17 09:28:02 -04:00
|
|
|
visit("/latest")
|
2024-02-20 17:16:49 -05:00
|
|
|
|
|
|
|
sidebar.open_on_mobile
|
|
|
|
sidebar.edit_custom_section("My section")
|
|
|
|
|
|
|
|
expect(page).not_to have_css(".sidebar-section-form-link .draggable")
|
|
|
|
end
|
|
|
|
|
2023-02-21 16:55:44 -05:00
|
|
|
it "does not allow the user to edit public section" do
|
2023-04-05 18:55:47 -04:00
|
|
|
sidebar_section = Fabricate(:sidebar_section, title: "Public section", public: true)
|
2023-02-21 16:55:44 -05:00
|
|
|
sidebar_url_1 = Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags")
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url_1)
|
|
|
|
sidebar_url_2 = Fabricate(:sidebar_url, name: "Sidebar Categories", value: "/categories")
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url_2)
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-02-21 16:55:44 -05:00
|
|
|
visit("/latest")
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
expect(sidebar).to have_section("Public section")
|
2023-03-23 01:09:45 -04:00
|
|
|
|
|
|
|
find(".sidebar-section[data-section-name='public-section']").hover
|
|
|
|
|
|
|
|
expect(page).not_to have_css(
|
|
|
|
".sidebar-section[data-section-name='public-section'] button.sidebar-section-header-button",
|
|
|
|
)
|
|
|
|
|
2023-02-21 16:55:44 -05:00
|
|
|
expect(page).not_to have_css(
|
2023-03-23 01:09:45 -04:00
|
|
|
".sidebar-section[data-section-name='public-section'] .d-icon-globe",
|
2023-02-21 16:55:44 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-02-02 22:44:40 -05:00
|
|
|
it "allows the user to delete custom section" do
|
|
|
|
sidebar_section = Fabricate(:sidebar_section, title: "My section", user: user)
|
|
|
|
sidebar_url_1 = Fabricate(:sidebar_url, name: "tags", value: "/tags")
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url_1)
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-02-02 22:44:40 -05:00
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
sidebar.edit_custom_section("My section")
|
|
|
|
|
|
|
|
section_modal.delete
|
2024-04-08 19:58:30 -04:00
|
|
|
expect(section_modal).to have_text("Are you sure you want to delete this section?")
|
2023-02-02 22:44:40 -05:00
|
|
|
section_modal.confirm_delete
|
|
|
|
|
2023-05-04 19:45:53 -04:00
|
|
|
expect(sidebar).to have_no_section("My section")
|
2023-02-02 22:44:40 -05:00
|
|
|
end
|
2023-02-21 16:55:44 -05:00
|
|
|
|
|
|
|
it "allows admin to create, edit and delete public section" do
|
|
|
|
sign_in admin
|
|
|
|
visit("/latest")
|
2023-05-18 21:31:25 -04:00
|
|
|
sidebar.click_add_section_button
|
2023-02-21 16:55:44 -05:00
|
|
|
|
|
|
|
section_modal.fill_name("Public section")
|
|
|
|
section_modal.fill_link("Sidebar Tags", "/tags")
|
|
|
|
section_modal.mark_as_public
|
|
|
|
section_modal.save
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
expect(sidebar).to have_section("Public section")
|
2023-04-12 03:52:10 -04:00
|
|
|
expect(sidebar).to have_section_link("Sidebar Tags")
|
2023-03-23 01:09:45 -04:00
|
|
|
expect(page).to have_css(".sidebar-section[data-section-name='public-section'] .d-icon-globe")
|
2023-02-21 16:55:44 -05:00
|
|
|
|
|
|
|
sidebar.edit_custom_section("Public section")
|
|
|
|
section_modal.fill_name("Edited public section")
|
|
|
|
section_modal.save
|
|
|
|
|
2024-04-08 19:58:30 -04:00
|
|
|
expect(section_modal).to have_text(
|
|
|
|
"Changes will be visible to everyone on this site. Are you sure?",
|
|
|
|
)
|
|
|
|
|
|
|
|
section_modal.confirm_update
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
expect(sidebar).to have_section("Edited public section")
|
2023-02-21 16:55:44 -05:00
|
|
|
|
|
|
|
sidebar.edit_custom_section("Edited public section")
|
|
|
|
section_modal.delete
|
2024-04-08 19:58:30 -04:00
|
|
|
expect(section_modal).to have_text(
|
|
|
|
"This section is visible to everyone, are you sure you want to delete it?",
|
|
|
|
)
|
2023-02-21 16:55:44 -05:00
|
|
|
section_modal.confirm_delete
|
|
|
|
|
2023-05-04 19:45:53 -04:00
|
|
|
expect(sidebar).to have_no_section("Edited public section")
|
2023-04-05 18:55:47 -04:00
|
|
|
end
|
|
|
|
|
2024-04-08 19:58:30 -04:00
|
|
|
it "displays warning when public section is marked as private" do
|
|
|
|
sign_in admin
|
|
|
|
visit("/latest")
|
|
|
|
sidebar.click_add_section_button
|
|
|
|
|
|
|
|
section_modal.fill_name("Public section")
|
|
|
|
section_modal.fill_link("Sidebar Tags", "/tags")
|
|
|
|
section_modal.mark_as_public
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
sidebar.edit_custom_section("Public section")
|
|
|
|
section_modal.fill_name("Edited public section")
|
|
|
|
section_modal.mark_as_public
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(section_modal).to have_text(
|
|
|
|
"This section is visible to everyone. After the update, it will be visible only to you. Are you sure?",
|
|
|
|
)
|
|
|
|
|
|
|
|
section_modal.confirm_update
|
|
|
|
|
|
|
|
expect(sidebar).to have_section("Edited public section")
|
|
|
|
expect(page).not_to have_css(
|
|
|
|
".sidebar-section[data-section-name='edited-public-section'] .d-icon-globe",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
it "shows anonymous public sections" do
|
|
|
|
sidebar_section = Fabricate(:sidebar_section, title: "Public section", public: true)
|
|
|
|
sidebar_url_1 = Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags")
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url_1)
|
|
|
|
sidebar_url_2 = Fabricate(:sidebar_url, name: "Sidebar Categories", value: "/categories")
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section, linkable: sidebar_url_2)
|
|
|
|
|
|
|
|
visit("/latest")
|
|
|
|
expect(sidebar).to have_section("Public section")
|
2023-04-12 03:52:10 -04:00
|
|
|
expect(sidebar).to have_section_link("Sidebar Tags")
|
|
|
|
expect(sidebar).to have_section_link("Sidebar Categories")
|
2023-02-21 16:55:44 -05:00
|
|
|
end
|
2023-03-26 22:03:16 -04:00
|
|
|
|
|
|
|
it "validates custom section fields" do
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-03-26 22:03:16 -04:00
|
|
|
visit("/latest")
|
2023-05-18 21:31:25 -04:00
|
|
|
sidebar.click_add_section_button
|
2023-03-26 22:03:16 -04:00
|
|
|
|
|
|
|
section_modal.fill_name("A" * (SidebarSection::MAX_TITLE_LENGTH + 1))
|
FIX: Simplify sidebar custom link implementation (#26201)
All our link validation, and conversion from url -> route/model/query is expensive and prone to bugs. Instead, if people enter a link, we can just use it as-is.
Originally all this extra logic was added to handle unusual situations like `/safe-mode`, `/my/...`, etc. However, all of these are now handled correctly by our Ember router, so there is no need for it.
Now, we just pass the user-supplied `href` directly to the SectionLink component, and let Ember handle routing to it when clicked.
The only functional change here is that we no longer validate internal links by parsing them with the Ember router. But I'd argue this is fine, because the previous logic would cause both false positives (e.g. `/t/123` would be valid, even if topic 123 doesn't exist), and false negatives (for routes which are server-side only, like the new AI share pages).
2024-03-20 08:55:40 -04:00
|
|
|
section_modal.fill_link("B" * (SidebarUrl::MAX_NAME_LENGTH + 1), "https:")
|
2023-03-26 22:03:16 -04:00
|
|
|
|
|
|
|
expect(page.find(".title.warning")).to have_content("Title must be shorter than 30 characters")
|
|
|
|
expect(page.find(".name.warning")).to have_content("Name must be shorter than 80 characters")
|
|
|
|
expect(page.find(".value.warning")).to have_content("Format is invalid")
|
|
|
|
|
|
|
|
section_modal.fill_name("")
|
|
|
|
section_modal.fill_link("", "")
|
|
|
|
expect(page.find(".title.warning")).to have_content("Title cannot be blank")
|
|
|
|
expect(page.find(".name.warning")).to have_content("Name cannot be blank")
|
|
|
|
expect(page.find(".value.warning")).to have_content("Link cannot be blank")
|
|
|
|
|
|
|
|
expect(section_modal).to have_disabled_save
|
|
|
|
end
|
2024-07-09 17:32:29 -04:00
|
|
|
|
|
|
|
it "allows the user to expand/collapse section containing unicode titles separately" do
|
|
|
|
sidebar_section1 = Fabricate(:sidebar_section, title: "談話", user: user)
|
|
|
|
Fabricate(:sidebar_url, name: "Sidebar Latest", value: "/latest").tap do |sidebar_url|
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section1, linkable: sidebar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
sidebar_section2 = Fabricate(:sidebar_section, title: "趣", user: user)
|
|
|
|
Fabricate(:sidebar_url, name: "Sidebar Categories", value: "/categories").tap do |sidebar_url|
|
|
|
|
Fabricate(:sidebar_section_link, sidebar_section: sidebar_section2, linkable: sidebar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
sign_in user
|
|
|
|
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
expect(sidebar).to have_section_expanded("談話")
|
|
|
|
expect(sidebar).to have_section_expanded("趣")
|
|
|
|
|
|
|
|
sidebar.click_section_header("談話")
|
|
|
|
expect(sidebar).to have_section_collapsed("談話")
|
|
|
|
expect(sidebar).to have_section_expanded("趣")
|
|
|
|
|
|
|
|
sidebar.click_section_header("趣")
|
|
|
|
expect(sidebar).to have_section_collapsed("談話")
|
|
|
|
expect(sidebar).to have_section_collapsed("趣")
|
|
|
|
|
|
|
|
sidebar.click_section_header("談話")
|
|
|
|
expect(sidebar).to have_section_expanded("談話")
|
|
|
|
expect(sidebar).to have_section_collapsed("趣")
|
|
|
|
|
|
|
|
sidebar.click_section_header("趣")
|
|
|
|
expect(sidebar).to have_section_expanded("談話")
|
|
|
|
expect(sidebar).to have_section_expanded("趣")
|
|
|
|
end
|
2023-02-02 22:44:40 -05:00
|
|
|
end
|