-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This updates the legend element to allow the size attribute to be `nil`, and when `nil` a size class won't be specified for the element. This is required to support the case where a field has a legend element but shouldn't have a size class. There's an example of this kind of component in the GOV.UK Design System: https://design-system.service.gov.uk/components/date-input/#if-youre-asking-more-than-one-question-on-the-page It's currently not possible to re-create this example using purely the form builder classes as the size is enforced as one of `s`, `m`, `l` or `xl`.
- Loading branch information
1 parent
8c0fb5d
commit 8ca528a
Showing
2 changed files
with
57 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
55 changes: 55 additions & 0 deletions
55
spec/govuk_design_system_formbuilder/elements/legend_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,55 @@ | ||
describe GOVUKDesignSystemFormBuilder::Elements::Legend do | ||
subject(:html) { described_class.new(builder, object_name, attribute_name, size:).html } | ||
|
||
let(:controller) { ActionController::Base.new } | ||
let(:lookup_context) { ActionView::LookupContext.new(nil) } | ||
let(:helper) { ActionView::Base.new(lookup_context, {}, controller) } | ||
let(:object) { Person.new(name: 'Joey') } | ||
let(:object_name) { :person } | ||
let(:builder) { GOVUKDesignSystemFormBuilder::FormBuilder.new(object_name, object, helper, {}) } | ||
let(:attribute_name) { :name } | ||
|
||
context 'with a nil size' do | ||
let(:size) { nil } | ||
|
||
specify 'the size class should be absent' do | ||
expect(html).to have_tag('legend', with: { class: 'govuk-fieldset__legend' }) | ||
expect(html).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--s' }) | ||
expect(html).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--m' }) | ||
expect(html).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--l' }) | ||
expect(html).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--xl' }) | ||
end | ||
end | ||
|
||
context 'with a "s" size' do | ||
let(:size) { 's' } | ||
|
||
specify 'the size class should be present' do | ||
expect(html).to have_tag('legend', with: { class: 'govuk-fieldset__legend govuk-fieldset__legend--s' }) | ||
end | ||
end | ||
|
||
context 'with a "m" size' do | ||
let(:size) { 'm' } | ||
|
||
specify 'the size class should be present' do | ||
expect(html).to have_tag('legend', with: { class: 'govuk-fieldset__legend govuk-fieldset__legend--m' }) | ||
end | ||
end | ||
|
||
context 'with a "l" size' do | ||
let(:size) { 'l' } | ||
|
||
specify 'the size class should be present' do | ||
expect(html).to have_tag('legend', with: { class: 'govuk-fieldset__legend govuk-fieldset__legend--l' }) | ||
end | ||
end | ||
|
||
context 'with a "xl" size' do | ||
let(:size) { 'xl' } | ||
|
||
specify 'the size class should be present' do | ||
expect(html).to have_tag('legend', with: { class: 'govuk-fieldset__legend govuk-fieldset__legend--xl' }) | ||
end | ||
end | ||
end |