-
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.
Investigate adding fixture-based specs
This is an initial attempt at using GOV.UK Frontend's recent fixtures[0] addition to ensure the HTML we're generating is in accordance with the Design System. After flipping a few default values it's not a million miles off, but there are some snags: 1) Rails insists on adding a `data-disable-with` attribute to the submit[1], even when we attempt to disable it by passing `false` 2) Because in all cases (other than `#govuk_date_field`) we are merely wrapping the built-in Rails form helpers, we're not in control of the order of attributes. Comparing them directly will fail. Both of these problems are demonstrated in the RSpec output: expected: `<input value="Start now" type="submit" name="start-now" class="govuk-button" data-module="govuk-button">` got: `<input type="submit" name="start-now" value="Start now" class="govuk-button" data-module="govuk-button" data-disable-with="Start now" />` [0] alphagov/govuk-frontend#1830 [1] https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-submit_tag
- Loading branch information
1 parent
bf9577b
commit 663c1ae
Showing
5 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,32 @@ | ||
describe GOVUKDesignSystemFormBuilder::FormBuilder do | ||
include_context 'setup builder' | ||
|
||
describe 'Button' do | ||
# we only generate `<input type=submit...` so ignore everything else like `<button>` | ||
applicable = ['input'] | ||
|
||
fixtures = JSON | ||
.parse(File.read('guide/node_modules/govuk-frontend/govuk/components/button/fixtures.json')) | ||
.select { |f| f['name'].in?(applicable) } | ||
|
||
fixtures.each do |fixture| | ||
describe fixture['name'] do | ||
let(:expected) { fixture['html'] } | ||
|
||
let(:button_text) { fixture.dig('options', 'text') } | ||
subject { builder.govuk_submit(button_text) } | ||
|
||
# name: input | ||
# options: | ||
# element: input | ||
# name: start-now | ||
# text: Start now | ||
# html: <input value="Start now" type="submit" name="start-now" class="govuk-button" data-module="govuk-button"> | ||
|
||
specify 'should match the HTML' do | ||
expect(subject).to eql(expected) | ||
end | ||
end | ||
end | ||
end | ||
end |