|
| 1 | +require 'rails_helper' |
| 2 | +require_relative "../../support/form_test_controller" |
| 3 | + |
| 4 | +RSpec.describe "Nested Form Support Spec", type: :feature, js: true do |
| 5 | + include Utils |
| 6 | + |
| 7 | + before :all do |
| 8 | + Rails.application.routes.append do |
| 9 | + scope "nested_form_support_spec" do |
| 10 | + post '/input_success_form_test', to: 'form_test#success_submit', as: 'input_success_form_test' |
| 11 | + post '/input_failure_form_test', to: 'form_test#failure_submit', as: 'input_failure_form_test' |
| 12 | + end |
| 13 | + end |
| 14 | + Rails.application.reload_routes! |
| 15 | + end |
| 16 | + |
| 17 | + before :each do |
| 18 | + allow_any_instance_of(FormTestController).to receive(:expect_params) |
| 19 | + end |
| 20 | + |
| 21 | + it 'properly renders all input components with dynamically adjusted IDs' do |
| 22 | + form_config = get_form_config(path: input_success_form_test_path) |
| 23 | + |
| 24 | + ExamplePage.define_method(:order_item_form) do |order_item = OrderItem.new| |
| 25 | + form_fields_for order_item, key: :order_items_attributes do |
| 26 | + |
| 27 | + bs_form_input key: :a, type: :number, label: "Label A" |
| 28 | + bs_form_select key: :b, options: [1, 2], label: "Label B" |
| 29 | + bs_form_switch key: :c, options: [1, 2], label: "Label C" |
| 30 | + bs_form_switch key: :d, label: "Label D" |
| 31 | + bs_form_radio key: :e, options: [1, 2], label: "Label E" |
| 32 | + bs_form_textarea key: :f, type: :number, label: "Label F" |
| 33 | + bs_form_checkbox key: :g, label: "Label G" |
| 34 | + bs_form_checkbox key: :h, options: [1, 2], label: "Label H" |
| 35 | + |
| 36 | + form_fields_for_remove_item do |
| 37 | + bs_btn type: :button, variant: :danger do |
| 38 | + bs_icon name: "trash" |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + matestack_render do |
| 45 | + matestack_form form_config do |
| 46 | + |
| 47 | + form_fields_for_add_item key: :order_items_attributes, prototype: method(:order_item_form) do |
| 48 | + bs_btn "add", type: :button, variant: :primary, outline: true, class: "mt-2" |
| 49 | + end |
| 50 | + |
| 51 | + bs_form_submit text: "Submit" |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + visit example_path |
| 56 | + |
| 57 | + click_on "add" |
| 58 | + click_on "add" |
| 59 | + |
| 60 | + [0, 1].each do |i| |
| 61 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-input > label[for=\"a_order_items_attributes_child_#{i}\"]") |
| 62 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-input > input.form-control#a_order_items_attributes_child_#{i}") |
| 63 | + |
| 64 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-form-select > label[for=\"b_order_items_attributes_child_#{i}\"]") |
| 65 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-form-select > select.form-select#b_order_items_attributes_child_#{i}") |
| 66 | + |
| 67 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-switch > label[for=\"c_order_items_attributes_child_#{i}\"]") |
| 68 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-switch > div.form-switch > input.form-check-input#c_order_items_attributes_child_#{i}_1") |
| 69 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-switch > div.form-switch > input.form-check-input#c_order_items_attributes_child_#{i}_2") |
| 70 | + |
| 71 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-switch > div.form-switch > input.form-check-input#d_order_items_attributes_child_#{i}_1") |
| 72 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-switch > div.form-switch > label[for=\"d_order_items_attributes_child_#{i}_1\"]") |
| 73 | + |
| 74 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-radio > label[for=\"e_order_items_attributes_child_#{i}\"]") |
| 75 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-radio > div.form-check > input.form-check-input#e_order_items_attributes_child_#{i}_1") |
| 76 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-radio > div.form-check > label[for=\"e_order_items_attributes_child_#{i}_1\"]") |
| 77 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-radio > div.form-check > input.form-check-input#e_order_items_attributes_child_#{i}_2") |
| 78 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-radio > div.form-check > label[for=\"e_order_items_attributes_child_#{i}_2\"]") |
| 79 | + |
| 80 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-textarea > label[for=\"f_order_items_attributes_child_#{i}\"]") |
| 81 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-textarea > textarea.form-control#f_order_items_attributes_child_#{i}") |
| 82 | + |
| 83 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-form-checkbox > div.form-check > input.form-check-input#g_order_items_attributes_child_#{i}_1") |
| 84 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-form-checkbox > div.form-check > label[for=\"g_order_items_attributes_child_#{i}_1\"]") |
| 85 | + |
| 86 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-form-checkbox > label[for=\"h_order_items_attributes_child_#{i}\"]") |
| 87 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-form-checkbox > div.form-check > input.form-check-input#h_order_items_attributes_child_#{i}_1") |
| 88 | + expect(page).to have_selector("form > div > div.matestack-form-fields-for#order_items_attributes_child_#{i} > div.matestack-ui-bootstrap-form-checkbox > div.form-check > input.form-check-input#h_order_items_attributes_child_#{i}_2") |
| 89 | + end |
| 90 | + |
| 91 | + end |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +end |
0 commit comments