From 2effcaa0f96d89423330c9bb9d93f81bd078a25e Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 15 Jun 2023 09:31:28 +1000 Subject: [PATCH] FIX: Update sidebar to be navigation menu (#22101) Communities can use sidebar or header dropdown, therefore navigation menu is a better name settings in 2 places: - Old user sidebar preferences; - Site setting about default tags and categories. --- .../admin/addon/mixins/setting-component.js | 4 +- .../sidebar/anonymous/categories-section.js | 6 +-- .../sidebar/anonymous/tags-section.js | 6 +-- .../sidebar/user/categories-section.hbs | 6 +-- .../sidebar/user/categories-section.js | 4 +- .../components/sidebar/user/tags-section.hbs | 4 +- .../components/sidebar/user/tags-section.js | 4 +- .../{sidebar.js => navigation-menu.js} | 2 +- .../everything-section-link.js | 2 +- .../category-section-link.js | 2 +- .../my-posts-section-link.js | 2 +- .../user/tags-section/tag-section-link.js | 2 +- .../discourse/app/routes/app-route-map.js | 2 +- ...ebar.js => preferences-navigation-menu.js} | 0 .../discourse/app/templates/preferences.hbs | 6 +-- .../{sidebar.hbs => navigation-menu.hbs} | 8 ++-- ...debar-anonymous-categories-section-test.js | 8 ++-- .../sidebar-anonymous-tags-section-test.js | 4 +- .../acceptance/sidebar-plugin-api-test.js | 2 +- .../sidebar-user-categories-section-test.js | 18 ++++---- .../sidebar-user-tags-section-test.js | 12 ++--- ... user-preferences-navigation-menu-test.js} | 12 ++--- .../admin/site_settings_controller.rb | 2 +- app/models/user.rb | 8 ++-- app/serializers/site_serializer.rb | 10 ++--- .../sidebar_site_settings_backfiller.rb | 4 +- config/locales/client.en.yml | 8 ++-- config/locales/server.en.yml | 4 +- config/routes.rb | 2 +- config/site_settings.yml | 4 +- ...name_default_sidebar_categories_setting.rb | 7 +++ ...419_rename_default_sidebar_tags_setting.rb | 7 +++ lib/seed_data/categories.rb | 4 +- spec/lib/seed_data/categories_spec.rb | 4 +- spec/models/user_spec.rb | 4 +- .../admin/site_settings_controller_spec.rb | 38 ++++++++-------- spec/serializers/site_serializer_spec.rb | 16 +++---- .../sidebar_site_settings_backfiller_spec.rb | 44 +++++++++++-------- ...ting_sidebar_categories_navigation_spec.rb | 2 +- ...rb => user_preferences_navigation_menu.rb} | 12 ++--- ...ewing_navigation_menu_preferences_spec.rb} | 19 +++++--- 41 files changed, 171 insertions(+), 144 deletions(-) rename app/assets/javascripts/discourse/app/controllers/preferences/{sidebar.js => navigation-menu.js} (96%) rename app/assets/javascripts/discourse/app/routes/{preferences-sidebar.js => preferences-navigation-menu.js} (100%) rename app/assets/javascripts/discourse/app/templates/preferences/{sidebar.hbs => navigation-menu.hbs} (85%) rename app/assets/javascripts/discourse/tests/acceptance/{user-preferences-sidebar-test.js => user-preferences-navigation-menu-test.js} (95%) create mode 100644 db/migrate/20230614011312_rename_default_sidebar_categories_setting.rb create mode 100644 db/migrate/20230614011419_rename_default_sidebar_tags_setting.rb rename spec/system/page_objects/pages/{user_preferences_sidebar.rb => user_preferences_navigation_menu.rb} (61%) rename spec/system/{viewing_sidebar_preferences_spec.rb => viewing_navigation_menu_preferences_spec.rb} (64%) diff --git a/app/assets/javascripts/admin/addon/mixins/setting-component.js b/app/assets/javascripts/admin/addon/mixins/setting-component.js index fa1675ce542..0127f5b6af0 100644 --- a/app/assets/javascripts/admin/addon/mixins/setting-component.js +++ b/app/assets/javascripts/admin/addon/mixins/setting-component.js @@ -67,8 +67,8 @@ const DEFAULT_USER_PREFERENCES = [ "default_tags_watching_first_post", "default_text_size", "default_title_count_mode", - "default_sidebar_categories", - "default_sidebar_tags", + "default_navigation_menu_categories", + "default_navigation_menu_tags", ]; export default Mixin.create({ diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/categories-section.js b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/categories-section.js index b1a2d849d26..c4243386dd6 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/categories-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/categories-section.js @@ -6,15 +6,15 @@ export default class SidebarAnonymousCategoriesSection extends SidebarCommonCate constructor() { super(...arguments); - if (!this.siteSettings.default_sidebar_categories) { + if (!this.siteSettings.default_navigation_menu_categories) { this.shouldSortCategoriesByDefault = false; } } get categories() { - if (this.siteSettings.default_sidebar_categories) { + if (this.siteSettings.default_navigation_menu_categories) { return Category.findByIds( - this.siteSettings.default_sidebar_categories + this.siteSettings.default_navigation_menu_categories .split("|") .map((categoryId) => parseInt(categoryId, 10)) ); diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.js b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.js index 3a3596ad520..51f99172ffc 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.js @@ -10,7 +10,7 @@ export default class SidebarAnonymousTagsSection extends Component { get displaySection() { return ( - this.site.anonymous_default_sidebar_tags?.length > 0 || + this.site.anonymous_default_navigation_menu_tags?.length > 0 || this.site.top_tags?.length > 0 ); } @@ -19,8 +19,8 @@ export default class SidebarAnonymousTagsSection extends Component { get sectionLinks() { let tags; - if (this.site.anonymous_default_sidebar_tags) { - tags = this.site.anonymous_default_sidebar_tags; + if (this.site.anonymous_default_navigation_menu_tags) { + tags = this.site.anonymous_default_navigation_menu_tags; } else { tags = this.site.top_tags.slice(0, 5); } diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbs b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbs index f02dabc5afd..10f52cc4ae3 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.hbs @@ -50,7 +50,7 @@ {{else}} {{/if}} diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.js b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.js index dc9fd581c50..d14a16cd2e3 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/user/categories-section.js @@ -70,7 +70,7 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie } get hasDefaultSidebarCategories() { - return this.siteSettings.default_sidebar_categories.length > 0; + return this.siteSettings.default_navigation_menu_categories.length > 0; } @action @@ -80,7 +80,7 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie ) { showModal("sidebar-categories-form"); } else { - this.router.transitionTo("preferences.sidebar", this.currentUser); + this.router.transitionTo("preferences.navigation-menu", this.currentUser); } } } diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbs b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbs index 7c997cb3488..95bacd60845 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.hbs @@ -34,7 +34,7 @@ {{else}} {{/if}} diff --git a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.js b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.js index a622605e4e9..70f747058f4 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/user/tags-section.js @@ -74,11 +74,11 @@ export default class SidebarUserTagsSection extends Component { } get hasDefaultSidebarTags() { - return this.siteSettings.default_sidebar_tags.length > 0; + return this.siteSettings.default_navigation_menu_tags.length > 0; } @action editTracked() { - this.router.transitionTo("preferences.sidebar", this.currentUser); + this.router.transitionTo("preferences.navigation-menu", this.currentUser); } } diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/sidebar.js b/app/assets/javascripts/discourse/app/controllers/preferences/navigation-menu.js similarity index 96% rename from app/assets/javascripts/discourse/app/controllers/preferences/sidebar.js rename to app/assets/javascripts/discourse/app/controllers/preferences/navigation-menu.js index 101a29dc18b..583abbec60e 100644 --- a/app/assets/javascripts/discourse/app/controllers/preferences/sidebar.js +++ b/app/assets/javascripts/discourse/app/controllers/preferences/navigation-menu.js @@ -12,7 +12,7 @@ export default class extends Controller { @tracked saved = false; @tracked selectedSidebarCategories = []; @tracked selectedSidebarTagNames = []; - subpageTitle = I18n.t("user.preferences_nav.sidebar"); + subpageTitle = I18n.t("user.preferences_nav.navigation_menu"); saveAttrNames = [ "sidebar_category_ids", diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/everything-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/everything-section-link.js index da7dce35350..9f1c6c5bc1e 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/everything-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/everything-section-link.js @@ -2,7 +2,7 @@ import I18n from "I18n"; import { tracked } from "@glimmer/tracking"; import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link"; -import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar"; +import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu"; export default class EverythingSectionLink extends BaseSectionLink { @tracked totalUnread = 0; diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js index 5e8db460d10..26fcf5720f7 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js @@ -5,7 +5,7 @@ import { get, set } from "@ember/object"; import { bind } from "discourse-common/utils/decorators"; import Category from "discourse/models/category"; -import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar"; +import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu"; const UNREAD_AND_NEW_COUNTABLE = { propertyName: "unreadAndNewCount", diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js index 4c7a54f20ee..be002344739 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js @@ -2,7 +2,7 @@ import I18n from "I18n"; import { tracked } from "@glimmer/tracking"; import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link"; -import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar"; +import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu"; const USER_DRAFTS_CHANGED_EVENT = "user-drafts:changed"; diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/user/tags-section/tag-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/user/tags-section/tag-section-link.js index 5f05849ba05..4f5d188c8c7 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/user/tags-section/tag-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/user/tags-section/tag-section-link.js @@ -4,7 +4,7 @@ import { tracked } from "@glimmer/tracking"; import { bind } from "discourse-common/utils/decorators"; import BaseTagSectionLink from "discourse/lib/sidebar/user/tags-section/base-tag-section-link"; -import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar"; +import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/navigation-menu"; export default class TagSectionLink extends BaseTagSectionLink { @tracked totalUnread = 0; diff --git a/app/assets/javascripts/discourse/app/routes/app-route-map.js b/app/assets/javascripts/discourse/app/routes/app-route-map.js index e1327cca343..f69417b55a8 100644 --- a/app/assets/javascripts/discourse/app/routes/app-route-map.js +++ b/app/assets/javascripts/discourse/app/routes/app-route-map.js @@ -175,7 +175,7 @@ export default function () { this.route("tags"); this.route("interface"); this.route("apps"); - this.route("sidebar"); + this.route("navigation-menu"); this.route("email"); this.route("second-factor"); diff --git a/app/assets/javascripts/discourse/app/routes/preferences-sidebar.js b/app/assets/javascripts/discourse/app/routes/preferences-navigation-menu.js similarity index 100% rename from app/assets/javascripts/discourse/app/routes/preferences-sidebar.js rename to app/assets/javascripts/discourse/app/routes/preferences-navigation-menu.js diff --git a/app/assets/javascripts/discourse/app/templates/preferences.hbs b/app/assets/javascripts/discourse/app/templates/preferences.hbs index 35952ce4157..bde5fc4dd19 100644 --- a/app/assets/javascripts/discourse/app/templates/preferences.hbs +++ b/app/assets/javascripts/discourse/app/templates/preferences.hbs @@ -78,12 +78,12 @@ {{#if (not (eq this.siteSettings.navigation_menu "legacy"))}} {{d-icon "bars"}} - {{i18n "user.preferences_nav.sidebar"}} + {{i18n "user.preferences_nav.navigation_menu"}} {{/if}} diff --git a/app/assets/javascripts/discourse/app/templates/preferences/sidebar.hbs b/app/assets/javascripts/discourse/app/templates/preferences/navigation-menu.hbs similarity index 85% rename from app/assets/javascripts/discourse/app/templates/preferences/sidebar.hbs rename to app/assets/javascripts/discourse/app/templates/preferences/navigation-menu.hbs index ab82ed5bc23..2de39d91d4a 100644 --- a/app/assets/javascripts/discourse/app/templates/preferences/sidebar.hbs +++ b/app/assets/javascripts/discourse/app/templates/preferences/navigation-menu.hbs @@ -1,4 +1,4 @@ -
+
{{i18n "user.experimental_sidebar.categories_section" }} @@ -20,7 +20,7 @@
{{#if this.model.display_sidebar_tags}} -
+
{{i18n "user.experimental_sidebar.tags_section" }} @@ -41,7 +41,7 @@
{{/if}} -
+
{{i18n "user.experimental_sidebar.navigation_section" }} @@ -51,7 +51,7 @@ "user.experimental_sidebar.list_destination_instruction" }} { username: RouteFormat.username, } - get "#{root_path}/:username/preferences/sidebar" => "users#preferences", + get "#{root_path}/:username/preferences/navigation-menu" => "users#preferences", :constraints => { username: RouteFormat.username, } diff --git a/config/site_settings.yml b/config/site_settings.yml index fba73964da2..8ee006f7c28 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -2128,11 +2128,11 @@ navigation: default: "sidebar" type: enum enum: "NavigationMenuSiteSetting" - default_sidebar_categories: + default_navigation_menu_categories: type: category_list default: "" client: true - default_sidebar_tags: + default_navigation_menu_tags: type: tag_list default: "" client: true diff --git a/db/migrate/20230614011312_rename_default_sidebar_categories_setting.rb b/db/migrate/20230614011312_rename_default_sidebar_categories_setting.rb new file mode 100644 index 00000000000..17587163a8e --- /dev/null +++ b/db/migrate/20230614011312_rename_default_sidebar_categories_setting.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class RenameDefaultSidebarCategoriesSetting < ActiveRecord::Migration[7.0] + def change + execute "UPDATE site_settings SET name = 'default_navigation_menu_categories' WHERE name = 'default_sidebar_categories'" + end +end diff --git a/db/migrate/20230614011419_rename_default_sidebar_tags_setting.rb b/db/migrate/20230614011419_rename_default_sidebar_tags_setting.rb new file mode 100644 index 00000000000..38c347bfde3 --- /dev/null +++ b/db/migrate/20230614011419_rename_default_sidebar_tags_setting.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class RenameDefaultSidebarTagsSetting < ActiveRecord::Migration[7.0] + def change + execute "UPDATE site_settings SET name = 'default_navigation_menu_tags' WHERE name = 'default_sidebar_tags'" + end +end diff --git a/lib/seed_data/categories.rb b/lib/seed_data/categories.rb index dd050d86983..e2ca27a13e4 100644 --- a/lib/seed_data/categories.rb +++ b/lib/seed_data/categories.rb @@ -138,9 +138,9 @@ module SeedData SiteSetting.set(site_setting_name, category.id) if sidebar - sidebar_categories = SiteSetting.default_sidebar_categories.split("|") + sidebar_categories = SiteSetting.default_navigation_menu_categories.split("|") sidebar_categories << category.id - SiteSetting.set("default_sidebar_categories", sidebar_categories.join("|")) + SiteSetting.set("default_navigation_menu_categories", sidebar_categories.join("|")) end SiteSetting.set("default_composer_category", category.id) if default_composer_category diff --git a/spec/lib/seed_data/categories_spec.rb b/spec/lib/seed_data/categories_spec.rb index dd52520af22..a9fccb9605c 100644 --- a/spec/lib/seed_data/categories_spec.rb +++ b/spec/lib/seed_data/categories_spec.rb @@ -118,14 +118,14 @@ RSpec.describe SeedData::Categories do expect(category.category_groups.first).to have_attributes(permissions(:staff, :full)) end - it "adds default categories SiteSetting.default_sidebar_categories" do + it "adds default categories SiteSetting.default_navigation_menu_categories" do create_category("staff_category_id") staff_category = Category.last create_category("meta_category_id") site_feedback_category = Category.last create_category("general_category_id") general_category = Category.last - site_setting_ids = SiteSetting.default_sidebar_categories.split("|") + site_setting_ids = SiteSetting.default_navigation_menu_categories.split("|") create_category("uncategorized_category_id") expect(site_setting_ids[0].to_i).to eq(staff_category.id) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fd993516cf8..7c0075e8c45 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -48,8 +48,8 @@ RSpec.describe User do before do SiteSetting.navigation_menu = "sidebar" SiteSetting.tagging_enabled = true - SiteSetting.default_sidebar_categories = "#{category.id}|#{secured_category.id}" - SiteSetting.default_sidebar_tags = "#{tag.name}|#{hidden_tag.name}" + SiteSetting.default_navigation_menu_categories = "#{category.id}|#{secured_category.id}" + SiteSetting.default_navigation_menu_tags = "#{tag.name}|#{hidden_tag.name}" end it "creates the right sidebar section link records for categories and tags that a user can see" do diff --git a/spec/requests/admin/site_settings_controller_spec.rb b/spec/requests/admin/site_settings_controller_spec.rb index 05bfda5edc8..e0f0a77ea7a 100644 --- a/spec/requests/admin/site_settings_controller_spec.rb +++ b/spec/requests/admin/site_settings_controller_spec.rb @@ -92,24 +92,24 @@ RSpec.describe Admin::SiteSettingsController do end context "for sidebar defaults" do - it "returns the right count for the default_sidebar_categories site setting" do + it "returns the right count for the default_navigation_menu_categories site setting" do category = Fabricate(:category) - put "/admin/site_settings/default_sidebar_categories/user_count.json", + put "/admin/site_settings/default_navigation_menu_categories/user_count.json", params: { - default_sidebar_categories: "#{category.id}", + default_navigation_menu_categories: "#{category.id}", } expect(response.status).to eq(200) expect(response.parsed_body["user_count"]).to eq(User.real.not_staged.count) end - it "returns the right count for the default_sidebar_tags site setting" do + it "returns the right count for the default_navigation_menu_tags site setting" do tag = Fabricate(:tag) - put "/admin/site_settings/default_sidebar_tags/user_count.json", + put "/admin/site_settings/default_navigation_menu_tags/user_count.json", params: { - default_sidebar_tags: "#{tag.name}", + default_navigation_menu_tags: "#{tag.name}", } expect(response.status).to eq(200) @@ -319,32 +319,32 @@ RSpec.describe Admin::SiteSettingsController do end end - context "when updating default sidebar categories and tags" do + context "when updating default navigation menu categories and tags" do it "does not enqueue the backfilling job if update_existing_user param is not present" do expect_not_enqueued_with(job: :backfill_sidebar_site_settings) do - put "/admin/site_settings/default_sidebar_categories.json", + put "/admin/site_settings/default_navigation_menu_categories.json", params: { - default_sidebar_categories: "1|2", + default_navigation_menu_categories: "1|2", } expect(response.status).to eq(200) end end - it "enqueues the backfilling job if update_existing_user param is present when updating default sidebar tags" do - SiteSetting.default_sidebar_tags = "tag3" + it "enqueues the backfilling job if update_existing_user param is present when updating default navigation menu tags" do + SiteSetting.default_navigation_menu_tags = "tag3" expect_enqueued_with( job: :backfill_sidebar_site_settings, args: { - setting_name: "default_sidebar_tags", + setting_name: "default_navigation_menu_tags", new_value: "tag1|tag2", previous_value: "tag3", }, ) do - put "/admin/site_settings/default_sidebar_tags.json", + put "/admin/site_settings/default_navigation_menu_tags.json", params: { - default_sidebar_tags: "tag1|tag2", + default_navigation_menu_tags: "tag1|tag2", update_existing_user: true, } @@ -352,20 +352,20 @@ RSpec.describe Admin::SiteSettingsController do end end - it "enqueues the backfilling job if update_existing_user param is present when updating default sidebar categories" do - SiteSetting.default_sidebar_categories = "3|4" + it "enqueues the backfilling job if update_existing_user param is present when updating default navigation_menu categories" do + SiteSetting.default_navigation_menu_categories = "3|4" expect_enqueued_with( job: :backfill_sidebar_site_settings, args: { - setting_name: "default_sidebar_categories", + setting_name: "default_navigation_menu_categories", new_value: "1|2", previous_value: "3|4", }, ) do - put "/admin/site_settings/default_sidebar_categories.json", + put "/admin/site_settings/default_navigation_menu_categories.json", params: { - default_sidebar_categories: "1|2", + default_navigation_menu_categories: "1|2", update_existing_user: true, } diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb index 201b0fb325b..c1337e8a74f 100644 --- a/spec/serializers/site_serializer_spec.rb +++ b/spec/serializers/site_serializer_spec.rb @@ -131,7 +131,7 @@ RSpec.describe SiteSerializer do expect(serialized[:shared_drafts_category_id]).to eq(nil) end - describe "#anonymous_default_sidebar_tags" do + describe "#anonymous_default_navigation_menu_tags" do fab!(:user) { Fabricate(:user) } fab!(:tag) { Fabricate(:tag, name: "dev") } fab!(:tag2) { Fabricate(:tag, name: "random") } @@ -143,7 +143,7 @@ RSpec.describe SiteSerializer do before do SiteSetting.navigation_menu = "sidebar" SiteSetting.tagging_enabled = true - SiteSetting.default_sidebar_tags = "#{tag.name}|#{tag2.name}|#{hidden_tag.name}" + SiteSetting.default_navigation_menu_tags = "#{tag.name}|#{tag2.name}|#{hidden_tag.name}" end it "is not included in the serialised object when tagging is not enabled" do @@ -151,33 +151,33 @@ RSpec.describe SiteSerializer do guardian = Guardian.new(user) serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json - expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil) + expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil) end it "is not included in the serialised object when navigation menu is legacy" do SiteSetting.navigation_menu = "legacy" serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json - expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil) + expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil) end it "is not included in the serialised object when user is not anonymous" do guardian = Guardian.new(user) serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json - expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil) + expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil) end it "is not included in the serialisd object when default sidebar tags have not been configured" do - SiteSetting.default_sidebar_tags = "" + SiteSetting.default_navigation_menu_tags = "" serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json - expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil) + expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(nil) end it "includes only tags user can see in the serialised object when user is anonymous" do serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json - expect(serialized[:anonymous_default_sidebar_tags]).to eq(%w[dev random]) + expect(serialized[:anonymous_default_navigation_menu_tags]).to eq(%w[dev random]) end end diff --git a/spec/services/sidebar_site_settings_backfiller_spec.rb b/spec/services/sidebar_site_settings_backfiller_spec.rb index 872a378964b..6a3717f6ca0 100644 --- a/spec/services/sidebar_site_settings_backfiller_spec.rb +++ b/spec/services/sidebar_site_settings_backfiller_spec.rb @@ -59,11 +59,11 @@ RSpec.describe SidebarSiteSettingsBackfiller do end describe "#backfill!" do - context "for default_sidebar_categories setting" do + context "for default_navigation_menu_categories setting" do it "deletes the right sidebar section link records when categories are removed" do backfiller = described_class.new( - "default_sidebar_categories", + "default_navigation_menu_categories", previous_value: "#{category.id}|#{category2.id}|#{category3.id}", new_value: "#{category3.id}", ) @@ -76,7 +76,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "creates the right sidebar section link records when categories are added" do backfiller = described_class.new( - "default_sidebar_categories", + "default_navigation_menu_categories", previous_value: "#{category.id}|#{category2.id}", new_value: "#{category.id}|#{category2.id}|#{category3.id}", ) @@ -93,7 +93,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "creates the right sidebar section link records when categories are added" do backfiller = described_class.new( - "default_sidebar_categories", + "default_navigation_menu_categories", previous_value: "", new_value: "#{category.id}|#{category2.id}|#{category3.id}", ) @@ -122,7 +122,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "deletes and creates the right sidebar section link records when categories are added and removed" do backfiller = described_class.new( - "default_sidebar_categories", + "default_navigation_menu_categories", previous_value: "#{category.id}|#{category2.id}", new_value: "#{category3.id}", ) @@ -150,11 +150,11 @@ RSpec.describe SidebarSiteSettingsBackfiller do end end - context "for default_sidebar_tags setting" do + context "for default_navigation_menu_tags setting" do it "deletes the right sidebar section link records when tags are removed" do backfiller = described_class.new( - "default_sidebar_tags", + "default_navigation_menu_tags", previous_value: "#{tag.name}|#{tag2.name}|#{tag3.name}", new_value: "#{tag3.name}", ) @@ -167,7 +167,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "creates the right sidebar section link records when tags are added" do backfiller = described_class.new( - "default_sidebar_tags", + "default_navigation_menu_tags", previous_value: "#{tag.name}|#{tag2.name}", new_value: "#{tag.name}|#{tag2.name}|#{tag3.name}", ) @@ -182,7 +182,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "deletes and creates the right sidebar section link records when tags are added and removed" do backfiller = described_class.new( - "default_sidebar_tags", + "default_navigation_menu_tags", previous_value: "#{tag.name}|#{tag2.name}", new_value: "#{tag3.name}", ) @@ -207,11 +207,11 @@ RSpec.describe SidebarSiteSettingsBackfiller do end describe "#number_of_users_to_backfill" do - context "for default_sidebar_categories setting" do + context "for default_navigation_menu_categories setting" do it "returns 3 for the user count when a new category for all users is added" do backfiller = described_class.new( - "default_sidebar_categories", + "default_navigation_menu_categories", previous_value: "", new_value: "#{category3.id}", ) @@ -222,7 +222,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "returns 2 for the user count when category which 2 users have configured in sidebar is removed" do backfiller = described_class.new( - "default_sidebar_categories", + "default_navigation_menu_categories", previous_value: "#{category.id}|#{category2.id}", new_value: "#{category2.id}", ) @@ -234,7 +234,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "returns 3 for the user count when a new category is added and a category is removed" do backfiller = described_class.new( - "default_sidebar_categories", + "default_navigation_menu_categories", previous_value: "#{category.id}|#{category2.id}", new_value: "#{category2.id}|#{category3.id}", ) @@ -244,16 +244,24 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "returns 0 for the user count when no new category is added or removed" do backfiller = - described_class.new("default_sidebar_categories", previous_value: "", new_value: "") + described_class.new( + "default_navigation_menu_categories", + previous_value: "", + new_value: "", + ) expect(backfiller.number_of_users_to_backfill).to eq(0) end end - context "for default_sidebar_tags setting" do + context "for default_navigation_menu_tags setting" do it "returns 3 for the user count when a new tag for all users is added" do backfiller = - described_class.new("default_sidebar_tags", previous_value: "", new_value: "#{tag3.name}") + described_class.new( + "default_navigation_menu_tags", + previous_value: "", + new_value: "#{tag3.name}", + ) expect(backfiller.number_of_users_to_backfill).to eq(3) end @@ -262,7 +270,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "returns 2 for the user count when tag which 2 users have configured in sidebar is removed" do backfiller = described_class.new( - "default_sidebar_tags", + "default_navigation_menu_tags", previous_value: "#{tag.name}|#{tag2.name}", new_value: "#{tag2.name}", ) @@ -274,7 +282,7 @@ RSpec.describe SidebarSiteSettingsBackfiller do it "returns 3 for the user count when a new tag is added and a tag is removed" do backfiller = described_class.new( - "default_sidebar_tags", + "default_navigation_menu_tags", previous_value: "#{tag.name}|#{tag2.name}", new_value: "#{tag2.name}|#{tag3.name}", ) diff --git a/spec/system/editing_sidebar_categories_navigation_spec.rb b/spec/system/editing_sidebar_categories_navigation_spec.rb index a94379183c0..4b527a28566 100644 --- a/spec/system/editing_sidebar_categories_navigation_spec.rb +++ b/spec/system/editing_sidebar_categories_navigation_spec.rb @@ -22,7 +22,7 @@ RSpec.describe "Editing sidebar categories navigation", type: :system do before do SiteSetting.new_edit_sidebar_categories_tags_interface_groups = group.name - SiteSetting.default_sidebar_categories = "#{category.id}|#{category2.id}" + SiteSetting.default_navigation_menu_categories = "#{category.id}|#{category2.id}" sign_in(user) end diff --git a/spec/system/page_objects/pages/user_preferences_sidebar.rb b/spec/system/page_objects/pages/user_preferences_navigation_menu.rb similarity index 61% rename from spec/system/page_objects/pages/user_preferences_sidebar.rb rename to spec/system/page_objects/pages/user_preferences_navigation_menu.rb index c84d5e33170..5cc9224325e 100644 --- a/spec/system/page_objects/pages/user_preferences_sidebar.rb +++ b/spec/system/page_objects/pages/user_preferences_navigation_menu.rb @@ -2,26 +2,26 @@ module PageObjects module Pages - class UserPreferencesSidebar < PageObjects::Pages::Base + class UserPreferencesNavigationMenu < PageObjects::Pages::Base def visit(user) - page.visit("/u/#{user.username}/preferences/sidebar") + page.visit("/u/#{user.username}/preferences/navigation-menu") self end - def has_sidebar_categories_preference?(*categories) + def has_navigation_menu_categories_preference?(*categories) category_selector_header = page.find(".category-selector .select-kit-header-wrapper") category_selector_header.has_content?(categories.map(&:name).join(", ")) end - def has_sidebar_tags_preference?(*tags) + def has_navigation_menu_tags_preference?(*tags) tag_selector_header = page.find(".tag-chooser .select-kit-header-wrapper") tag_selector_header.has_content?(tags.map(&:name).join(", ")) end - def has_sidebar_list_destination_preference?(type) + def has_navigation_menu_list_destination_preference?(type) list_selector_header = page.find( - ".preferences-sidebar-navigation__list-destination-selector .select-kit-header-wrapper", + ".preferences-navigation-menu-navigation__list-destination-selector .select-kit-header-wrapper", ) list_selector_header.has_content?( I18n.t("js.user.experimental_sidebar.list_destination_#{type}"), diff --git a/spec/system/viewing_sidebar_preferences_spec.rb b/spec/system/viewing_navigation_menu_preferences_spec.rb similarity index 64% rename from spec/system/viewing_sidebar_preferences_spec.rb rename to spec/system/viewing_navigation_menu_preferences_spec.rb index d990e943326..0acae658f15 100644 --- a/spec/system/viewing_sidebar_preferences_spec.rb +++ b/spec/system/viewing_navigation_menu_preferences_spec.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true describe "Viewing sidebar preferences", type: :system do - let(:user_preferences_sidebar_page) { PageObjects::Pages::UserPreferencesSidebar.new } + let(:user_preferences_navigation_menu_page) do + PageObjects::Pages::UserPreferencesNavigationMenu.new + end before { SiteSetting.navigation_menu = "sidebar" } @@ -27,19 +29,22 @@ describe "Viewing sidebar preferences", type: :system do before { sign_in(admin) } - it "should be able to view sidebar preferences of another user" do + it "should be able to view navigation menu preferences of another user" do user.user_option.update!(sidebar_list_destination: "unread_new") - user_preferences_sidebar_page.visit(user) + user_preferences_navigation_menu_page.visit(user) - expect(user_preferences_sidebar_page).to have_sidebar_categories_preference( + expect(user_preferences_navigation_menu_page).to have_navigation_menu_categories_preference( category, category2, ) - expect(user_preferences_sidebar_page).to have_sidebar_tags_preference(tag, tag2) - expect(user_preferences_sidebar_page).to have_sidebar_list_destination_preference( - "unread_new", + expect(user_preferences_navigation_menu_page).to have_navigation_menu_tags_preference( + tag, + tag2, ) + expect( + user_preferences_navigation_menu_page, + ).to have_navigation_menu_list_destination_preference("unread_new") end end end