-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add headings and tests to shared components helper
- Loading branch information
1 parent
924160c
commit 445d188
Showing
2 changed files
with
45 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,16 +1,21 @@ | ||
module GovukPublishingComponents | ||
module Presenters | ||
class SharedHelper | ||
attr_reader :options, :margin_bottom | ||
attr_reader :options, :margin_bottom, :heading_level | ||
|
||
def initialize(local_assigns) | ||
@options = local_assigns | ||
@margin_bottom = @options[:margin_bottom] || 3 | ||
@heading_level = @options[:heading_level] || 2 | ||
end | ||
|
||
def get_margin_bottom | ||
[*0..9].include?(@margin_bottom) ? "govuk-!-margin-bottom-#{margin_bottom}" : "govuk-!-margin-bottom-3" | ||
end | ||
|
||
def get_heading_level | ||
[*1..6].include?(@heading_level) ? "h#{@heading_level}" : "h2" | ||
end | ||
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,39 @@ | ||
RSpec.describe GovukPublishingComponents::Presenters::SharedHelper do | ||
describe "Shared component helper" do | ||
it "returns a default margin class" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new({}) | ||
margin_class = shared_helper.get_margin_bottom | ||
expect(margin_class).to eql('govuk-!-margin-bottom-3') | ||
end | ||
|
||
it "returns a given margin class" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(margin_bottom: 6) | ||
margin_class = shared_helper.get_margin_bottom | ||
expect(margin_class).to eql('govuk-!-margin-bottom-6') | ||
end | ||
|
||
it "returns the default margin class if passed value is wrong" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(margin_bottom: "a") | ||
margin_class = shared_helper.get_margin_bottom | ||
expect(margin_class).to eql('govuk-!-margin-bottom-3') | ||
end | ||
|
||
it "returns a default heading level" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new({}) | ||
heading = shared_helper.get_heading_level | ||
expect(heading).to eql('h2') | ||
end | ||
|
||
it "returns a given heading level" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(heading_level: 6) | ||
heading = shared_helper.get_heading_level | ||
expect(heading).to eql('h6') | ||
end | ||
|
||
it "returns the default heading level if passed value is wrong" do | ||
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(heading_level: 9) | ||
heading = shared_helper.get_heading_level | ||
expect(heading).to eql('h2') | ||
end | ||
end | ||
end |