2024-04-02 11:05:08 -04:00
|
|
|
# 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 }
|
2024-04-09 15:54:44 -04:00
|
|
|
fab!(:theme)
|
2024-04-02 11:05:08 -04:00
|
|
|
|
|
|
|
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 = nil
|
|
|
|
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")
|
|
|
|
|
|
|
|
visit "u/#{user.username}/preferences/interface"
|
|
|
|
|
|
|
|
homepage_picker = PageObjects::Components::SelectKit.new("#home-selector")
|
|
|
|
homepage_picker.expand
|
2024-08-08 13:57:42 -04:00
|
|
|
homepage_picker.select_row_by_name("Hot")
|
2024-04-02 11:05:08 -04:00
|
|
|
page.find(".btn-primary.save-changes").click
|
|
|
|
|
|
|
|
# Wait for the save to complete
|
|
|
|
find(".btn-primary.save-changes:not([disabled])", wait: 5)
|
|
|
|
|
|
|
|
visit "/"
|
|
|
|
|
2024-08-08 13:57:42 -04:00
|
|
|
expect(page).to have_css(".navigation-container .hot.active", text: "Hot")
|
2024-04-02 11:05:08 -04:00
|
|
|
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
|
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
shared_examples "a custom homepage" do
|
|
|
|
it "shows the custom homepage component" do
|
2024-04-02 11:05:08 -04:00
|
|
|
visit "/"
|
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
expect(page).to have_css(".new-home", text: "Hi friends!")
|
2024-04-02 11:05:08 -04:00
|
|
|
expect(page).to have_no_css(".list-container")
|
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
find("#sidebar-section-content-community li:first-child").click
|
|
|
|
expect(page).to have_css(".list-container")
|
|
|
|
|
2024-08-08 07:52:48 -04:00
|
|
|
click_logo
|
2024-04-02 11:05:08 -04:00
|
|
|
|
|
|
|
expect(page).to have_no_css(".list-container")
|
2024-06-21 11:24:11 -04:00
|
|
|
# ensure clicking on logo brings user back to the custom homepage
|
|
|
|
expect(page).to have_css(".new-home", text: "Hi friends!")
|
2024-04-02 11:05:08 -04:00
|
|
|
end
|
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
it "respects the user's homepage choice" do
|
|
|
|
visit "/"
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
expect(page).not_to have_css(".list-container")
|
|
|
|
expect(page).to have_css(".new-home", text: "Hi friends!")
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
sign_in user
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-07-19 12:39:22 -04:00
|
|
|
visit ""
|
|
|
|
expect(page).to have_css(".new-home", text: "Hi friends!")
|
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
visit "/u/#{user.username}/preferences/interface"
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
homepage_picker = PageObjects::Components::SelectKit.new("#home-selector")
|
|
|
|
homepage_picker.expand
|
|
|
|
# user overrides theme custom homepage
|
2024-08-08 13:57:42 -04:00
|
|
|
homepage_picker.select_row_by_name("Hot")
|
2024-06-21 11:24:11 -04:00
|
|
|
page.find(".btn-primary.save-changes").click
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-07-22 12:35:23 -04:00
|
|
|
# Wait for the save to complete
|
2024-06-21 11:24:11 -04:00
|
|
|
find(".btn-primary.save-changes:not([disabled])", wait: 5)
|
2024-08-08 13:57:42 -04:00
|
|
|
expect(user.user_option.homepage_id).to eq(UserOption::HOMEPAGES.key("hot"))
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-08-08 07:52:48 -04:00
|
|
|
click_logo
|
2024-08-08 13:57:42 -04:00
|
|
|
expect(page).to have_css(".navigation-container .hot.active", text: "Hot")
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
visit "/u/#{user.username}/preferences/interface"
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
homepage_picker = PageObjects::Components::SelectKit.new("#home-selector")
|
|
|
|
homepage_picker.expand
|
|
|
|
# user selects theme custom homepage again
|
|
|
|
homepage_picker.select_row_by_name("(default)")
|
|
|
|
page.find(".btn-primary.save-changes").click
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
# Wait for the save to complete
|
|
|
|
find(".btn-primary.save-changes:not([disabled])", wait: 5)
|
2024-08-08 13:57:42 -04:00
|
|
|
expect(user.reload.user_option.homepage_id).to_not eq(UserOption::HOMEPAGES.key("hot"))
|
2024-07-19 12:39:22 -04:00
|
|
|
|
2024-08-08 07:52:48 -04:00
|
|
|
click_logo
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-07-19 12:39:22 -04:00
|
|
|
expect(page).to have_current_path("/")
|
2024-06-21 11:24:11 -04:00
|
|
|
expect(page).to have_css(".new-home", text: "Hi friends!")
|
|
|
|
end
|
|
|
|
end
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
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
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
it "shows empty state to regular users" do
|
|
|
|
sign_in user
|
|
|
|
visit "/"
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
expect(page).to have_no_css(".list-container")
|
|
|
|
expect(page).to have_no_css(".alert-info")
|
|
|
|
end
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
it "shows empty state and notice to admins" do
|
|
|
|
sign_in admin
|
|
|
|
visit "/"
|
2024-04-02 11:05:08 -04:00
|
|
|
|
2024-06-21 11:24:11 -04:00
|
|
|
expect(page).to have_no_css(".list-container")
|
|
|
|
expect(page).to have_css(".alert-info")
|
2024-04-02 11:05:08 -04:00
|
|
|
end
|
2024-04-09 15:54:44 -04:00
|
|
|
|
|
|
|
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[:html],
|
|
|
|
target_id: Theme.targets[:common],
|
|
|
|
name: "head_tag",
|
|
|
|
value: <<~HTML,
|
|
|
|
<script type="text/x-handlebars" data-template-name="/connectors/custom-homepage/new-home">
|
|
|
|
<div class="new-home">Hi friends!</div>
|
|
|
|
</script>
|
|
|
|
HTML
|
|
|
|
)
|
|
|
|
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[:html],
|
|
|
|
target_id: Theme.targets[:common],
|
|
|
|
name: "head_tag",
|
|
|
|
value: <<~HTML,
|
|
|
|
<script type="text/x-handlebars" data-template-name="/connectors/custom-homepage/new-home">
|
|
|
|
<div class="new-home">Hi friends!</div>
|
|
|
|
</script>
|
|
|
|
HTML
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before { theme.add_relative_theme!(:child, component) }
|
|
|
|
|
|
|
|
include_examples "a custom homepage"
|
|
|
|
end
|
2024-04-02 11:05:08 -04:00
|
|
|
end
|
2024-06-21 11:24:11 -04:00
|
|
|
|
|
|
|
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[:html],
|
|
|
|
target_id: Theme.targets[:common],
|
|
|
|
name: "head_tag",
|
|
|
|
value: <<~HTML,
|
|
|
|
<script type="text/x-handlebars" data-template-name="/connectors/custom-homepage/new-home">
|
|
|
|
<div class="new-home">Hi friends!</div>
|
|
|
|
</script>
|
|
|
|
HTML
|
|
|
|
)
|
|
|
|
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
|
2024-04-02 11:05:08 -04:00
|
|
|
end
|