0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/app/helpers/qunit_helper.rb
David Taylor efb5c35b5a
DEV: Ensure activatedThemes key is always available in tests (#40675)
Otherwise we get an error in core/plugin qunit runs
2026-06-09 10:56:51 +01:00

47 lines
1.4 KiB
Ruby
Vendored

# frozen_string_literal: true
module QunitHelper
def theme_tests
theme = Theme.find_by(id: request.env[:resolved_theme_id])
return "" if theme.blank?
_, digest = theme.baked_js_tests_with_digest
src =
"#{GlobalSetting.cdn_url}" \
"#{Discourse.base_path}" \
"/theme-javascripts/tests/#{theme.id}-#{digest}.js" \
"?__ws=#{Discourse.current_hostname}"
"<link rel='modulepreload' href='#{src}' data-theme-id='#{theme.id}' data-theme-name='#{Rack::Utils.escape_html(theme.name)}' nonce='#{ThemeField::CSP_NONCE_PLACEHOLDER}' />".html_safe
end
def fake_preload_data
preloaded = {}
preloaded.merge!(theme_settings_preload_data)
preloaded.merge!(site_settings_preload_data)
return "" if preloaded.empty?
tag.div("", id: "data-preloaded", data: { preloaded: preloaded.to_json })
end
private
def theme_settings_preload_data
theme = Theme.find_by(id: request.env[:resolved_theme_id])
activated_themes =
if theme
{ theme.id => { name: theme.name, settings: theme.cached_default_settings } }
else
{}
end
{ "activatedThemes" => activated_themes.to_json }
end
def site_settings_preload_data
{
"siteSettings" => SiteSetting.client_settings_json_uncached(return_defaults: true),
"themeSiteSettingOverrides" => SiteSetting.theme_site_settings_json_uncached(nil),
}
end
end