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-02-02 22:44:40 -05:00
|
|
|
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 }
|
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-02-02 22:44:40 -05:00
|
|
|
it "allows the user to create custom section" do
|
2023-05-18 21:31:25 -04:00
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
expect(sidebar).to have_no_add_section_button
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
sign_in user
|
2023-02-02 22:44:40 -05:00
|
|
|
visit("/latest")
|
2023-05-18 21:31:25 -04:00
|
|
|
sidebar.click_add_section_button
|
2023-02-02 22:44:40 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-04-05 18:55:47 -04:00
|
|
|
expect(sidebar).to have_section("My section")
|
2023-04-12 03:52:10 -04:00
|
|
|
expect(sidebar).to have_section_link("Sidebar Tags")
|
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
|
|
|
|
|
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", "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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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-04-12 03:52:10 -04:00
|
|
|
tags_link = find(".sidebar-section-link[data-link-name='Sidebar Tags']")
|
2023-07-10 21:40:37 -04:00
|
|
|
latest_link = find(".sidebar-section-link[data-link-name='Sidebar Latest']")
|
|
|
|
tags_link.drag_to(latest_link, html5: true, delay: 0.4)
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
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))
|
|
|
|
section_modal.fill_link("B" * (SidebarUrl::MAX_NAME_LENGTH + 1), "/wrong-url")
|
|
|
|
|
|
|
|
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
|
2023-02-02 22:44:40 -05:00
|
|
|
end
|