DEV: Add tests for `categories` setting (#50)

This commit improves the test coverage for the client side logic
surrounding the `categories` theme setting
This commit is contained in:
Alan Guo Xiang Tan 2024-04-24 11:57:34 +08:00 committed by GitHub
parent 41ddbb8c11
commit 77645890df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 51 additions and 5 deletions

View File

@ -6,7 +6,12 @@ RSpec.describe "Category Banners", type: :system do
let!(:theme) { upload_theme_component }
fab!(:category) { Fabricate(:category, description: "<p>this is some description</p>") }
fab!(:category_subcategory) do
Fabricate(:category, parent_category: category, description: "some description", uploaded_logo: Fabricate(:upload))
Fabricate(
:category,
parent_category: category,
description: "some description",
uploaded_logo: Fabricate(:upload),
)
end
let(:category_banner) { PageObjects::Components::CategoryBanner.new(category) }
let(:subcategory_banner) { PageObjects::Components::CategoryBanner.new(category_subcategory) }
@ -19,6 +24,47 @@ RSpec.describe "Category Banners", type: :system do
expect(category_banner).to have_description("this is some description")
end
context "when `categories` setting has been set" do
it "displays category banner for category and its subcategory when target is set to `all`" do
theme.update_setting(:categories, "#{category.name}:all")
theme.save!
visit(category.url)
expect(category_banner).to be_visible
visit(category_subcategory.url)
expect(subcategory_banner).to be_visible
end
it "displays category banner only for root category when target is set to `no_sub`" do
theme.update_setting(:categories, "#{category.name}:no_sub")
theme.save!
visit(category.url)
expect(category_banner).to be_visible
visit(category_subcategory.url)
expect(subcategory_banner).to be_not_visible
end
it "displays category banner only for sub categories when target is set to `only_sub`" do
theme.update_setting(:categories, "#{category.name}:only_sub")
theme.save!
visit(category.url)
expect(category_banner).to be_not_visible
visit(category_subcategory.url)
expect(subcategory_banner).to be_visible
end
end
it "does not display the category description when `show_description` setting is false" do
theme.update_setting(:show_description, false)
theme.save!