Skip to content

Commit

Permalink
Merge pull request #219 from jonatasrancan/test-components
Browse files Browse the repository at this point in the history
Test components
  • Loading branch information
marcello committed May 5, 2015
2 parents 7076dec + 37d1361 commit b3b522a
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/lib/weby/components/blank_component_spec.rb
@@ -0,0 +1,5 @@
require 'rails_helper'

describe BlankComponent do
it { should have_setting :body }
end
7 changes: 7 additions & 0 deletions spec/lib/weby/components/breadcrumb_component_spec.rb
@@ -0,0 +1,7 @@
require 'rails_helper'

describe BreadcrumbComponent do
it { should have_setting :label }

it { should have_i18n_setting :label }
end
8 changes: 8 additions & 0 deletions spec/lib/weby/components/components_group_component_spec.rb
@@ -0,0 +1,8 @@
require 'rails_helper'

describe ComponentsGroupComponent do
it { should have_setting :html_class }

it { should allow_value('class').for(:html_class) }
it { should_not allow_value('<body></bodyx>').for(:html_class) }
end
7 changes: 7 additions & 0 deletions spec/lib/weby/components/feed_component_spec.rb
@@ -0,0 +1,7 @@
require 'rails_helper'

describe FeedComponent do
it { should have_setting :rss_icon }
it { should have_setting :atom_icon }
it { should have_setting :align }
end
36 changes: 36 additions & 0 deletions spec/lib/weby/components/image_component_spec.rb
@@ -0,0 +1,36 @@
require 'rails_helper'

describe ImageComponent do
it { should have_setting :repository_id }
it { should have_setting :size }
it { should have_setting :height }
it { should have_setting :width }
it { should have_setting :target_type }
it { should have_setting :target_id }
it { should have_setting :url }
it { should have_setting :new_tab }
it { should have_setting :html_class }

it { should validate_presence_of :repository_id }

it { should allow_value('class').for(:html_class) }
it { should_not allow_value('<body></bodyx>').for(:html_class) }

describe '#new_tab' do
it 'returns false when _new_tab is blank' do
expect(subject.new_tab).to eq false
end

it 'returns false when _new_tab is diferent from 1' do
allow(subject).to receive(:_new_tab).and_return 2

expect(subject.new_tab).to eq false
end

it 'returns true when _new_tab is 1' do
allow(subject).to receive(:_new_tab).and_return 1

expect(subject.new_tab).to eq true
end
end
end
10 changes: 10 additions & 0 deletions spec/lib/weby/components/institutional_links_component_spec.rb
@@ -0,0 +1,10 @@
require 'rails_helper'

describe InstitutionalLinksComponent do
it { should have_setting :institution }
it { should have_setting :html_class }
it { should have_setting :format }
it { should have_setting :new_tab }

it { should validate_presence_of :institution }
end
14 changes: 14 additions & 0 deletions spec/lib/weby/components/menu_accessibility_component_spec.rb
@@ -0,0 +1,14 @@
require 'rails_helper'

describe MenuAccessibilityComponent do
it { should have_setting :font_size }
it { should have_setting :contrast }
it { should have_setting :label_contrast }
it { should have_setting :label_font_size }
it { should have_setting :extended_accessibility }
it { should have_setting :additional_information }

it { should have_i18n_setting :label_contrast }
it { should have_i18n_setting :label_font_size }
it { should have_i18n_setting :additional_information }
end
48 changes: 48 additions & 0 deletions spec/lib/weby/components/menu_component_spec.rb
@@ -0,0 +1,48 @@
require 'rails_helper'

describe MenuComponent do
it { should have_setting :menu_id }
it { should have_setting :dropdown }

it { should validate_presence_of :menu_id }

describe '#dropdown' do
it 'returns false when _dropdown is blank' do
allow(subject).to receive(:_dropdown).and_return ''

expect(subject.dropdown).to eq false
end

it 'returns true when _dropdown is 1' do
allow(subject).to receive(:_dropdown).and_return '1'

expect(subject.dropdown).to eq true
end

it 'returns false when _dropdown is diferent from 1' do
allow(subject).to receive(:_dropdown).and_return '0'

expect(subject.dropdown).to eq false
end
end

describe '#default_alias' do
it "returns '' when doesn't find a menu with menu_id" do
allow(subject).to receive(:menu_id).and_return 1

allow(Menu).to receive(:find).with(1).and_return nil

expect(subject.default_alias).to eq ''
end

it "returns '' when doesn't find a menu with menu_id" do
menu = double(:menu, name: 'menu')

allow(subject).to receive(:menu_id).and_return 1

allow(Menu).to receive(:find).with(1).and_return menu

expect(subject.default_alias).to eq menu.name
end
end
end
5 changes: 5 additions & 0 deletions spec/lib/weby/components/menu_i18n_component_spec.rb
@@ -0,0 +1,5 @@
require 'rails_helper'

describe MenuI18nComponent do
it { should have_setting :dropdown }
end
9 changes: 9 additions & 0 deletions spec/lib/weby/components/news_as_home_component_spec.rb
@@ -0,0 +1,9 @@
require 'rails_helper'

describe NewsAsHomeComponent do
it { should have_setting :page_id }
it { should have_setting :show_title }
it { should have_setting :show_info }

it { should validate_presence_of :page_id }
end
14 changes: 14 additions & 0 deletions spec/lib/weby/components/photo_slider_component_spec.rb
@@ -0,0 +1,14 @@
require 'rails_helper'

describe PhotoSliderComponent do
it { should have_setting :photo_ids }
it { should have_setting :width }
it { should have_setting :height }
it { should have_setting :timer }
it { should have_setting :description }
it { should have_setting :style }
it { should have_setting :show_controls }
it { should have_setting :title }

it { should have_i18n_setting :title }
end
6 changes: 6 additions & 0 deletions spec/lib/weby/components/search_box_component_spec.rb
@@ -0,0 +1,6 @@
require 'rails_helper'

describe SearchBoxComponent do
it { should have_setting :width }
it { should have_setting :align }
end
11 changes: 11 additions & 0 deletions spec/lib/weby/components/text_component_spec.rb
@@ -0,0 +1,11 @@
require 'rails_helper'

describe TextComponent do
it { should have_setting :body }
it { should have_setting :html_class }

it { should have_i18n_setting :body }

it { should allow_value('class').for(:html_class) }
it { should_not allow_value('<body></bodyx>').for(:html_class) }
end
17 changes: 17 additions & 0 deletions spec/support/matchers/have_i18n_setting.rb
@@ -0,0 +1,17 @@
require 'rspec/expectations'

RSpec::Matchers.define :have_i18n_setting do |expected|
match do |actual|
method = expected.to_s + '_i18n'

actual.respond_to? method.to_sym
end

failure_message do |actual|
"expected #{actual.class} to have a i18n setting called #{expected}."
end

description do
"define a i18n setting called #{expected}."
end
end
21 changes: 21 additions & 0 deletions spec/support/matchers/have_setting.rb
@@ -0,0 +1,21 @@
require 'rspec/expectations'

RSpec::Matchers.define :have_setting do |expected|
match do |actual|
getter = actual.respond_to? expected

setter_method = expected.to_s + '='

setter = actual.respond_to? setter_method.to_sym

getter && setter
end

failure_message do |actual|
"expected #{actual.class} to have a setting called #{expected}."
end

description do
"define a setting called #{expected}."
end
end

0 comments on commit b3b522a

Please sign in to comment.