discourse/spec/components/site_icon_manager_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
FEATURE: Automatically generate optimized site metadata icons (#7372) This change automatically resizes icons for various purposes. Admins can now upload `logo` and `logo_small`, and everything else will be auto-generated. Specific icons can still be uploaded separately if required. ## Core - Adds an SiteIconManager module which manages automatic resizing and fallback - Icons are looked up in the OptimizedImage table at runtime, and then cached in Redis. If the resized version is missing for some reason, then most icons will fall back to the original files. Some icons (e.g. PWA Manifest) will return `nil` (because an incorrectly sized icon is worse than a missing icon). - `SiteSetting.site_large_icon_url` will return the optimized version, including any fallback. `SiteSetting.large_icon` continues to return the upload object. This means that (almost) no changes are required in core/plugins to support this new system. - Icons are resized whenever a relevant site setting is changed, and during post-deploy migrations ## Wizard - Allows `requiresRefresh` wizard steps to reload data via AJAX instead of a full page reload - Add placeholders to the **icons** step of the wizard, which automatically update from the "Square Logo" - Various copy updates to support the changes - Remove the "upload-time" resizing for `large_icon`. This is no longer required. ## Site Settings UX - Move logo/icon settings under a new "Branding" tab - Various copy changes to support the changes - Adds placeholder support to the `image-uploader` component - Automatically reloads site settings after saving. This allows setting placeholders to change based on changes to other settings - Upload site settings will be assigned a placeholder if SiteIconManager `responds_to?` an icon of the same name ## Dashboard Warnings - Remove PWA icon and PWA title warnings. Both are now handled automatically. ## Bonus - Updated the sketch logos to use @awesomerobot's new high-res designs
2019-05-01 09:44:45 -04:00
require 'rails_helper'
class GlobalPathInstance
extend GlobalPath
end
describe SiteIconManager do
before do
SiteIconManager.enable
end
let(:upload) do
UploadCreator.new(file_from_fixtures("smallest.png"), 'logo.png').create_for(Discourse.system_user.id)
end
it "works correctly" do
SiteSetting.logo = nil
SiteSetting.logo_small = nil
# Falls back to sketch for some icons
expect(SiteIconManager.favicon.upload_id).to eq(SiteIconManager::SKETCH_LOGO_ID)
expect(SiteIconManager.mobile_logo).to eq(nil)
SiteSetting.logo_small = upload
# Always resizes to 512x512
manifest = SiteIconManager.manifest_icon
expect(manifest.upload_id).to eq(upload.id)
expect(manifest.width).to eq(512)
expect(manifest.height).to eq(512)
# Always resizes to 32x32
favicon = SiteIconManager.favicon
expect(favicon.upload_id).to eq(upload.id)
expect(favicon.width).to eq(32)
expect(favicon.height).to eq(32)
# Don't resize
opengraph = SiteIconManager.opengraph_image
expect(opengraph).to eq(upload)
# Site Setting integration
expect(SiteSetting.manifest_icon).to eq(nil)
expect(SiteSetting.site_manifest_icon_url).to eq(GlobalPathInstance.full_cdn_url(manifest.url))
end
end