|
185 | 185 | end
|
186 | 186 | end
|
187 | 187 | end
|
| 188 | + context "with filters" 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" 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: { attribute: :region_id }, |
| 237 | + level_3: { attribute: :city_id } |
| 238 | + end |
| 239 | + |
| 240 | + create_cities |
| 241 | + create_invoice(city: @colina) |
| 242 | + visit edit_admin_invoice_path(@invoice) |
| 243 | + end |
| 244 | + |
| 245 | + it "shows filled select controls based on defined city_id", js: true do |
| 246 | + on_input_ctx("invoice_country_id") { expect_select2_selection("Chile") } |
| 247 | + on_input_ctx("invoice_region_id") { expect_select2_selection("Metropolitana") } |
| 248 | + on_input_ctx("invoice_city_id") { expect_select2_selection("Colina") } |
| 249 | + end |
| 250 | + |
| 251 | + context "updating medium level" do |
| 252 | + before do |
| 253 | + on_input_ctx("invoice_region_id") { open_select2_options } |
| 254 | + select2_input.set("a") |
| 255 | + end |
| 256 | + |
| 257 | + it "shows no results based on entered text", js: true do |
| 258 | + expect_select2_results_count_to_eq(2) |
| 259 | + end |
| 260 | + end |
| 261 | + end |
188 | 262 |
|
189 | 263 | context "with nested resources" do
|
190 | 264 | before do
|
|
0 commit comments