Skip to content

Commit 1f04b93

Browse files
author
Stefano Savanelli
committed
add test to nested_input on filters usage
1 parent da77ea9 commit 1f04b93

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

spec/features/inputs/nested_select_input_spec.rb

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,83 @@
185185
end
186186
end
187187
end
188+
context "with filters", focus: true do
189+
before do
190+
register_page(Country, false) {}
191+
register_page(Region, false) {}
192+
register_page(City, false) {}
193+
194+
register_form(Invoice, false) do |f|
195+
f.input :city_id, as: :nested_select,
196+
level_1: { attribute: :country_id },
197+
level_2: {
198+
attribute: :region_id,
199+
filters: { name_contains: 'Met' }
200+
},
201+
level_3: { attribute: :city_id }
202+
end
203+
204+
create_cities
205+
create_invoice(city: @colina)
206+
visit edit_admin_invoice_path(@invoice)
207+
end
208+
209+
it "shows filled select controls based on defined city_id", js: true do
210+
on_input_ctx("invoice_country_id") { expect_select2_selection("Chile") }
211+
on_input_ctx("invoice_region_id") { expect_select2_selection("Metropolitana") }
212+
on_input_ctx("invoice_city_id") { expect_select2_selection("Colina") }
213+
end
214+
215+
context "updating medium level" do
216+
before do
217+
on_input_ctx("invoice_region_id") { open_select2_options }
218+
select2_input.set("a")
219+
end
220+
221+
it "shows no results based on entered text", js: true do
222+
expect_select2_results_count_to_eq(1)
223+
end
224+
end
225+
end
226+
227+
context "without filters", focus: true do
228+
before do
229+
register_page(Country, false) {}
230+
register_page(Region, false) {}
231+
register_page(City, false) {}
232+
233+
register_form(Invoice, false) do |f|
234+
f.input :city_id, as: :nested_select,
235+
level_1: { attribute: :country_id },
236+
level_2: {
237+
attribute: :region_id,
238+
# filters: { name_contains: 'Met' }
239+
},
240+
level_3: { attribute: :city_id }
241+
end
242+
243+
create_cities
244+
create_invoice(city: @colina)
245+
visit edit_admin_invoice_path(@invoice)
246+
end
247+
248+
it "shows filled select controls based on defined city_id", js: true do
249+
on_input_ctx("invoice_country_id") { expect_select2_selection("Chile") }
250+
on_input_ctx("invoice_region_id") { expect_select2_selection("Metropolitana") }
251+
on_input_ctx("invoice_city_id") { expect_select2_selection("Colina") }
252+
end
253+
254+
context "updating medium level" do
255+
before do
256+
on_input_ctx("invoice_region_id") { open_select2_options }
257+
select2_input.set("a")
258+
end
259+
260+
it "shows no results based on entered text", js: true do
261+
expect_select2_results_count_to_eq(2)
262+
end
263+
end
264+
end
188265

189266
context "with nested resources" do
190267
before do

0 commit comments

Comments
 (0)