simple_form 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/MIT-LICENSE +1 -1
- data/README.md +3 -4
- data/lib/simple_form/components/label_input.rb +1 -1
- data/lib/simple_form/form_builder.rb +1 -5
- data/lib/simple_form/railtie.rb +4 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/leaf.rb +1 -1
- data/lib/simple_form.rb +8 -4
- metadata +5 -85
- data/test/action_view_extensions/builder_test.rb +0 -634
- data/test/action_view_extensions/form_helper_test.rb +0 -172
- data/test/components/custom_components_test.rb +0 -62
- data/test/components/label_test.rb +0 -352
- data/test/form_builder/association_test.rb +0 -252
- data/test/form_builder/button_test.rb +0 -48
- data/test/form_builder/error_notification_test.rb +0 -80
- data/test/form_builder/error_test.rb +0 -281
- data/test/form_builder/general_test.rb +0 -539
- data/test/form_builder/hint_test.rb +0 -150
- data/test/form_builder/input_field_test.rb +0 -195
- data/test/form_builder/label_test.rb +0 -136
- data/test/form_builder/wrapper_test.rb +0 -378
- data/test/generators/simple_form_generator_test.rb +0 -43
- data/test/inputs/boolean_input_test.rb +0 -256
- data/test/inputs/collection_check_boxes_input_test.rb +0 -323
- data/test/inputs/collection_radio_buttons_input_test.rb +0 -446
- data/test/inputs/collection_select_input_test.rb +0 -380
- data/test/inputs/color_input_test.rb +0 -10
- data/test/inputs/country_input_test.rb +0 -36
- data/test/inputs/datetime_input_test.rb +0 -176
- data/test/inputs/disabled_test.rb +0 -92
- data/test/inputs/discovery_test.rb +0 -142
- data/test/inputs/file_input_test.rb +0 -17
- data/test/inputs/general_test.rb +0 -133
- data/test/inputs/grouped_collection_select_input_test.rb +0 -196
- data/test/inputs/hidden_input_test.rb +0 -32
- data/test/inputs/numeric_input_test.rb +0 -177
- data/test/inputs/readonly_test.rb +0 -102
- data/test/inputs/required_test.rb +0 -158
- data/test/inputs/rich_text_area_input_test.rb +0 -15
- data/test/inputs/string_input_test.rb +0 -158
- data/test/inputs/text_input_test.rb +0 -37
- data/test/inputs/time_zone_input_test.rb +0 -36
- data/test/simple_form_test.rb +0 -18
- data/test/support/discovery_inputs.rb +0 -65
- data/test/support/misc_helpers.rb +0 -274
- data/test/support/mock_controller.rb +0 -30
- data/test/support/models.rb +0 -357
- data/test/test_helper.rb +0 -95
@@ -1,380 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class CollectionSelectInputTest < ActionView::TestCase
|
6
|
-
test 'input generates a boolean select with options by default for select types' do
|
7
|
-
with_input_for @user, :active, :select
|
8
|
-
assert_select 'select.select#user_active'
|
9
|
-
assert_select 'select option[value=true]', 'Yes'
|
10
|
-
assert_select 'select option[value=false]', 'No'
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'input as select uses i18n to translate select boolean options' do
|
14
|
-
store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
|
15
|
-
with_input_for @user, :active, :select
|
16
|
-
assert_select 'select option[value=true]', 'Sim'
|
17
|
-
assert_select 'select option[value=false]', 'Não'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'input allows overriding collection for select types' do
|
22
|
-
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
23
|
-
assert_select 'select.select#user_name'
|
24
|
-
assert_select 'select option', 'Jose'
|
25
|
-
assert_select 'select option', 'Carlos'
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'input does automatic collection translation for select types using defaults key' do
|
29
|
-
store_translations(:en, simple_form: { options: { defaults: {
|
30
|
-
gender: { male: 'Male', female: 'Female' }
|
31
|
-
} } }) do
|
32
|
-
with_input_for @user, :gender, :select, collection: %i[male female]
|
33
|
-
assert_select 'select.select#user_gender'
|
34
|
-
assert_select 'select option', 'Male'
|
35
|
-
assert_select 'select option', 'Female'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
test 'input does automatic collection translation for select types using specific object key' do
|
40
|
-
store_translations(:en, simple_form: { options: { user: {
|
41
|
-
gender: { male: 'Male', female: 'Female' }
|
42
|
-
} } }) do
|
43
|
-
with_input_for @user, :gender, :select, collection: %i[male female]
|
44
|
-
assert_select 'select.select#user_gender'
|
45
|
-
assert_select 'select option', 'Male'
|
46
|
-
assert_select 'select option', 'Female'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'input marks the selected value by default' do
|
51
|
-
@user.name = "Carlos"
|
52
|
-
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
53
|
-
assert_select 'select option[selected=selected]', 'Carlos'
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'input accepts html options as the last element of collection' do
|
57
|
-
with_input_for @user, :name, :select, collection: [['Jose', class: 'foo']]
|
58
|
-
assert_select 'select.select#user_name'
|
59
|
-
assert_select 'select option.foo', 'Jose'
|
60
|
-
end
|
61
|
-
|
62
|
-
test 'input marks the selected value also when using integers' do
|
63
|
-
@user.age = 18
|
64
|
-
with_input_for @user, :age, :select, collection: 18..60
|
65
|
-
assert_select 'select option[selected=selected]', '18'
|
66
|
-
end
|
67
|
-
|
68
|
-
test 'input marks the selected value when using booleans and select' do
|
69
|
-
@user.active = false
|
70
|
-
with_input_for @user, :active, :select
|
71
|
-
assert_no_select 'select option[selected][value=true]', 'Yes'
|
72
|
-
assert_select 'select option[selected][value=false]', 'No'
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'input sets the correct value when using a collection that includes floats' do
|
76
|
-
with_input_for @user, :age, :select, collection: [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
|
77
|
-
assert_select 'select option[value="2.0"]'
|
78
|
-
assert_select 'select option[value="2.5"]'
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'input sets the correct values when using a collection that uses mixed values' do
|
82
|
-
with_input_for @user, :age, :select, collection: ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
|
83
|
-
assert_select 'select option[value="Hello Kitty"]'
|
84
|
-
assert_select 'select option[value="2"]'
|
85
|
-
assert_select 'select option[value="4.5"]'
|
86
|
-
assert_select 'select option[value="johnny"]'
|
87
|
-
assert_select 'select option[value=""]'
|
88
|
-
assert_select 'select option[value="true"]'
|
89
|
-
assert_select 'select option[value="false"]'
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'input includes a blank option even if :include_blank is set to false if the collection includes a nil value' do
|
93
|
-
with_input_for @user, :age, :select, collection: [nil], include_blank: false
|
94
|
-
assert_select 'select option[value=""]'
|
95
|
-
end
|
96
|
-
|
97
|
-
test 'input automatically sets include blank' do
|
98
|
-
with_input_for @user, :age, :select, collection: 18..30
|
99
|
-
assert_select 'select option[value=""]', ''
|
100
|
-
end
|
101
|
-
|
102
|
-
test 'input translates include blank when set to :translate' do
|
103
|
-
store_translations(:en, simple_form: { include_blanks: { user: {
|
104
|
-
age: 'Rather not say'
|
105
|
-
} } }) do
|
106
|
-
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
107
|
-
assert_select 'select option[value=""]', 'Rather not say'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
test 'input translates include blank with a default' do
|
112
|
-
store_translations(:en, simple_form: { include_blanks: { defaults: {
|
113
|
-
age: 'Rather not say'
|
114
|
-
} } }) do
|
115
|
-
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
116
|
-
assert_select 'select option[value=""]', 'Rather not say'
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
test 'input does not translate include blank when set to a string' do
|
121
|
-
store_translations(:en, simple_form: { include_blanks: { user: {
|
122
|
-
age: 'Rather not say'
|
123
|
-
} } }) do
|
124
|
-
with_input_for @user, :age, :select, collection: 18..30, include_blank: 'Young at heart'
|
125
|
-
assert_select 'select option[value=""]', 'Young at heart'
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
test 'input does not translate include blank when automatically set' do
|
130
|
-
store_translations(:en, simple_form: { include_blanks: { user: {
|
131
|
-
age: 'Rather not say'
|
132
|
-
} } }) do
|
133
|
-
with_input_for @user, :age, :select, collection: 18..30
|
134
|
-
assert_select 'select option[value=""]', ''
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
test 'input does not translate include blank when set to true' do
|
139
|
-
store_translations(:en, simple_form: { include_blanks: { user: {
|
140
|
-
age: 'Rather not say'
|
141
|
-
} } }) do
|
142
|
-
with_input_for @user, :age, :select, collection: 18..30, include_blank: true
|
143
|
-
assert_select 'select option[value=""]', ''
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
test 'input does not translate include blank when set to false' do
|
148
|
-
store_translations(:en, simple_form: { include_blanks: { user: {
|
149
|
-
age: 'Rather not say'
|
150
|
-
} } }) do
|
151
|
-
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
152
|
-
assert_no_select 'select option[value=""]'
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
test 'input does not set include blank if otherwise is told' do
|
157
|
-
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
158
|
-
assert_no_select 'select option[value=""]'
|
159
|
-
end
|
160
|
-
|
161
|
-
test 'input does not set include blank if prompt is given' do
|
162
|
-
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
163
|
-
assert_no_select 'select option[value=""]', ''
|
164
|
-
end
|
165
|
-
|
166
|
-
test 'input does not set include blank if multiple is given' do
|
167
|
-
with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
|
168
|
-
assert_no_select 'select option[value=""]', ''
|
169
|
-
end
|
170
|
-
|
171
|
-
test 'input translates prompt when set to :translate' do
|
172
|
-
store_translations(:en, simple_form: { prompts: { user: {
|
173
|
-
age: 'Select age:'
|
174
|
-
} } }) do
|
175
|
-
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
176
|
-
assert_select 'select option[value=""]', 'Select age:'
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
test 'input translates prompt with a default' do
|
181
|
-
store_translations(:en, simple_form: { prompts: { defaults: {
|
182
|
-
age: 'Select age:'
|
183
|
-
} } }) do
|
184
|
-
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
185
|
-
assert_select 'select option[value=""]', 'Select age:'
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
test 'input does not translate prompt when set to a string' do
|
190
|
-
store_translations(:en, simple_form: { prompts: { user: {
|
191
|
-
age: 'Select age:'
|
192
|
-
} } }) do
|
193
|
-
with_input_for @user, :age, :select, collection: 18..30, prompt: 'Do it:'
|
194
|
-
assert_select 'select option[value=""]', 'Do it:'
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
test 'input does not translate prompt when set to false' do
|
199
|
-
store_translations(:en, simple_form: { prompts: { user: {
|
200
|
-
age: 'Select age:'
|
201
|
-
} } }) do
|
202
|
-
with_input_for @user, :age, :select, collection: 18..30, prompt: false
|
203
|
-
assert_no_select 'select option[value=""]'
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
test 'input uses Rails prompt translation as a fallback' do
|
208
|
-
store_translations(:en, helpers: { select: {
|
209
|
-
prompt: 'Select value:'
|
210
|
-
} }) do
|
211
|
-
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
212
|
-
assert_select 'select option[value=""]', "Select value:"
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
test 'input detects label and value on collections' do
|
217
|
-
users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
|
218
|
-
with_input_for @user, :description, :select, collection: users
|
219
|
-
assert_select 'select option[value="1"]', 'Jose'
|
220
|
-
assert_select 'select option[value="2"]', 'Carlos'
|
221
|
-
end
|
222
|
-
|
223
|
-
test 'input disables the anothers components when the option is a object' do
|
224
|
-
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: true
|
225
|
-
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
226
|
-
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
227
|
-
assert_select 'select[disabled=disabled]'
|
228
|
-
assert_select 'div.disabled'
|
229
|
-
end
|
230
|
-
|
231
|
-
test 'input does not disable the anothers components when the option is a object' do
|
232
|
-
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: 'Jose'
|
233
|
-
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
234
|
-
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
235
|
-
assert_no_select 'select[disabled=disabled]'
|
236
|
-
assert_no_select 'div.disabled'
|
237
|
-
end
|
238
|
-
|
239
|
-
test 'input allows overriding label and value method using a lambda for collection selects' do
|
240
|
-
with_input_for @user, :name, :select,
|
241
|
-
collection: %w[Jose Carlos],
|
242
|
-
label_method: ->(i) { i.upcase },
|
243
|
-
value_method: ->(i) { i.downcase }
|
244
|
-
assert_select 'select option[value=jose]', "JOSE"
|
245
|
-
assert_select 'select option[value=carlos]', "CARLOS"
|
246
|
-
end
|
247
|
-
|
248
|
-
test 'input allows overriding only label but not value method using a lambda for collection select' do
|
249
|
-
with_input_for @user, :name, :select,
|
250
|
-
collection: %w[Jose Carlos],
|
251
|
-
label_method: ->(i) { i.upcase }
|
252
|
-
assert_select 'select option[value=Jose]', "JOSE"
|
253
|
-
assert_select 'select option[value=Carlos]', "CARLOS"
|
254
|
-
end
|
255
|
-
|
256
|
-
test 'input allows overriding only value but not label method using a lambda for collection select' do
|
257
|
-
with_input_for @user, :name, :select,
|
258
|
-
collection: %w[Jose Carlos],
|
259
|
-
value_method: ->(i) { i.downcase }
|
260
|
-
assert_select 'select option[value=jose]', "Jose"
|
261
|
-
assert_select 'select option[value=carlos]', "Carlos"
|
262
|
-
end
|
263
|
-
|
264
|
-
test 'input allows symbols for collections' do
|
265
|
-
with_input_for @user, :name, :select, collection: %i[jose carlos]
|
266
|
-
assert_select 'select.select#user_name'
|
267
|
-
assert_select 'select option[value=jose]', 'jose'
|
268
|
-
assert_select 'select option[value=carlos]', 'carlos'
|
269
|
-
end
|
270
|
-
|
271
|
-
test 'collection input with select type generates required html attribute only with blank option' do
|
272
|
-
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
273
|
-
assert_select 'select.required'
|
274
|
-
assert_select 'select[required]'
|
275
|
-
end
|
276
|
-
|
277
|
-
test 'collection input with select type generates required html attribute only with blank option or prompt' do
|
278
|
-
with_input_for @user, :name, :select, prompt: 'Name...', collection: %w[Jose Carlos]
|
279
|
-
assert_select 'select.required'
|
280
|
-
assert_select 'select[required]'
|
281
|
-
end
|
282
|
-
|
283
|
-
test "collection input generated aria-label should contain 'true'" do
|
284
|
-
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
285
|
-
assert_select 'select.required'
|
286
|
-
assert_select 'select[aria-required=true]'
|
287
|
-
end
|
288
|
-
|
289
|
-
test 'collection input with select type does not generate required html attribute without blank option' do
|
290
|
-
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
291
|
-
assert_select 'select.required'
|
292
|
-
assert_no_select 'select[required]'
|
293
|
-
assert_no_select 'select[aria-required=true]'
|
294
|
-
end
|
295
|
-
|
296
|
-
test 'collection input with select type with multiple attribute generates required html attribute without blank option' do
|
297
|
-
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
298
|
-
assert_select 'select.required'
|
299
|
-
assert_select 'select[required]'
|
300
|
-
end
|
301
|
-
|
302
|
-
test 'collection input with select type with multiple attribute generates required html attribute with blank option' do
|
303
|
-
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
304
|
-
assert_select 'select.required'
|
305
|
-
assert_select 'select[required]'
|
306
|
-
end
|
307
|
-
|
308
|
-
test 'with a blank option, a collection input of type select has an aria-required html attribute' do
|
309
|
-
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
310
|
-
assert_select 'select.required'
|
311
|
-
assert_select 'select[aria-required=true]'
|
312
|
-
end
|
313
|
-
|
314
|
-
test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do
|
315
|
-
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
316
|
-
assert_select 'select.required'
|
317
|
-
assert_no_select 'select[aria-required]'
|
318
|
-
end
|
319
|
-
|
320
|
-
test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do
|
321
|
-
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
322
|
-
assert_select 'select.required'
|
323
|
-
assert_select 'select[aria-required=true]'
|
324
|
-
end
|
325
|
-
|
326
|
-
test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do
|
327
|
-
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
328
|
-
assert_select 'select.required'
|
329
|
-
assert_select 'select[aria-required]'
|
330
|
-
end
|
331
|
-
|
332
|
-
test 'input allows disabled options with a lambda for collection select' do
|
333
|
-
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
334
|
-
disabled: ->(x) { x == "Carlos" }
|
335
|
-
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
336
|
-
assert_select 'select option[value=Antonio]', 'Antonio'
|
337
|
-
assert_no_select 'select option[value=Antonio][disabled]'
|
338
|
-
end
|
339
|
-
|
340
|
-
test 'input allows disabled and label method with lambdas for collection select' do
|
341
|
-
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
342
|
-
disabled: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
343
|
-
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
344
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
345
|
-
assert_no_select 'select option[value=Antonio][disabled]'
|
346
|
-
end
|
347
|
-
|
348
|
-
test 'input allows a non lambda disabled option with lambda label method for collections' do
|
349
|
-
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
350
|
-
disabled: "Carlos", label_method: ->(x) { x.upcase }
|
351
|
-
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
352
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
353
|
-
assert_no_select 'select option[value=Antonio][disabled]'
|
354
|
-
end
|
355
|
-
|
356
|
-
test 'input allows selected and label method with lambdas for collection select' do
|
357
|
-
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
358
|
-
selected: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
359
|
-
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
360
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
361
|
-
assert_no_select 'select option[value=Antonio][selected]'
|
362
|
-
end
|
363
|
-
|
364
|
-
test 'input allows a non lambda selected option with lambda label method for collection select' do
|
365
|
-
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
366
|
-
selected: "Carlos", label_method: ->(x) { x.upcase }
|
367
|
-
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
368
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
369
|
-
assert_no_select 'select option[value=Antonio][selected]'
|
370
|
-
end
|
371
|
-
|
372
|
-
test 'input does not override default selection through attribute value with label method as lambda for collection select' do
|
373
|
-
@user.name = "Carlos"
|
374
|
-
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
375
|
-
label_method: ->(x) { x.upcase }
|
376
|
-
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
377
|
-
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
378
|
-
assert_no_select 'select option[value=Antonio][selected]'
|
379
|
-
end
|
380
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ColorInputTest < ActionView::TestCase
|
6
|
-
test 'input generates a color field' do
|
7
|
-
with_input_for @user, :favorite_color, :color
|
8
|
-
assert_select 'input[type=color].color#user_favorite_color'
|
9
|
-
end
|
10
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class CountryInputTest < ActionView::TestCase
|
6
|
-
test 'input generates a country select field' do
|
7
|
-
with_input_for @user, :country, :country
|
8
|
-
assert_select 'select#user_country'
|
9
|
-
assert_select 'select option[value=BR]', 'Brazil'
|
10
|
-
assert_no_select 'select option[value=""][disabled=disabled]'
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'input generates a country select with SimpleForm default' do
|
14
|
-
swap SimpleForm, country_priority: [ 'Brazil' ] do
|
15
|
-
with_input_for @user, :country, :country
|
16
|
-
assert_select 'select option[value="BR"] + option[value="---------------"][disabled=disabled]'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'input generates a country select using options priority' do
|
21
|
-
with_input_for @user, :country, :country, priority: [ 'Ukraine' ]
|
22
|
-
assert_select 'select option[value="UA"] + option[value="---------------"][disabled=disabled]'
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'input does generate select element with required html attribute' do
|
26
|
-
with_input_for @user, :country, :country
|
27
|
-
assert_select 'select.required'
|
28
|
-
assert_select 'select[required]'
|
29
|
-
end
|
30
|
-
|
31
|
-
test 'input does generate select element with aria-required html attribute' do
|
32
|
-
with_input_for @user, :country, :country
|
33
|
-
assert_select 'select.required'
|
34
|
-
assert_select 'select[aria-required]'
|
35
|
-
end
|
36
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
|
6
|
-
class DateTimeInputWithHtml5Test < ActionView::TestCase
|
7
|
-
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enbled' do
|
8
|
-
with_input_for @user, :created_at, :datetime, html5: true
|
9
|
-
assert_select 'input[type="datetime-local"]'
|
10
|
-
end
|
11
|
-
|
12
|
-
test 'input generates a datetime select for datetime attributes' do
|
13
|
-
with_input_for @user, :created_at, :datetime
|
14
|
-
|
15
|
-
assert_select 'select.datetime'
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enbled' do
|
19
|
-
with_input_for @user, :born_at, :date, html5: true
|
20
|
-
|
21
|
-
assert_select 'input[type="date"]'
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'input generates a date select for date attributes' do
|
25
|
-
with_input_for @user, :born_at, :date
|
26
|
-
|
27
|
-
assert_select 'select.date'
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enbled' do
|
31
|
-
with_input_for @user, :delivery_time, :time, html5: true
|
32
|
-
|
33
|
-
assert_select 'input[type="time"]'
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'input generates a time select for time attributes' do
|
37
|
-
with_input_for @user, :delivery_time, :time
|
38
|
-
|
39
|
-
assert_select 'select.time'
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'input generates required html attribute' do
|
43
|
-
with_input_for @user, :delivery_time, :time, required: true, html5: true
|
44
|
-
assert_select 'input.required'
|
45
|
-
assert_select 'input[required]'
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'input has an aria-required html attribute' do
|
49
|
-
with_input_for @user, :delivery_time, :time, required: true, html5: true
|
50
|
-
assert_select 'input[aria-required=true]'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
|
55
|
-
class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
56
|
-
test 'input generates a datetime select by default for datetime attributes' do
|
57
|
-
swap_wrapper do
|
58
|
-
with_input_for @user, :created_at, :datetime
|
59
|
-
1.upto(5) do |i|
|
60
|
-
assert_select "form select.datetime#user_created_at_#{i}i"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
test 'input is able to pass options to datetime select' do
|
66
|
-
with_input_for @user, :created_at, :datetime, html5: false,
|
67
|
-
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
68
|
-
|
69
|
-
assert_select 'select.datetime[disabled=disabled]'
|
70
|
-
assert_select 'select.datetime option', 'ano'
|
71
|
-
assert_select 'select.datetime option', 'mês'
|
72
|
-
assert_select 'select.datetime option', 'dia'
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enabled' do
|
76
|
-
swap_wrapper do
|
77
|
-
with_input_for @user, :created_at, :datetime, html5: true
|
78
|
-
assert_select 'input[type="datetime-local"]'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
test 'input generates a date select for date attributes' do
|
83
|
-
swap_wrapper do
|
84
|
-
with_input_for @user, :born_at, :date
|
85
|
-
assert_select 'select.date#user_born_at_1i'
|
86
|
-
assert_select 'select.date#user_born_at_2i'
|
87
|
-
assert_select 'select.date#user_born_at_3i'
|
88
|
-
assert_no_select 'select.date#user_born_at_4i'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'input is able to pass options to date select' do
|
93
|
-
with_input_for @user, :born_at, :date, as: :date, html5: false,
|
94
|
-
disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
|
95
|
-
|
96
|
-
assert_select 'select.date[disabled=disabled]'
|
97
|
-
assert_select 'select.date option', 'ano'
|
98
|
-
assert_select 'select.date option', 'mês'
|
99
|
-
assert_select 'select.date option', 'dia'
|
100
|
-
end
|
101
|
-
|
102
|
-
test 'input is able to pass :default to date select' do
|
103
|
-
with_input_for @user, :born_at, :date, default: Date.today, html5: false
|
104
|
-
assert_select "select.date option[value='#{Date.today.year}'][selected=selected]"
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enabled' do
|
108
|
-
swap_wrapper do
|
109
|
-
with_input_for @user, :born_at, :date, html5: true
|
110
|
-
|
111
|
-
assert_select 'input[type="date"]'
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
test 'input generates a time select for time attributes' do
|
116
|
-
swap_wrapper do
|
117
|
-
with_input_for @user, :delivery_time, :time
|
118
|
-
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
119
|
-
assert_select 'input[type=hidden]#user_delivery_time_2i'
|
120
|
-
assert_select 'input[type=hidden]#user_delivery_time_3i'
|
121
|
-
assert_select 'select.time#user_delivery_time_4i'
|
122
|
-
assert_select 'select.time#user_delivery_time_5i'
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
test 'input is able to pass options to time select' do
|
127
|
-
with_input_for @user, :delivery_time, :time, required: true, html5: false,
|
128
|
-
disabled: true, prompt: { hour: 'hora', minute: 'minuto' }
|
129
|
-
|
130
|
-
assert_select 'select.time[disabled=disabled]'
|
131
|
-
assert_select 'select.time option', 'hora'
|
132
|
-
assert_select 'select.time option', 'minuto'
|
133
|
-
end
|
134
|
-
|
135
|
-
test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enabled' do
|
136
|
-
swap_wrapper do
|
137
|
-
with_input_for @user, :delivery_time, :time, html5: true
|
138
|
-
|
139
|
-
assert_select 'input[type="time"]'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
test 'label uses i18n to get target for date input type' do
|
144
|
-
store_translations(:en, date: { order: %w[month day year] }) do
|
145
|
-
with_input_for :project, :created_at, :date, html5: false
|
146
|
-
assert_select 'label[for=project_created_at_2i]'
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
test 'label uses i18n to get target for datetime input type' do
|
151
|
-
store_translations(:en, date: { order: %w[month day year] }) do
|
152
|
-
with_input_for :project, :created_at, :datetime, html5: false
|
153
|
-
assert_select 'label[for=project_created_at_2i]'
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
test 'label uses order to get target when date input type' do
|
158
|
-
with_input_for :project, :created_at, :date, order: %w[month year day], html5: false
|
159
|
-
assert_select 'label[for=project_created_at_2i]'
|
160
|
-
end
|
161
|
-
|
162
|
-
test 'label uses order to get target when datetime input type' do
|
163
|
-
with_input_for :project, :created_at, :datetime, order: %w[month year day], html5: false
|
164
|
-
assert_select 'label[for=project_created_at_2i]'
|
165
|
-
end
|
166
|
-
|
167
|
-
test 'label points to first option when time input type' do
|
168
|
-
with_input_for :project, :created_at, :time, html5: false
|
169
|
-
assert_select 'label[for=project_created_at_4i]'
|
170
|
-
end
|
171
|
-
|
172
|
-
test 'label points to attribute name if HTML5 compatibility is explicitly enabled' do
|
173
|
-
with_input_for :project, :created_at, :date, html5: true
|
174
|
-
assert_select 'label[for=project_created_at]'
|
175
|
-
end
|
176
|
-
end
|