2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/spec/system/homepage_spec.rb
Sérgio Saquetim 726fc21187
DEV: Enforce deprecation-free tests for preinstalled plugins/themes (#36445)
This PR implements stricter deprecation handling that enforces
deprecation-free tests for core and preinstalled plugins, while allowing
custom (non-preinstalled) plugins and themes to have deprecations
without causing test failures.

### Key Changes

#### CI Workflow Improvements
- Split plugin system tests into separate CI targets: `core-plugins`,
`official-plugins`, and `chat`
- Enhance `bin/turbo_rspec` to accept comma-separated exclude patterns
via `--exclude-pattern`
- Simplify workflow configuration with default `shell: bash` and
consolidated environment variables

#### Plugin Classification & Detection
- Centralize official plugins list in `config/official_plugins.json` for
unified backend and frontend access
- Detect preinstalled plugins by checking for absence of `.git`
directory
- Add `isOfficial` and `isPreinstalled` metadata flags to plugin info
- Add `data-preinstalled` and `data-official` attributes to all plugin
and theme script tags for runtime identification

#### Deprecation Source Tracking
- Track deprecation sources (core, plugin, or theme) through template
map and resolver to attribute deprecations correctly
- Improve `source-identifier.js` to detect admin UI plugin files in both
development and production environments
- Add source information to deprecation messages for better debugging

#### Test Infrastructure
- Modify `raise-on-deprecation` test helper to skip errors for custom
(non-preinstalled) plugins and themes
- Add `EMBER_RAISE_ON_DEPRECATION` environment variable to control
deprecation throwing behavior in Rails tests
- Automatically set `EMBER_RAISE_ON_DEPRECATION` for core and
preinstalled plugin/theme specs in `rails_helper.rb`
- Improve deprecation summary output for system specs with test/spec
origin tracking

#### Deprecation Workflow Enhancements
- Add `dont-throw` handler for selective deprecation bypassing in test
fixtures without raising errors
- Add `dont-count` handler for preventing deprecation counting in
specific scenarios (e.g., test fixtures)

#### Deprecation Fixes
- Fix pending deprecations across core plugins (chat, data-explorer,
discourse-subscriptions, gamification, house-ads, reactions,
rss-polling, styleguide)
- Update import paths and remove deprecated patterns
- Migrate deprecated Handlebars templates to JavaScript API

### Testing Strategy

With these changes:
- **Core and preinstalled plugins** must pass all tests without any
deprecations
- **Custom plugins and themes** can have deprecations without failing
tests
- Test fixtures can use `dont-throw` and `dont-count` handlers when
testing deprecation behavior itself
- System specs automatically configure deprecation enforcement based on
test file location

---------

Co-authored-by: David Taylor <david@taylorhq.com>
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2025-12-16 17:48:29 -03:00

223 lines
6.6 KiB
Ruby

# frozen_string_literal: true
describe "Homepage", type: :system do
fab!(:admin)
fab!(:user)
fab!(:topics) { Fabricate.times(5, :post).map(&:topic) }
let(:discovery) { PageObjects::Pages::Discovery.new }
fab!(:theme)
let(:user_preferences_interface_page) { PageObjects::Pages::UserPreferencesInterface.new }
before do
# A workaround to avoid the global notice from interfering with the tests
# It is coming from the ensure_login_hint.rb initializer and it gets
# evaluated before the tests run (and it wrongly counts 0 admins defined)
SiteSetting.global_notice = ""
end
it "shows a list of topics by default" do
visit "/"
expect(discovery.topic_list).to have_topics(count: 5)
end
it "allows users to pick their homepage" do
sign_in user
visit "/"
expect(page).to have_css(".navigation-container .latest.active", text: "Latest")
user_preferences_interface_page.visit(user)
homepage_picker = PageObjects::Components::SelectKit.new("#home-selector")
homepage_picker.expand
homepage_picker.select_row_by_name("Hot")
user_preferences_interface_page.save_changes
visit "/"
expect(page).to have_css(".navigation-container .hot.active", text: "Hot")
end
it "defaults to first top_menu item as anonymous homepage" do
SiteSetting.top_menu = "categories|latest|new|unread"
visit "/"
expect(page).to have_css(".navigation-container .categories.active", text: "Categories")
sign_in user
visit "/"
expect(page).to have_css(".navigation-container .categories.active", text: "Categories")
end
shared_examples "a custom homepage" do
it "shows the custom homepage component" do
visit "/"
expect(page).to have_css(".new-home", text: "Hi friends!")
expect(page).to have_no_css(".list-container")
find("#sidebar-section-content-community li:first-child").click
expect(page).to have_css(".list-container")
click_logo
expect(page).to have_no_css(".list-container")
# ensure clicking on logo brings user back to the custom homepage
expect(page).to have_css(".new-home", text: "Hi friends!")
end
it "respects the user's homepage choice" do
visit "/"
expect(page).not_to have_css(".list-container")
expect(page).to have_css(".new-home", text: "Hi friends!")
sign_in user
visit ""
expect(page).to have_css(".new-home", text: "Hi friends!")
user_preferences_interface_page.visit(user)
homepage_picker = PageObjects::Components::SelectKit.new("#home-selector")
homepage_picker.expand
# user overrides theme custom homepage
homepage_picker.select_row_by_name("Hot")
user_preferences_interface_page.save_changes
expect(user.user_option.homepage_id).to eq(UserOption::HOMEPAGES.key("hot"))
click_logo
expect(page).to have_css(".navigation-container .hot.active", text: "Hot")
user_preferences_interface_page.visit(user)
homepage_picker = PageObjects::Components::SelectKit.new("#home-selector")
homepage_picker.expand
# user selects theme custom homepage again
homepage_picker.select_row_by_name("(default)")
user_preferences_interface_page.save_changes
click_logo
expect(page).to have_current_path("/")
expect(page).to have_css(".new-home", text: "Hi friends!")
end
end
context "when default theme uses a custom_homepage modifier" do
before do
theme.theme_modifier_set.custom_homepage = true
theme.theme_modifier_set.save!
theme.set_default!
end
it "shows empty state to regular users" do
sign_in user
visit "/"
expect(page).to have_no_css(".list-container")
expect(page).to have_no_css(".alert-info")
end
it "shows empty state and notice to admins" do
sign_in admin
visit "/"
expect(page).to have_no_css(".list-container")
expect(page).to have_css(".alert-info")
end
context "when the theme adds content to the [custom-homepage] connector" do
let!(:basic_html_field) do
Fabricate(
:theme_field,
theme: theme,
type_id: ThemeField.types[:js],
target_id: Theme.targets[:extra_js],
name: "discourse/api-initializers/theme-initializer.gjs",
value: <<~GJS,
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer((api) => {
api.renderInOutlet(
"custom-homepage",
<template>
<div class="new-home">Hi friends!</div>
</template>
);
});
GJS
)
end
include_examples "a custom homepage"
end
context "when a theme component adds content to the [custom-homepage] connector" do
let!(:component) { Fabricate(:theme, component: true) }
let!(:component_html_field) do
Fabricate(
:theme_field,
theme: component,
type_id: ThemeField.types[:js],
target_id: Theme.targets[:extra_js],
name: "discourse/api-initializers/theme-initializer.gjs",
value: <<~GJS,
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer((api) => {
api.renderInOutlet(
"custom-homepage",
<template>
<div class="new-home">Hi friends!</div>
</template>
);
});
GJS
)
end
before { theme.add_relative_theme!(:child, component) }
include_examples "a custom homepage"
end
end
context "when a theme component uses the custom_homepage modifier" do
let!(:component) { Fabricate(:theme, component: true) }
let!(:component_html_field) do
Fabricate(
:theme_field,
theme: component,
type_id: ThemeField.types[:js],
target_id: Theme.targets[:extra_js],
name: "discourse/api-initializers/theme-initializer.gjs",
value: <<~GJS,
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer((api) => {
api.renderInOutlet(
"custom-homepage",
<template>
<div class="new-home">Hi friends!</div>
</template>
);
});
GJS
)
end
before do
component.theme_modifier_set.custom_homepage = true
component.theme_modifier_set.save!
theme.add_relative_theme!(:child, component)
theme.set_default!
end
include_examples "a custom homepage"
end
end