Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from jonatasrancan/test-components
Test components
- Loading branch information
Showing
15 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
describe BlankComponent do | ||
it { should have_setting :body } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
describe BreadcrumbComponent do | ||
it { should have_setting :label } | ||
|
||
it { should have_i18n_setting :label } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
10
spec/lib/weby/components/institutional_links_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
14
spec/lib/weby/components/menu_accessibility_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
describe MenuI18nComponent do | ||
it { should have_setting :dropdown } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'rails_helper' | ||
|
||
describe SearchBoxComponent do | ||
it { should have_setting :width } | ||
it { should have_setting :align } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |