Add specs for ThemeHelper
This commit is contained in:
parent
c142920c6c
commit
b7b2adde44
|
@ -0,0 +1,108 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe ThemeHelper, :type => :helper do
|
||||
describe "#get_hex_color_from_theme_value" do
|
||||
it "returns the proper hex value from the theme value" do
|
||||
expect(helper.get_hex_color_from_theme_value(16777215)).to eq("ffffff")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#get_decimal_triplet_from_hex" do
|
||||
it "returns the proper decimal triplet from a hex value" do
|
||||
expect(helper.get_decimal_triplet_from_hex("5e35b1")).to eq("94, 53, 177")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#get_active_theme" do
|
||||
context "when user is a guest" do
|
||||
context "when target page doesn't have a theme" do
|
||||
it "returns no theme" do
|
||||
expect(helper.get_active_theme).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when target page has a theme" do
|
||||
before(:each) do
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.theme = Theme.new
|
||||
@user.save!
|
||||
end
|
||||
|
||||
it "returns a theme" do
|
||||
expect(helper.get_active_theme).to be_a(Theme)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when user is signed in" do
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
before(:each) { sign_in(user) }
|
||||
|
||||
context "when user has no theme" do
|
||||
context "when target page has no theme" do
|
||||
it "returns no theme" do
|
||||
expect(helper.get_active_theme).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when target page has a theme" do
|
||||
let(:theme) { Theme.new }
|
||||
|
||||
before(:each) do
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.theme = theme
|
||||
@user.save!
|
||||
end
|
||||
|
||||
it "returns a theme" do
|
||||
expect(helper.get_active_theme).to be(theme)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when user has a theme" do
|
||||
let(:theme) { Theme.new }
|
||||
|
||||
before(:each) do
|
||||
user.theme = theme
|
||||
user.show_foreign_themes = true
|
||||
user.save!
|
||||
end
|
||||
|
||||
context "when target page has no theme" do
|
||||
it "returns the theme of the current user" do
|
||||
expect(helper.get_active_theme).to eq(theme)
|
||||
end
|
||||
end
|
||||
|
||||
context "when target page has a theme" do
|
||||
let(:user_theme) { Theme.new }
|
||||
|
||||
before(:each) do
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.theme = user_theme
|
||||
@user.save!
|
||||
end
|
||||
|
||||
it "returns the theme of the current page" do
|
||||
expect(helper.get_active_theme).to eq(user_theme)
|
||||
end
|
||||
|
||||
context "when user doesn't allow foreign themes" do
|
||||
before(:each) do
|
||||
user.show_foreign_themes = false
|
||||
user.save!
|
||||
end
|
||||
|
||||
it "should return the users theme" do
|
||||
expect(helper.get_active_theme).to eq(theme)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -77,6 +77,7 @@ RSpec.configure do |config|
|
|||
# config.filter_gems_from_backtrace("gem name")
|
||||
|
||||
config.include Devise::Test::ControllerHelpers, type: :controller
|
||||
config.include Devise::Test::ControllerHelpers, type: :helper
|
||||
end
|
||||
|
||||
Dir[Rails.root.join "spec", "shared_examples", "*.rb"].sort.each { |f| require f }
|
||||
|
|
Loading…
Reference in New Issue