From d81641ac18ae84446a4ecc8b296f2bec14d085e3 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 13 Aug 2021 01:23:07 +0200 Subject: [PATCH] Add theme model spec --- app/helpers/theme_helper.rb | 4 ++-- spec/factories/theme.rb | 27 +++++++++++++++++++++++++++ spec/models/theme_spec.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 spec/factories/theme.rb create mode 100644 spec/models/theme_spec.rb diff --git a/app/helpers/theme_helper.rb b/app/helpers/theme_helper.rb index 02b36008..2ba9d186 100644 --- a/app/helpers/theme_helper.rb +++ b/app/helpers/theme_helper.rb @@ -50,7 +50,7 @@ module ThemeHelper def theme_color theme = get_active_theme if theme - "##{get_hex_color_from_theme_value(theme.primary_color)}" + theme.theme_color else '#5e35b1' end @@ -59,7 +59,7 @@ module ThemeHelper def mobile_theme_color theme = get_active_theme if theme - "##{get_hex_color_from_theme_value(theme.background_color)}" + theme.mobile_theme_color else '#f0edf4' end diff --git a/spec/factories/theme.rb b/spec/factories/theme.rb new file mode 100644 index 00000000..4339377a --- /dev/null +++ b/spec/factories/theme.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :theme do + primary_color { 9_342_168 } + primary_text { 16_777_215 } + danger_color { 14_257_035 } + danger_text { 16_777_215 } + success_color { 12_573_067 } + success_text { 16_777_215 } + warning_color { 14_261_899 } + warning_text { 16_777_215 } + info_color { 9_165_273 } + info_text { 16_777_215 } + dark_color { 6_710_886 } + dark_text { 15_658_734 } + raised_background { 16_777_215 } + background_color { 13_026_795 } + body_text { 3_355_443 } + muted_text { 3_355_443 } + input_color { 15_789_556 } + input_text { 6_710_886 } + raised_accent { 16_250_871 } + light_color { 16_316_922 } + light_text { 0 } + end +end diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb new file mode 100644 index 00000000..a170c1d9 --- /dev/null +++ b/spec/models/theme_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe(Theme, type: :model) do + context 'user-defined theme' do + let(:user) { FactoryBot.create(:user) } + let(:theme) { FactoryBot.create(:theme, user: user) } + + describe '#theme_color' do + subject { theme.theme_color } + + it 'should return the theme\'s primary colour as a hex triplet' do + expect(subject).to eq('#8e8cd8') + end + end + + describe '#mobile_theme_color' do + subject { theme.mobile_theme_color } + + it 'should return the theme\'s background colour as a hex triplet' do + expect(subject).to eq('#c6c5eb') + end + end + end +end \ No newline at end of file