Retrospring/spec/helpers/theme_helper_spec.rb

140 lines
3.7 KiB
Ruby
Raw Normal View History

2020-05-05 11:17:29 -07:00
# frozen_string_literal: true
require "rails_helper"
describe ThemeHelper, :type => :helper do
describe "#render_theme" do
context "when target page doesn't have a theme" do
it "returns no theme" do
expect(helper.render_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.render_theme).to include("<style>:root {")
end
it "contains correct theme background colors" do
expect(helper.render_theme).to include("--primary: #5e35b1;")
end
it "properly converts color values for *-text theme attributes" do
expect(helper.render_theme).to include("--primary-text: 255, 255, 255;")
end
end
end
2020-05-05 11:17:29 -07:00
describe "#get_hex_color_from_theme_value" do
it "returns the proper hex value from the decimal value for white" do
2020-05-05 11:17:29 -07:00
expect(helper.get_hex_color_from_theme_value(16777215)).to eq("ffffff")
end
it "returns the proper hex value from the decimal value for purple" do
expect(helper.get_hex_color_from_theme_value(6174129)).to eq("5e35b1")
end
2020-05-05 11:17:29 -07:00
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