2023-02-02 22:44:40 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe "Custom sidebar sections", type: :system, js: true do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2023-02-21 16:55:44 -05:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2023-02-02 22:44:40 -05:00
|
|
|
let(:section_modal) { PageObjects::Modals::SidebarSectionForm.new }
|
|
|
|
let(:sidebar) { PageObjects::Components::Sidebar.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
### TODO remove when enable_custom_sidebar_sections SiteSetting is removed
|
|
|
|
group = Fabricate(:group)
|
|
|
|
Fabricate(:group_user, group: group, user: user)
|
2023-02-21 16:55:44 -05:00
|
|
|
Fabricate(:group_user, group: group, user: admin)
|
2023-02-02 22:44:40 -05:00
|
|
|
SiteSetting.enable_custom_sidebar_sections = group.id.to_s
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows the user to create custom section" do
|
|
|
|
visit("/latest")
|
|
|
|
sidebar.open_new_custom_section
|
|
|
|
|
|
|
|
expect(section_modal).to be_visible
|
|
|
|
expect(section_modal).to have_disabled_save
|
2023-03-06 19:47:18 -05:00
|
|
|
expect(sidebar.custom_section_modal_title).to have_content("Add custom section")
|
2023-02-02 22:44:40 -05:00
|
|
|
|
|
|
|
section_modal.fill_name("My section")
|
|
|
|
|
|
|
|
section_modal.fill_link("Sidebar Tags", "/tags")
|
|
|
|
expect(section_modal).to have_enabled_save
|
|
|
|
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(page).to have_button("My section")
|
2023-03-06 19:47:18 -05:00
|
|
|
expect(sidebar).to have_link("Sidebar Tags")
|
|
|
|
end
|
|
|
|
|
2023-03-21 00:58:42 -04:00
|
|
|
it "allows the user to create custom section with /my 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("My preferences", "/my/preferences")
|
|
|
|
expect(section_modal).to have_enabled_save
|
|
|
|
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(page).to have_button("My section")
|
|
|
|
expect(sidebar).to have_link("My preferences")
|
|
|
|
end
|
|
|
|
|
2023-03-06 19:47:18 -05:00
|
|
|
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")
|
2023-02-02 22:44:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).to have_button("Edited section")
|
2023-03-06 19:47:18 -05:00
|
|
|
expect(sidebar).to have_link("Edited Tag")
|
|
|
|
|
2023-02-02 22:44:40 -05:00
|
|
|
expect(page).not_to have_link("Sidebar Categories")
|
|
|
|
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)
|
|
|
|
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")
|
|
|
|
within(".sidebar-custom-sections .sidebar-section-link-wrapper:nth-child(1)") do
|
|
|
|
expect(page).to have_css(".sidebar-section-link-sidebar-tags")
|
|
|
|
end
|
|
|
|
within(".sidebar-custom-sections .sidebar-section-link-wrapper:nth-child(2)") do
|
|
|
|
expect(page).to have_css(".sidebar-section-link-sidebar-categories")
|
|
|
|
end
|
|
|
|
|
|
|
|
tags_link = find(".sidebar-section-link-sidebar-tags")
|
|
|
|
categories_link = find(".sidebar-section-link-sidebar-categories")
|
2023-03-23 22:58:05 -04:00
|
|
|
tags_link.drag_to(categories_link, html5: true, delay: 0.4)
|
2023-03-20 21:23:28 -04:00
|
|
|
|
|
|
|
within(".sidebar-custom-sections .sidebar-section-link-wrapper:nth-child(1)") do
|
|
|
|
expect(page).to have_css(".sidebar-section-link-sidebar-categories")
|
|
|
|
end
|
|
|
|
within(".sidebar-custom-sections .sidebar-section-link-wrapper:nth-child(2)") do
|
|
|
|
expect(page).to have_css(".sidebar-section-link-sidebar-tags")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-21 16:55:44 -05:00
|
|
|
it "does not allow the user to edit public section" do
|
|
|
|
sidebar_section = Fabricate(:sidebar_section, title: "Public section", user: user, 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(page).to have_button("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)
|
|
|
|
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
sidebar.edit_custom_section("My section")
|
|
|
|
|
|
|
|
section_modal.delete
|
|
|
|
section_modal.confirm_delete
|
|
|
|
|
|
|
|
expect(page).not_to have_button("My section")
|
|
|
|
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")
|
|
|
|
sidebar.open_new_custom_section
|
|
|
|
|
|
|
|
section_modal.fill_name("Public section")
|
|
|
|
section_modal.fill_link("Sidebar Tags", "/tags")
|
|
|
|
section_modal.mark_as_public
|
|
|
|
section_modal.save
|
|
|
|
|
|
|
|
expect(page).to have_button("Public section")
|
2023-03-06 19:47:18 -05:00
|
|
|
expect(sidebar).to have_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
|
|
|
|
|
|
|
|
expect(page).to have_button("Edited public section")
|
|
|
|
|
|
|
|
sidebar.edit_custom_section("Edited public section")
|
|
|
|
section_modal.delete
|
|
|
|
section_modal.confirm_delete
|
|
|
|
|
|
|
|
expect(page).not_to have_button("Edited public section")
|
|
|
|
end
|
2023-02-02 22:44:40 -05:00
|
|
|
end
|