From da88cad6489a6211bebcf4b0e5c357e3b1100e50 Mon Sep 17 00:00:00 2001 From: jbrw Date: Thu, 16 Sep 2021 17:47:51 -0400 Subject: [PATCH] FIX: Offer site_logo_dark_url as an option for dark mode themes (#14361) --- app/helpers/application_helper.rb | 12 ++++++ app/views/application/_header.html.erb | 7 +++- spec/helpers/application_helper_spec.rb | 53 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 56996a41201..8bd509f1837 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -341,6 +341,18 @@ module ApplicationHelper end end + def application_logo_dark_url + @application_logo_dark_url ||= begin + if dark_scheme_id != -1 + if mobile_view? && SiteSetting.site_mobile_logo_dark_url != application_logo_url + SiteSetting.site_mobile_logo_dark_url + elsif !mobile_view? && SiteSetting.site_logo_dark_url != application_logo_url + SiteSetting.site_logo_dark_url + end + end + end + end + def login_path "#{Discourse.base_path}/login" end diff --git a/app/views/application/_header.html.erb b/app/views/application/_header.html.erb index 9c2e59328ad..d93fca7585d 100644 --- a/app/views/application/_header.html.erb +++ b/app/views/application/_header.html.erb @@ -5,7 +5,12 @@
"> <%- if application_logo_url.present? %> - + + <%- if application_logo_dark_url.present? %> + + <%- end %> + + <%- else %> <%- end %> diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index ccc7842ef91..bc20d32e432 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -136,6 +136,59 @@ describe ApplicationHelper do end end + describe "application_logo_dark_url" do + context "when dark theme is not present" do + context "when dark logo is not present" do + it "should return nothing" do + expect(helper.application_logo_dark_url.present?).to eq(false) + end + end + end + + context "when dark theme is present" do + before do + dark_theme = Theme.create( + name: "Dark", + user_id: -1, + color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id + ) + end + + context "when dark logo is not present" do + it "should return nothing" do + expect(helper.application_logo_dark_url.present?).to eq(false) + end + end + + context "when dark logo is present" do + before do + SiteSetting.logo_dark = Fabricate(:upload, url: '/images/logo-dark.png') + end + + it "should return correct url" do + expect(helper.application_logo_dark_url).to eq(SiteSetting.site_logo_dark_url) + end + end + end + + context "when dark theme is present and selected" do + before do + dark_theme = Theme.create( + name: "Dark", + user_id: -1, + color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id + ) + helper.request.env[:resolved_theme_id] = dark_theme.id + SiteSetting.logo_dark = Fabricate(:upload, url: '/images/logo-dark.png') + end + + it "should return nothing" do + expect(helper.application_logo_url).to eq(SiteSetting.site_logo_dark_url) + expect(helper.application_logo_dark_url.present?).to eq(false) + end + end + end + describe "mobile_view?" do context "enable_mobile_theme is true" do before do