mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Calculate sprite-sheet based on currently active themes (#6973)
Previously there was only one sprite sheet, which always included icons from all themes even if they were disabled
This commit is contained in:
@@ -3,7 +3,7 @@ require 'rails_helper'
|
||||
describe SvgSprite do
|
||||
|
||||
before do
|
||||
SvgSprite.rebuild_cache
|
||||
SvgSprite.expire_cache
|
||||
end
|
||||
|
||||
it 'can generate a bundle' do
|
||||
@@ -12,6 +12,15 @@ describe SvgSprite do
|
||||
expect(bundle).to match(/angle-double-down/)
|
||||
end
|
||||
|
||||
it 'can generate paths' do
|
||||
version = SvgSprite.version # Icons won't change for this test
|
||||
expect(SvgSprite.path).to eq("/svg-sprite/#{Discourse.current_hostname}/svg--#{version}.js")
|
||||
expect(SvgSprite.path([1, 2])).to eq("/svg-sprite/#{Discourse.current_hostname}/svg-1,2-#{version}.js")
|
||||
|
||||
# Safe mode
|
||||
expect(SvgSprite.path([nil])).to eq("/svg-sprite/#{Discourse.current_hostname}/svg--#{version}.js")
|
||||
end
|
||||
|
||||
it 'can search for a specific FA icon' do
|
||||
expect(SvgSprite.search("fa-heart")).to match(/heart/)
|
||||
expect(SvgSprite.search("poo-storm")).to match(/poo-storm/)
|
||||
@@ -51,26 +60,43 @@ describe SvgSprite do
|
||||
|
||||
it 'includes icons defined in theme settings' do
|
||||
theme = Fabricate(:theme)
|
||||
theme.set_field(target: :settings, name: :yaml, value: "custom_icon: magic")
|
||||
|
||||
# Works for default settings:
|
||||
theme.set_field(target: :settings, name: :yaml, value: "custom_icon: dragon")
|
||||
theme.save!
|
||||
expect(SvgSprite.all_icons([theme.id])).to include("dragon")
|
||||
|
||||
# TODO: add test for default settings values
|
||||
# Automatically purges cache when default changes:
|
||||
theme.set_field(target: :settings, name: :yaml, value: "custom_icon: gamepad")
|
||||
theme.save!
|
||||
expect(SvgSprite.all_icons([theme.id])).to include("gamepad")
|
||||
|
||||
# Works when applying override
|
||||
theme.update_setting(:custom_icon, "gas-pump")
|
||||
expect(SvgSprite.all_icons).to include("gas-pump")
|
||||
expect(SvgSprite.all_icons([theme.id])).to include("gas-pump")
|
||||
|
||||
# Works when changing override
|
||||
theme.update_setting(:custom_icon, "gamepad")
|
||||
expect(SvgSprite.all_icons).to include("gamepad")
|
||||
expect(SvgSprite.all_icons).not_to include("gas-pump")
|
||||
expect(SvgSprite.all_icons([theme.id])).to include("gamepad")
|
||||
expect(SvgSprite.all_icons([theme.id])).not_to include("gas-pump")
|
||||
|
||||
# FA5 syntax
|
||||
theme.update_setting(:custom_icon, "fab fa-bandcamp")
|
||||
expect(SvgSprite.all_icons).to include("fab-bandcamp")
|
||||
expect(SvgSprite.all_icons([theme.id])).to include("fab-bandcamp")
|
||||
|
||||
# Internal Discourse syntax + multiple icons
|
||||
theme.update_setting(:custom_icon, "fab-android|dragon")
|
||||
expect(SvgSprite.all_icons).to include("fab-android")
|
||||
expect(SvgSprite.all_icons).to include("dragon")
|
||||
expect(SvgSprite.all_icons([theme.id])).to include("fab-android")
|
||||
expect(SvgSprite.all_icons([theme.id])).to include("dragon")
|
||||
|
||||
# Check themes don't leak into non-theme sprite sheet
|
||||
expect(SvgSprite.all_icons).not_to include("dragon")
|
||||
|
||||
# Check components are included
|
||||
theme.update(component: true)
|
||||
parent_theme = Fabricate(:theme)
|
||||
parent_theme.add_child_theme!(theme)
|
||||
expect(SvgSprite.all_icons([parent_theme.id])).to include("dragon")
|
||||
end
|
||||
|
||||
it 'includes icons from SiteSettings' do
|
||||
@@ -82,10 +108,12 @@ describe SvgSprite do
|
||||
expect(all_icons).to include("fab-bandcamp")
|
||||
|
||||
SiteSetting.svg_icon_subset = nil
|
||||
SvgSprite.expire_cache
|
||||
expect(SvgSprite.all_icons).not_to include("drafting-compass")
|
||||
|
||||
# does not fail on non-string setting
|
||||
SiteSetting.svg_icon_subset = false
|
||||
SvgSprite.expire_cache
|
||||
expect(SvgSprite.all_icons).to be_truthy
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user