gov_uk_date_fields 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gov_uk_date_fields/form_fields.rb +117 -168
- data/lib/gov_uk_date_fields/version.rb +1 -1
- data/test/dummy/app/views/employees/_form.html.erb +1 -1
- data/test/dummy/config/locales/en.yml +18 -1
- data/test/dummy/log/development.log +27 -0
- data/test/dummy/log/test.log +6027 -0
- data/test/dummy/test/controllers/employees_controller_test.rb +2 -7
- data/test/dummy/test/fixtures/files/date_fields_error.html +37 -0
- data/test/dummy/test/fixtures/files/date_fields_no_error.html +36 -0
- data/test/dummy/test/fixtures/files/date_fields_no_heading.html +34 -0
- data/test/dummy/test/models/default_error_clash_employee_test.rb +2 -2
- data/test/dummy/test/models/form_fields_test.rb +16 -311
- data/test/dummy/test/models/omit_error_clash_employee_test.rb +2 -2
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/5L/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/8M/8MByLANOkxnxtwqWuaeLzh_J4rurtoIBeW03ek6Y08w.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/AX/AX3L2fGpRF9VevxsOcMT3K8MFiRGjRX81JBxvrH7IIc.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/DW/DWiSprTdmJSiF4eYqRLDfLfWLyF-m0Mk3TOoLQXKKW0.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Dm/DmmfrCpXtt74Hr6NO54lxyOCDv6klnDyBqeDFR7oDU8.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/En/EnEfvwgFKP1AahR6eTP-u0TeHcVpHV2cuOYmDrfoDec.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/GW/GWPTgNDuFCS8p0ARIL21FLMCy42vfx4PSInNAm8hmyw.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/I4/I4zyVgaaEAo-RxZorzwj10dfMJ9z4yjkfkCrJJMiEYs.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ke/KeDHuzXMfGj06rzGw-wM0tr5j4viSTDtJ3tRD3-9jRI.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/M2/M2O1kCLdiZHeElbkOPVkvow3BKa026ayrJI6fMMFyRY.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/OI/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/QA/QA32z-4v8KU7eagra1ogcpOZOh5qLTIKxsr-0mmUYOk.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/WG/WGiwsdOFJDQRfkEQ_J28GODJYTENHaNDez1hrVfCI-M.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/_J/_JuLBi_RjcFhLlHO-CAH2DseU3sebABcazh2bG2D3iE.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/aD/aDGWuTF47JbhohmDBQPQ88olIS3GLQnTWjXucFfudqI.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/hZ/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/hi/hivuiGt4E4n9IsL7iMnPPAzK1vMRiG38tocXbUiQDuc.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/oC/oCyHm9DrBpNyFSoBvDDZxU4QbPwynEtk3yQzV2nQb_0.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/pE/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/vU/vU-zjPdBQL_wrwTTQHVcfWW_-JiPpwkOnTQtNpMPsVk.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/yH/yH-LUVpCFC8cqvwFp8v4VzRkwWrnAqBNViBRvhjiu3I.cache +1 -0
- metadata +38 -7
- data/test/sample.html +0 -25
- data/vendor/assets/javascripts/govuk_date_fields.js +0 -57
- data/vendor/assets/stylesheets/_govuk_date_fields.scss +0 -32
@@ -74,13 +74,8 @@ class EmployeesControllerTest < ActionController::TestCase
|
|
74
74
|
get :edit, params: { id: @employee }
|
75
75
|
|
76
76
|
assert_select 'input#employee_dob_dd' do
|
77
|
-
assert_select '[
|
78
|
-
assert_select '[
|
79
|
-
assert_select '[size=?]','2'
|
80
|
-
end
|
81
|
-
|
82
|
-
assert_select 'input#employee_joined_dd' do
|
83
|
-
assert_select '[placeholder]',false
|
77
|
+
assert_select '[type=?]','number'
|
78
|
+
assert_select '[pattern=?]','[0-9]*'
|
84
79
|
end
|
85
80
|
end
|
86
81
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<div class="govuk-form-group govuk-form-group--error">
|
2
|
+
<fieldset class="govuk-fieldset" role="group" aria-describedby="employee_dob_hint employee_dob_error">
|
3
|
+
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
|
4
|
+
<h1 class="govuk-fieldset__heading">
|
5
|
+
Date of birth
|
6
|
+
</h1>
|
7
|
+
</legend>
|
8
|
+
<span class="govuk-hint" id="employee_dob_hint">For example, 12 11 2007</span>
|
9
|
+
<span class="govuk-error-message" id="employee_dob_error">Enter the date of birth</span>
|
10
|
+
<div class="govuk-date-input" id="employee_dob">
|
11
|
+
<div class="govuk-date-input__item">
|
12
|
+
<div class="govuk-form-group">
|
13
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_dd">
|
14
|
+
Day
|
15
|
+
</label>
|
16
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-2 govuk-input--error" id="employee_dob_dd" name="employee[dob_dd]" value="" type="number" pattern="[0-9]*">
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
<div class="govuk-date-input__item">
|
20
|
+
<div class="govuk-form-group">
|
21
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_mm">
|
22
|
+
Month
|
23
|
+
</label>
|
24
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-2 govuk-input--error" id="employee_dob_mm" name="employee[dob_mm]" value="" type="number" pattern="[0-9]*">
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<div class="govuk-date-input__item">
|
28
|
+
<div class="govuk-form-group">
|
29
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_yyyy">
|
30
|
+
Year
|
31
|
+
</label>
|
32
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-4 govuk-input--error" id="employee_dob_yyyy" name="employee[dob_yyyy]" value="" type="number" pattern="[0-9]*">
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
</fieldset>
|
37
|
+
</div>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<div class="govuk-form-group">
|
2
|
+
<fieldset class="govuk-fieldset" role="group" aria-describedby="employee_dob_hint">
|
3
|
+
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
|
4
|
+
<h1 class="govuk-fieldset__heading">
|
5
|
+
Date of birth
|
6
|
+
</h1>
|
7
|
+
</legend>
|
8
|
+
<span class="govuk-hint" id="employee_dob_hint">For example, 12 11 2007</span>
|
9
|
+
<div class="govuk-date-input" id="employee_dob">
|
10
|
+
<div class="govuk-date-input__item">
|
11
|
+
<div class="govuk-form-group">
|
12
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_dd">
|
13
|
+
Day
|
14
|
+
</label>
|
15
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="employee_dob_dd" name="employee[dob_dd]" value="7" type="number" pattern="[0-9]*">
|
16
|
+
</div>
|
17
|
+
</div>
|
18
|
+
<div class="govuk-date-input__item">
|
19
|
+
<div class="govuk-form-group">
|
20
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_mm">
|
21
|
+
Month
|
22
|
+
</label>
|
23
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="employee_dob_mm" name="employee[dob_mm]" value="12" type="number" pattern="[0-9]*">
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
<div class="govuk-date-input__item">
|
27
|
+
<div class="govuk-form-group">
|
28
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_yyyy">
|
29
|
+
Year
|
30
|
+
</label>
|
31
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-4" id="employee_dob_yyyy" name="employee[dob_yyyy]" value="1963" type="number" pattern="[0-9]*">
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
</fieldset>
|
36
|
+
</div>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<div class="govuk-form-group">
|
2
|
+
<fieldset class="govuk-fieldset" role="group" aria-describedby="employee_dob_hint">
|
3
|
+
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl govuk-visually-hidden">
|
4
|
+
Date of birth
|
5
|
+
</legend>
|
6
|
+
<span class="govuk-hint" id="employee_dob_hint">For example, 12 11 2007</span>
|
7
|
+
<div class="govuk-date-input" id="employee_dob">
|
8
|
+
<div class="govuk-date-input__item">
|
9
|
+
<div class="govuk-form-group">
|
10
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_dd">
|
11
|
+
Day
|
12
|
+
</label>
|
13
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="employee_dob_dd" name="employee[dob_dd]" value="7" type="number" pattern="[0-9]*">
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
<div class="govuk-date-input__item">
|
17
|
+
<div class="govuk-form-group">
|
18
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_mm">
|
19
|
+
Month
|
20
|
+
</label>
|
21
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="employee_dob_mm" name="employee[dob_mm]" value="12" type="number" pattern="[0-9]*">
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
<div class="govuk-date-input__item">
|
25
|
+
<div class="govuk-form-group">
|
26
|
+
<label class="govuk-label govuk-date-input__label" for="employee_dob_yyyy">
|
27
|
+
Year
|
28
|
+
</label>
|
29
|
+
<input class="govuk-input govuk-date-input__input govuk-input--width-4" id="employee_dob_yyyy" name="employee[dob_yyyy]" value="1963" type="number" pattern="[0-9]*">
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
</fieldset>
|
34
|
+
</div>
|
@@ -12,14 +12,14 @@ class DefaultErrorClashEmployeeTest < ActiveSupport::TestCase
|
|
12
12
|
|
13
13
|
def test_presence_error_messages_generated
|
14
14
|
@employee.valid?
|
15
|
-
assert_equal ["
|
15
|
+
assert_equal ["Enter the date of birth"], @employee.errors[:dob]
|
16
16
|
assert_equal ["can't be blank"], @employee.errors[:joined]
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_invalid_day_adds_invalid_date_message_to_cant_be_blank_message
|
20
20
|
@employee.dob_dd = '32'
|
21
21
|
assert_false @employee.valid?
|
22
|
-
assert_equal ['Invalid date', "
|
22
|
+
assert_equal ['Invalid date', "Enter the date of birth"], @employee.errors[:dob]
|
23
23
|
assert_equal ["can't be blank"], @employee.errors[:joined]
|
24
24
|
end
|
25
25
|
|
@@ -20,325 +20,30 @@ class GovUkDateFieldsTest < ActiveSupport::TestCase
|
|
20
20
|
@form_builder = ActionView::Helpers::FormBuilder.new(:employee, @employee, @template, {} )
|
21
21
|
end
|
22
22
|
|
23
|
+
test 'date_fields_no_error' do
|
24
|
+
fixture = file_fixture('date_fields_no_error.html').read
|
23
25
|
|
24
|
-
test "error raised if invalid options given" do
|
25
|
-
err = assert_raise do
|
26
|
-
GovUkDateFields::FormFields.new(@form_builder, :employee, :dob, rubbish: 'some_value')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
test "basic_output_without_fieldset" do
|
32
26
|
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :dob)
|
33
|
-
assert_html_equal(date_fields.raw_output,
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'placeholder_output_without_fieldset' do
|
37
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :dob, {placeholders: { day: 'DAY', month: 'MTH', year: 'YEAR' } })
|
38
|
-
assert_html_equal(date_fields.raw_output, expected_placeholder_output_without_fieldset)
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'fieldset_output_with_form_hint' do
|
42
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :dob, {legend_text: 'Date of birth', legend_class: 'govuk_legend_class', form_hint_text: 'In the form: dd mm yyyy'})
|
43
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_form_hint)
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'fieldset output with legend class' do
|
47
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', legend_class: 'date-legend-class', form_hint_text: 'For example, 31 3 1980'})
|
48
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_legend_class)
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'fieldset with id' do
|
52
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', id: 'employee_date_joined'})
|
53
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_id)
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'fieldset without explicit `id` passed in the options (will be autogenerated)' do
|
57
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date'})
|
58
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_without_id)
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'fieldset output with today button with no css class specified' do
|
62
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', id: 'employee_date_joined', today_button: true})
|
63
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_unstyled_today_button)
|
64
|
-
end
|
65
|
-
|
66
|
-
test 'fieldset output with today button with css class applied' do
|
67
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', id: 'employee_date_joined', today_button: {class: 'today-button-class'} } )
|
68
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_syled_today_button)
|
69
|
-
end
|
70
|
-
|
71
|
-
test 'fieldset with error_class and message' do
|
72
|
-
@employee.errors[:joined] << "Invalid joining date"
|
73
|
-
@employee.errors[:joined] << "Joining date must be in the past"
|
74
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', id: 'employee_date_joined'})
|
75
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_error_class_and_message)
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'fieldset with error_class and message, with autogenerated `id`' do
|
79
|
-
@employee.errors[:joined] << "Invalid joining date"
|
80
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date'})
|
81
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_error_class_and_message_without_id)
|
27
|
+
assert_html_equal(date_fields.raw_output, fixture)
|
82
28
|
end
|
83
29
|
|
84
|
-
test '
|
85
|
-
|
86
|
-
@employee.errors[:joined] << "must_be_in_past"
|
87
|
-
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :joined, {legend_text: 'Joining date', id: 'employee_date_joined', error_messages: ['Invalid joining date', 'Joining date must be in the past']})
|
88
|
-
assert_html_equal(date_fields.raw_output, expected_fieldset_output_with_error_class_and_message)
|
89
|
-
end
|
90
|
-
|
91
|
-
test "squash_html" do
|
92
|
-
html = " <html> This is some text \n <tr> \n <td> <%= dfkhdfh %> </td> </tr>\n</html> "
|
93
|
-
expected_result = "<html>This is some text<tr><td><%= dfkhdfh %></td></tr></html>"
|
94
|
-
assert_html_equal(html, expected_result)
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def expected_basic_output_without_fieldset
|
99
|
-
%Q{
|
100
|
-
<input value="7" id="employee_dob_dd" name="employee[dob_dd]" size="2" type="text" />
|
101
|
-
<input value="12" id="employee_dob_mm" name="employee[dob_mm]" size="3" type="text" />
|
102
|
-
<input value="1963" id="employee_dob_yyyy" name="employee[dob_yyyy]" size="4" type="text" />
|
103
|
-
}
|
104
|
-
end
|
30
|
+
test 'date_fields_error' do
|
31
|
+
fixture = file_fixture('date_fields_error.html').read
|
105
32
|
|
33
|
+
@employee.dob = nil
|
34
|
+
@employee.errors.add(:dob, :blank)
|
106
35
|
|
107
|
-
|
108
|
-
|
109
|
-
<input value="7" id="employee_dob_dd" name="employee[dob_dd]" placeholder="DAY" size="2" type="text" />
|
110
|
-
<input value="12" id="employee_dob_mm" name="employee[dob_mm]" placeholder="MTH" size="3" type="text" />
|
111
|
-
<input value="1963" id="employee_dob_yyyy" name="employee[dob_yyyy]" placeholder="YEAR" size="4" type="text" />
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
def expected_fieldset_output_with_error_class_and_message
|
116
|
-
%Q{
|
117
|
-
<div class="form-group gov_uk_date form-group-error" id="employee_date_joined">
|
118
|
-
<fieldset>
|
119
|
-
<legend>
|
120
|
-
<span class="form-label-bold">Joining date</span>
|
121
|
-
<span class="form-hint" id="employee_date_joined-hint">
|
122
|
-
For example, 31 3 1980
|
123
|
-
</span>
|
124
|
-
<ul>
|
125
|
-
<li><span class="error-message">Invalid joining date</span></li>
|
126
|
-
<li><span class="error-message">Joining date must be in the past</span></li>
|
127
|
-
</ul>
|
128
|
-
</legend>
|
129
|
-
<div class="form-date">
|
130
|
-
<div class="form-group form-group-day">
|
131
|
-
<label for="employee_joined_dd">Day</label>
|
132
|
-
<input class="form-control form-control-error" id="employee_joined_dd" name="employee[joined_dd]" type="number" min="0" max="31" aria-describedby="employee_date_joined-hint" value="1">
|
133
|
-
</div>
|
134
|
-
<div class="form-group form-group-month">
|
135
|
-
<label for="employee_joined_mm">Month</label>
|
136
|
-
<input class="form-control form-control-error" id="employee_joined_mm" name="employee[joined_mm]" type="number" min="0" max="12" value="4">
|
137
|
-
</div>
|
138
|
-
<div class="form-group form-group-year">
|
139
|
-
<label for="employee_joined_yyyy">Year</label>
|
140
|
-
<input class="form-control form-control-error" id="employee_joined_yyyy" name="employee[joined_yyyy]" type="number" min="0" max="2100" value="2015">
|
141
|
-
</div>
|
142
|
-
</div>
|
143
|
-
</fieldset>
|
144
|
-
</div>
|
145
|
-
}
|
146
|
-
end
|
147
|
-
|
148
|
-
def expected_fieldset_output_with_error_class_and_message_without_id
|
149
|
-
%Q{
|
150
|
-
<div class="form-group gov_uk_date form-group-error" id="error_employee_joined">
|
151
|
-
<fieldset>
|
152
|
-
<legend>
|
153
|
-
<span class="form-label-bold">Joining date</span>
|
154
|
-
<span class="form-hint" id="employee_joined-hint">
|
155
|
-
For example, 31 3 1980
|
156
|
-
</span>
|
157
|
-
<ul>
|
158
|
-
<li><span class="error-message">Invalid joining date</span></li>
|
159
|
-
</ul>
|
160
|
-
</legend>
|
161
|
-
<div class="form-date">
|
162
|
-
<div class="form-group form-group-day">
|
163
|
-
<label for="employee_joined_dd">Day</label>
|
164
|
-
<input class="form-control form-control-error" id="employee_joined_dd" name="employee[joined_dd]" type="number" min="0" max="31" aria-describedby="employee_joined-hint" value="1">
|
165
|
-
</div>
|
166
|
-
<div class="form-group form-group-month">
|
167
|
-
<label for="employee_joined_mm">Month</label>
|
168
|
-
<input class="form-control form-control-error" id="employee_joined_mm" name="employee[joined_mm]" type="number" min="0" max="12" value="4">
|
169
|
-
</div>
|
170
|
-
<div class="form-group form-group-year">
|
171
|
-
<label for="employee_joined_yyyy">Year</label>
|
172
|
-
<input class="form-control form-control-error" id="employee_joined_yyyy" name="employee[joined_yyyy]" type="number" min="0" max="2100" value="2015">
|
173
|
-
</div>
|
174
|
-
</div>
|
175
|
-
</fieldset>
|
176
|
-
</div>
|
177
|
-
}
|
178
|
-
end
|
179
|
-
|
180
|
-
def expected_fieldset_output_with_id
|
181
|
-
%Q{
|
182
|
-
<div class="form-group gov_uk_date" id="employee_date_joined">
|
183
|
-
<fieldset>
|
184
|
-
<legend>
|
185
|
-
<span class="form-label-bold">Joining date</span>
|
186
|
-
<span class="form-hint" id="employee_date_joined-hint">For example, 31 3 1980</span>
|
187
|
-
</legend>
|
188
|
-
<div class="form-date">
|
189
|
-
<div class="form-group form-group-day">
|
190
|
-
<label for="employee_joined_dd">Day</label>
|
191
|
-
<input class="form-control" id="employee_joined_dd" name="employee[joined_dd]" type="number" min="0" max="31" aria-describedby="employee_date_joined-hint" value="1">
|
192
|
-
</div>
|
193
|
-
<div class="form-group form-group-month">
|
194
|
-
<label for="employee_joined_mm">Month</label>
|
195
|
-
<input class="form-control" id="employee_joined_mm" name="employee[joined_mm]" type="number" min="0" max="12" value="4">
|
196
|
-
</div>
|
197
|
-
<div class="form-group form-group-year">
|
198
|
-
<label for="employee_joined_yyyy">Year</label>
|
199
|
-
<input class="form-control" id="employee_joined_yyyy" name="employee[joined_yyyy]" type="number" min="0" max="2100" value="2015">
|
200
|
-
</div>
|
201
|
-
</div>
|
202
|
-
</fieldset>
|
203
|
-
</div>
|
204
|
-
}
|
205
|
-
end
|
206
|
-
|
207
|
-
def expected_fieldset_output_without_id
|
208
|
-
%Q{
|
209
|
-
<div class="form-group gov_uk_date" id="employee_joined">
|
210
|
-
<fieldset>
|
211
|
-
<legend>
|
212
|
-
<span class="form-label-bold">Joining date</span>
|
213
|
-
<span class="form-hint" id="employee_joined-hint">For example, 31 3 1980</span>
|
214
|
-
</legend>
|
215
|
-
<div class="form-date">
|
216
|
-
<div class="form-group form-group-day">
|
217
|
-
<label for="employee_joined_dd">Day</label>
|
218
|
-
<input class="form-control" id="employee_joined_dd" name="employee[joined_dd]" type="number" min="0" max="31" aria-describedby="employee_joined-hint" value="1">
|
219
|
-
</div>
|
220
|
-
<div class="form-group form-group-month">
|
221
|
-
<label for="employee_joined_mm">Month</label>
|
222
|
-
<input class="form-control" id="employee_joined_mm" name="employee[joined_mm]" type="number" min="0" max="12" value="4">
|
223
|
-
</div>
|
224
|
-
<div class="form-group form-group-year">
|
225
|
-
<label for="employee_joined_yyyy">Year</label>
|
226
|
-
<input class="form-control" id="employee_joined_yyyy" name="employee[joined_yyyy]" type="number" min="0" max="2100" value="2015">
|
227
|
-
</div>
|
228
|
-
</div>
|
229
|
-
</fieldset>
|
230
|
-
</div>
|
231
|
-
}
|
232
|
-
end
|
233
|
-
|
234
|
-
def expected_fieldset_output_with_form_hint
|
235
|
-
%Q{
|
236
|
-
<div class="form-group gov_uk_date" id="employee_dob">
|
237
|
-
<fieldset>
|
238
|
-
<legend class="govuk_legend_class">
|
239
|
-
<span class="form-label-bold">Date of birth</span>
|
240
|
-
<span class="form-hint" id="employee_dob-hint">In the form: dd mm yyyy</span>
|
241
|
-
</legend>
|
242
|
-
<div class="form-date">
|
243
|
-
<div class="form-group form-group-day">
|
244
|
-
<label for="employee_dob_dd">Day</label>
|
245
|
-
<input class="form-control" id="employee_dob_dd" name="employee[dob_dd]" type="number" min="0" max="31" aria-describedby="employee_dob-hint" value="7">
|
246
|
-
</div>
|
247
|
-
<div class="form-group form-group-month">
|
248
|
-
<label for="employee_dob_mm">Month</label>
|
249
|
-
<input class="form-control" id="employee_dob_mm" name="employee[dob_mm]" type="number" min="0" max="12" value="12">
|
250
|
-
</div>
|
251
|
-
<div class="form-group form-group-year">
|
252
|
-
<label for="employee_dob_yyyy">Year</label>
|
253
|
-
<input class="form-control" id="employee_dob_yyyy" name="employee[dob_yyyy]" type="number" min="0" max="2100" value="1963">
|
254
|
-
</div>
|
255
|
-
</div>
|
256
|
-
</fieldset>
|
257
|
-
</div>
|
258
|
-
}
|
36
|
+
date_fields = GovUkDateFields::FormFields.new(@form_builder, :employee, :dob)
|
37
|
+
assert_html_equal(date_fields.raw_output, fixture)
|
259
38
|
end
|
260
39
|
|
261
|
-
|
262
|
-
|
263
|
-
<div class="form-group gov_uk_date" id="employee_joined">
|
264
|
-
<fieldset>
|
265
|
-
<legend class="date-legend-class">
|
266
|
-
<span class="form-label-bold">Joining date</span>
|
267
|
-
<span class="form-hint" id="employee_joined-hint">For example, 31 3 1980</span>
|
268
|
-
</legend>
|
269
|
-
<div class="form-date">
|
270
|
-
<div class="form-group form-group-day">
|
271
|
-
<label for="employee_joined_dd">Day</label>
|
272
|
-
<input class="form-control" id="employee_joined_dd" name="employee[joined_dd]" type="number" min="0" max="31" aria-describedby="employee_joined-hint" value="1">
|
273
|
-
</div>
|
274
|
-
<div class="form-group form-group-month">
|
275
|
-
<label for="employee_joined_mm">Month</label>
|
276
|
-
<input class="form-control" id="employee_joined_mm" name="employee[joined_mm]" type="number" min="0" max="12" value="4">
|
277
|
-
</div>
|
278
|
-
<div class="form-group form-group-year">
|
279
|
-
<label for="employee_joined_yyyy">Year</label>
|
280
|
-
<input class="form-control" id="employee_joined_yyyy" name="employee[joined_yyyy]" type="number" min="0" max="2100" value="2015">
|
281
|
-
</div>
|
282
|
-
</div>
|
283
|
-
</fieldset>
|
284
|
-
</div>
|
285
|
-
}
|
286
|
-
end
|
40
|
+
test 'date_fields_no_heading' do
|
41
|
+
fixture = file_fixture('date_fields_no_heading.html').read
|
287
42
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
<span class="form-label-bold">Joining date</span>
|
294
|
-
<span class="form-hint" id="employee_date_joined-hint">For example, 31 3 1980</span>
|
295
|
-
</legend>
|
296
|
-
<div class="form-date">
|
297
|
-
<a class="button" role="button" href="#">Today</a>
|
298
|
-
<div class="form-group form-group-day">
|
299
|
-
<label for="employee_joined_dd">Day</label>
|
300
|
-
<input class="form-control" id="employee_joined_dd" name="employee[joined_dd]" type="number" min="0" max="31" aria-describedby="employee_date_joined-hint" value="1">
|
301
|
-
</div>
|
302
|
-
<div class="form-group form-group-month">
|
303
|
-
<label for="employee_joined_mm">Month</label>
|
304
|
-
<input class="form-control" id="employee_joined_mm" name="employee[joined_mm]" type="number" min="0" max="12" value="4">
|
305
|
-
</div>
|
306
|
-
<div class="form-group form-group-year">
|
307
|
-
<label for="employee_joined_yyyy">Year</label>
|
308
|
-
<input class="form-control" id="employee_joined_yyyy" name="employee[joined_yyyy]" type="number" min="0" max="2100" value="2015">
|
309
|
-
</div>
|
310
|
-
</div>
|
311
|
-
</fieldset>
|
312
|
-
</div>
|
313
|
-
}
|
43
|
+
date_fields = GovUkDateFields::FormFields.new(
|
44
|
+
@form_builder, :employee, :dob,
|
45
|
+
legend_options: { page_heading: false, visually_hidden: true }
|
46
|
+
)
|
47
|
+
assert_html_equal(date_fields.raw_output, fixture)
|
314
48
|
end
|
315
|
-
|
316
|
-
def expected_fieldset_output_with_syled_today_button
|
317
|
-
%Q{
|
318
|
-
<div class="form-group gov_uk_date" id="employee_date_joined">
|
319
|
-
<fieldset>
|
320
|
-
<legend>
|
321
|
-
<span class="form-label-bold">Joining date</span>
|
322
|
-
<span class="form-hint" id="employee_date_joined-hint">For example, 31 3 1980</span>
|
323
|
-
</legend>
|
324
|
-
<div class="form-date">
|
325
|
-
<a class="today-button-class" role="button" href="#">Today</a>
|
326
|
-
<div class="form-group form-group-day">
|
327
|
-
<label for="employee_joined_dd">Day</label>
|
328
|
-
<input class="form-control" id="employee_joined_dd" name="employee[joined_dd]" type="number" min="0" max="31" aria-describedby="employee_date_joined-hint" value="1">
|
329
|
-
</div>
|
330
|
-
<div class="form-group form-group-month">
|
331
|
-
<label for="employee_joined_mm">Month</label>
|
332
|
-
<input class="form-control" id="employee_joined_mm" name="employee[joined_mm]" type="number" min="0" max="12" value="4">
|
333
|
-
</div>
|
334
|
-
<div class="form-group form-group-year">
|
335
|
-
<label for="employee_joined_yyyy">Year</label>
|
336
|
-
<input class="form-control" id="employee_joined_yyyy" name="employee[joined_yyyy]" type="number" min="0" max="2100" value="2015">
|
337
|
-
</div>
|
338
|
-
</div>
|
339
|
-
</fieldset>
|
340
|
-
</div>
|
341
|
-
}
|
342
|
-
end
|
343
|
-
|
344
49
|
end
|