2023-10-19 12:23:41 +08:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2023-11-20 23:49:49 +08:00
|
|
|
|
describe "Admin Revamp | Sidebar Navigation", type: :system do
|
2023-11-10 06:47:59 +08:00
|
|
|
|
fab!(:admin)
|
2024-04-29 09:32:47 +08:00
|
|
|
|
fab!(:moderator)
|
2024-01-12 12:49:08 +08:00
|
|
|
|
|
2023-12-18 09:48:25 +08:00
|
|
|
|
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
|
2024-01-12 12:49:08 +08:00
|
|
|
|
let(:sidebar_dropdown) { PageObjects::Components::SidebarHeaderDropdown.new }
|
2024-02-28 09:15:02 +08:00
|
|
|
|
let(:filter) { PageObjects::Components::Filter.new }
|
2023-10-19 12:23:41 +08:00
|
|
|
|
|
|
|
|
|
before do
|
2024-04-29 13:01:33 +08:00
|
|
|
|
SiteSetting.navigation_menu = "sidebar"
|
2024-04-29 09:32:47 +08:00
|
|
|
|
SiteSetting.admin_sidebar_enabled_groups = [
|
|
|
|
|
Group::AUTO_GROUPS[:admins],
|
|
|
|
|
Group::AUTO_GROUPS[:moderators],
|
|
|
|
|
]
|
2024-04-29 13:01:33 +08:00
|
|
|
|
|
2023-10-19 12:23:41 +08:00
|
|
|
|
sign_in(admin)
|
|
|
|
|
end
|
|
|
|
|
|
2023-12-18 09:48:25 +08:00
|
|
|
|
it "shows the sidebar when navigating to an admin route and hides it when leaving" do
|
2023-10-19 12:23:41 +08:00
|
|
|
|
visit("/latest")
|
2024-03-27 11:42:06 +08:00
|
|
|
|
expect(sidebar).to have_section("categories")
|
2023-12-18 09:48:25 +08:00
|
|
|
|
sidebar.click_link_in_section("community", "admin")
|
|
|
|
|
expect(page).to have_current_path("/admin")
|
|
|
|
|
expect(sidebar).to be_visible
|
2024-03-27 11:42:06 +08:00
|
|
|
|
expect(sidebar).to have_no_section("categories")
|
2023-12-18 09:48:25 +08:00
|
|
|
|
expect(page).to have_no_css(".admin-main-nav")
|
2024-03-07 11:48:16 +08:00
|
|
|
|
filter.click_back_to_forum
|
2024-10-08 22:05:08 +08:00
|
|
|
|
expect(page).to have_current_path("/")
|
2024-03-27 11:42:06 +08:00
|
|
|
|
expect(sidebar).to have_no_section("admin-root")
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-08 22:05:08 +08:00
|
|
|
|
context "with subfolder" do
|
|
|
|
|
before { set_subfolder "/discuss" }
|
|
|
|
|
|
|
|
|
|
it "navigates back to homepage correctly" do
|
|
|
|
|
visit("/discuss/admin")
|
|
|
|
|
|
|
|
|
|
filter.click_back_to_forum
|
|
|
|
|
expect(page).to have_current_path("/discuss/")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-06 00:11:15 +08:00
|
|
|
|
it "displays the panel header" do
|
|
|
|
|
visit("/admin")
|
|
|
|
|
expect(sidebar).to have_panel_header
|
|
|
|
|
end
|
|
|
|
|
|
2024-03-27 11:42:06 +08:00
|
|
|
|
it "collapses sections by default" do
|
|
|
|
|
visit("/admin")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
2024-12-17 07:07:24 +08:00
|
|
|
|
expect(links.count).to eq(5)
|
|
|
|
|
expect(links.map(&:text)).to eq(
|
|
|
|
|
["Dashboard", "Users", "Groups", "All Site Settings", "What's New"],
|
|
|
|
|
)
|
2023-12-18 09:48:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
2024-01-12 12:49:08 +08:00
|
|
|
|
context "when on mobile" do
|
|
|
|
|
it "shows the admin sidebar links in the header-dropdown when navigating to an admin route and hides them when leaving",
|
|
|
|
|
mobile: true do
|
|
|
|
|
visit("/latest")
|
|
|
|
|
sidebar_dropdown.click
|
|
|
|
|
expect(sidebar).to have_section("community")
|
|
|
|
|
sidebar.click_link_in_section("community", "admin")
|
|
|
|
|
expect(page).to have_current_path("/admin")
|
|
|
|
|
sidebar_dropdown.click
|
|
|
|
|
expect(sidebar).to have_no_section("community")
|
|
|
|
|
expect(page).to have_no_css(".admin-main-nav")
|
2024-03-07 11:48:16 +08:00
|
|
|
|
filter.click_back_to_forum
|
2024-10-08 22:05:08 +08:00
|
|
|
|
expect(page).to have_current_path("/")
|
2024-01-12 12:49:08 +08:00
|
|
|
|
sidebar_dropdown.click
|
2024-03-27 11:42:06 +08:00
|
|
|
|
expect(sidebar).to have_no_section("admin-root")
|
2024-01-12 12:49:08 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-12-21 09:37:20 +08:00
|
|
|
|
context "when the setting is disabled" do
|
2024-01-09 07:06:27 +08:00
|
|
|
|
before { SiteSetting.admin_sidebar_enabled_groups = "" }
|
2023-12-21 09:37:20 +08:00
|
|
|
|
|
|
|
|
|
it "does not show the admin sidebar" do
|
|
|
|
|
visit("/latest")
|
|
|
|
|
sidebar.click_link_in_section("community", "admin")
|
|
|
|
|
expect(page).to have_current_path("/admin")
|
2024-03-27 11:42:06 +08:00
|
|
|
|
expect(sidebar).to have_no_section("admin-root")
|
2023-12-21 09:37:20 +08:00
|
|
|
|
end
|
2023-10-19 12:23:41 +08:00
|
|
|
|
end
|
2024-02-28 09:15:02 +08:00
|
|
|
|
|
|
|
|
|
it "allows links to be filtered" do
|
|
|
|
|
visit("/admin")
|
2024-03-27 11:42:06 +08:00
|
|
|
|
sidebar.toggle_all_sections
|
2024-02-28 09:15:02 +08:00
|
|
|
|
|
2024-07-20 00:39:22 +08:00
|
|
|
|
expect(page).to have_selector(".sidebar-section-link-content-text", minimum: 50)
|
2024-02-28 09:15:02 +08:00
|
|
|
|
expect(page).to have_no_css(".sidebar-no-results")
|
2024-07-20 00:39:22 +08:00
|
|
|
|
all_links_count = page.all(".sidebar-section-link-content-text").count
|
2024-02-28 09:15:02 +08:00
|
|
|
|
|
|
|
|
|
filter.filter("ie")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.count).to eq(2)
|
2024-03-13 07:18:08 +08:00
|
|
|
|
expect(links.map(&:text)).to eq(["User Fields", "Preview Summary"])
|
2024-02-28 09:15:02 +08:00
|
|
|
|
expect(page).to have_no_css(".sidebar-no-results")
|
|
|
|
|
|
|
|
|
|
filter.filter("ieeee")
|
|
|
|
|
expect(page).to have_no_css(".sidebar-section-link-content-text")
|
|
|
|
|
expect(page).to have_css(".sidebar-no-results")
|
|
|
|
|
|
|
|
|
|
filter.clear
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.count).to eq(all_links_count)
|
|
|
|
|
expect(page).to have_no_css(".sidebar-no-results")
|
2024-03-07 11:48:16 +08:00
|
|
|
|
expect(page).to have_css(".sidebar-sections__back-to-forum")
|
2024-02-28 09:15:02 +08:00
|
|
|
|
|
|
|
|
|
# When match section title, display all links
|
2024-03-13 07:18:08 +08:00
|
|
|
|
filter.filter("Email Sett")
|
2024-02-28 09:15:02 +08:00
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
2024-03-13 07:18:08 +08:00
|
|
|
|
expect(links.count).to eq(3)
|
|
|
|
|
expect(links.map(&:text)).to eq(["Appearance", "Preview Summary", "Server Setup"])
|
2024-06-04 10:23:21 +08:00
|
|
|
|
|
|
|
|
|
filter.filter(" preview ")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.count).to eq(1)
|
|
|
|
|
expect(links.map(&:text)).to eq(["Preview Summary"])
|
|
|
|
|
expect(page).to have_no_css(".sidebar-no-results")
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-06 04:54:22 +08:00
|
|
|
|
it "escapes the filtered expression for regex expressions" do
|
|
|
|
|
visit("/admin")
|
|
|
|
|
|
|
|
|
|
filter.filter(".*") # this shouldn't return any results if the expression was escaped
|
|
|
|
|
expect(page).to have_no_css(".sidebar-section-link-content-text")
|
|
|
|
|
expect(page).to have_css(".sidebar-no-results")
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-06 00:11:15 +08:00
|
|
|
|
it "displays the no results description message correctly when the filter has no results" do
|
|
|
|
|
visit("/admin")
|
|
|
|
|
|
|
|
|
|
filter.filter("ieeee")
|
|
|
|
|
expect(page).to have_no_css(".sidebar-section-link-content-text")
|
|
|
|
|
expect(page).to have_css(".sidebar-no-results")
|
|
|
|
|
|
|
|
|
|
no_results_description = page.find(".sidebar-no-results__description")
|
|
|
|
|
expect(no_results_description.text).to eq(
|
|
|
|
|
"We couldn’t find anything matching ‘ieeee’.\n\nDid you want to search site settings or the admin user list?",
|
|
|
|
|
)
|
|
|
|
|
expect(no_results_description).to have_link(
|
|
|
|
|
"search site settings",
|
|
|
|
|
href: "/admin/site_settings/category/all_results?filter=ieeee",
|
|
|
|
|
)
|
|
|
|
|
expect(no_results_description).to have_link(
|
|
|
|
|
"admin user list?",
|
|
|
|
|
href: "/admin/users/list/active?username=ieeee",
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-06 04:54:22 +08:00
|
|
|
|
it "encodes the url param in the links when the filter has no results" do
|
|
|
|
|
visit("/admin")
|
|
|
|
|
|
|
|
|
|
filter.filter("?")
|
|
|
|
|
expect(page).to have_no_css(".sidebar-section-link-content-text")
|
|
|
|
|
expect(page).to have_css(".sidebar-no-results")
|
|
|
|
|
|
|
|
|
|
no_results_description = page.find(".sidebar-no-results__description")
|
|
|
|
|
expect(no_results_description.text).to eq(
|
|
|
|
|
"We couldn’t find anything matching ‘?’.\n\nDid you want to search site settings or the admin user list?",
|
|
|
|
|
)
|
|
|
|
|
expect(no_results_description).to have_link(
|
|
|
|
|
"search site settings",
|
|
|
|
|
href: "/admin/site_settings/category/all_results?filter=%3F",
|
|
|
|
|
)
|
|
|
|
|
expect(no_results_description).to have_link(
|
|
|
|
|
"admin user list?",
|
|
|
|
|
href: "/admin/users/list/active?username=%3F",
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-04 10:23:21 +08:00
|
|
|
|
it "temporarily expands section when filter" do
|
|
|
|
|
visit("/admin")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
2024-12-17 07:07:24 +08:00
|
|
|
|
expect(links.count).to eq(5)
|
|
|
|
|
expect(links.map(&:text)).to eq(
|
|
|
|
|
["Dashboard", "Users", "Groups", "All Site Settings", "What's New"],
|
|
|
|
|
)
|
2024-06-04 10:23:21 +08:00
|
|
|
|
|
|
|
|
|
filter.filter("ie")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.count).to eq(2)
|
|
|
|
|
expect(links.map(&:text)).to eq(["User Fields", "Preview Summary"])
|
|
|
|
|
|
|
|
|
|
filter.filter("")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
2024-12-17 07:07:24 +08:00
|
|
|
|
expect(links.count).to eq(5)
|
|
|
|
|
expect(links.map(&:text)).to eq(
|
|
|
|
|
["Dashboard", "Users", "Groups", "All Site Settings", "What's New"],
|
|
|
|
|
)
|
2024-02-28 09:15:02 +08:00
|
|
|
|
end
|
2024-03-14 09:28:08 +08:00
|
|
|
|
|
2024-04-19 08:55:17 +08:00
|
|
|
|
it "allows further filtering of site settings or users if links do not show results" do
|
2024-04-29 13:01:33 +08:00
|
|
|
|
user_1 = Fabricate(:user, username: "moltisanti", name: "Christopher Moltisanti")
|
|
|
|
|
user_2 = Fabricate(:user, username: "bevelaqua", name: "Matthew Bevelaqua")
|
|
|
|
|
|
2024-04-19 08:55:17 +08:00
|
|
|
|
visit("/admin")
|
|
|
|
|
filter.filter("user locale")
|
|
|
|
|
find(".sidebar-additional-filter-settings").click
|
|
|
|
|
expect(page).to have_current_path(
|
|
|
|
|
"/admin/site_settings/category/all_results?filter=user%20locale",
|
|
|
|
|
)
|
|
|
|
|
expect(page).to have_content(I18n.t("site_settings.allow_user_locale"))
|
|
|
|
|
|
|
|
|
|
filter.filter("log_search_queries")
|
|
|
|
|
find(".sidebar-additional-filter-settings").click
|
|
|
|
|
expect(page).to have_current_path(
|
|
|
|
|
"/admin/site_settings/category/all_results?filter=log_search_queries",
|
|
|
|
|
)
|
|
|
|
|
expect(page).to have_content(I18n.t("site_settings.log_search_queries"))
|
|
|
|
|
|
|
|
|
|
filter.filter("bevelaqua")
|
|
|
|
|
find(".sidebar-additional-filter-users").click
|
|
|
|
|
expect(page).to have_current_path("/admin/users/list/active?username=bevelaqua")
|
2024-05-02 11:27:24 +08:00
|
|
|
|
expect(find(".users-list-container")).to have_content("bevelaqua")
|
2024-04-19 08:55:17 +08:00
|
|
|
|
|
|
|
|
|
filter.filter("moltisanti")
|
|
|
|
|
find(".sidebar-additional-filter-users").click
|
|
|
|
|
expect(page).to have_current_path("/admin/users/list/active?username=moltisanti")
|
2024-05-02 11:27:24 +08:00
|
|
|
|
expect(find(".users-list-container")).to have_content("moltisanti")
|
2024-04-19 08:55:17 +08:00
|
|
|
|
end
|
|
|
|
|
|
2024-03-27 11:42:06 +08:00
|
|
|
|
it "allows sections to be expanded" do
|
|
|
|
|
visit("/admin")
|
|
|
|
|
sidebar.toggle_all_sections
|
2024-07-20 00:39:22 +08:00
|
|
|
|
expect(page).to have_selector(".sidebar-section-link-content-text", minimum: 50)
|
2024-03-27 11:42:06 +08:00
|
|
|
|
|
2024-07-20 00:39:22 +08:00
|
|
|
|
sidebar.toggle_all_sections
|
2024-12-17 07:07:24 +08:00
|
|
|
|
expect(page).to have_selector(".sidebar-section-link-content-text", count: 5)
|
2024-07-20 00:39:22 +08:00
|
|
|
|
expect(all(".sidebar-section-link-content-text").map(&:text)).to eq(
|
2024-12-17 07:07:24 +08:00
|
|
|
|
["Dashboard", "Users", "Groups", "All Site Settings", "What's New"],
|
2024-07-20 00:39:22 +08:00
|
|
|
|
)
|
2024-03-27 11:42:06 +08:00
|
|
|
|
|
|
|
|
|
sidebar.toggle_all_sections
|
2024-07-20 00:39:22 +08:00
|
|
|
|
expect(page).to have_selector(".sidebar-section-link-content-text", minimum: 50)
|
2024-03-27 11:42:06 +08:00
|
|
|
|
end
|
|
|
|
|
|
2024-03-14 09:28:08 +08:00
|
|
|
|
it "accepts hidden keywords like installed plugin names for filter" do
|
|
|
|
|
Discourse.instance_variable_set(
|
|
|
|
|
"@plugins",
|
|
|
|
|
Plugin::Instance.find_all("#{Rails.root}/spec/fixtures/plugins"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
visit("/admin")
|
2024-03-27 11:42:06 +08:00
|
|
|
|
sidebar.toggle_all_sections
|
2024-03-14 09:28:08 +08:00
|
|
|
|
filter.filter("csp_extension")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.count).to eq(1)
|
|
|
|
|
expect(links.map(&:text)).to eq(["Installed"])
|
|
|
|
|
end
|
2024-04-08 13:21:24 +08:00
|
|
|
|
|
2024-04-24 10:34:38 +08:00
|
|
|
|
it "accepts components and themes keywords for filter" do
|
|
|
|
|
Fabricate(:theme, name: "Air theme", component: false)
|
|
|
|
|
Fabricate(:theme, name: "Kanban", component: true)
|
|
|
|
|
|
|
|
|
|
visit("/admin")
|
|
|
|
|
sidebar.toggle_all_sections
|
|
|
|
|
|
|
|
|
|
filter.filter("air")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.count).to eq(1)
|
|
|
|
|
expect(links.map(&:text)).to eq(["Themes"])
|
|
|
|
|
|
|
|
|
|
filter.filter("kanban")
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.count).to eq(1)
|
|
|
|
|
expect(links.map(&:text)).to eq(["Components"])
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-08 13:21:24 +08:00
|
|
|
|
it "does not show the button to customize sidebar sections, that is only supported in the main panel" do
|
|
|
|
|
visit("/")
|
|
|
|
|
expect(sidebar).to have_add_section_button
|
|
|
|
|
visit("/admin")
|
|
|
|
|
expect(sidebar).to have_no_add_section_button
|
|
|
|
|
end
|
2024-04-29 09:32:47 +08:00
|
|
|
|
|
|
|
|
|
it "displays limited links for moderator" do
|
|
|
|
|
sign_in(moderator)
|
|
|
|
|
visit("/admin")
|
|
|
|
|
|
|
|
|
|
sidebar.toggle_all_sections
|
|
|
|
|
|
|
|
|
|
links = page.all(".sidebar-section-link-content-text")
|
|
|
|
|
expect(links.map(&:text)).to eq(
|
|
|
|
|
[
|
|
|
|
|
"Dashboard",
|
2024-06-05 10:49:46 +08:00
|
|
|
|
"Users",
|
2024-12-17 07:07:24 +08:00
|
|
|
|
"Groups",
|
2024-04-30 08:34:12 +08:00
|
|
|
|
"What's New",
|
|
|
|
|
"All",
|
2024-04-29 09:32:47 +08:00
|
|
|
|
"Watched Words",
|
|
|
|
|
"Screened Emails",
|
|
|
|
|
"Screened IPs",
|
|
|
|
|
"Screened URLs",
|
|
|
|
|
"Search Logs",
|
|
|
|
|
"Staff Action Logs",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
end
|
2023-10-19 12:23:41 +08:00
|
|
|
|
end
|