|
| 1 | +require_relative "../../../support/utils" |
| 2 | +require_relative "../../../support/test_controller" |
| 3 | +require_relative "support/form_test_controller" |
| 4 | +require_relative "support/model_form_test_controller" |
| 5 | +include Utils |
| 6 | + |
| 7 | +describe "Form Component", type: :feature, js: true do |
| 8 | + |
| 9 | + before :all do |
| 10 | + class EmitFormTestController < FormTestController |
| 11 | + def success_submit |
| 12 | + render json: { message: "server says: form submitted successfully" }, status: 200 |
| 13 | + end |
| 14 | + end |
| 15 | + |
| 16 | + Rails.application.routes.prepend do |
| 17 | + post '/data_access_form_test', to: 'emit_form_test#success_submit', as: 'form_data_access_submit' |
| 18 | + end |
| 19 | + Rails.application.reload_routes! |
| 20 | + end |
| 21 | + |
| 22 | + before :each do |
| 23 | + allow_any_instance_of(EmitFormTestController).to receive(:expect_params) |
| 24 | + end |
| 25 | + |
| 26 | + describe "data is accessable within form without component in pure Vue.js" do |
| 27 | + |
| 28 | + it "if set, emits event directly when form is submitted (not waiting for success or failure)" do |
| 29 | + class ExamplePage < Matestack::Ui::Page |
| 30 | + def response |
| 31 | + matestack_form form_config do |
| 32 | + plain "{{ data }}" |
| 33 | + form_input key: :foo_input, type: :text, id: "foo-input" |
| 34 | + form_textarea key: :foo_textarea, type: :text, id: "foo-textarea" |
| 35 | + form_select key: :foo_select, options: [1, 2, 3], id: "foo-select", init: 2 |
| 36 | + form_checkbox key: :foo_single_checkbox, id: "foo-single-checkbox" |
| 37 | + form_checkbox key: :foo_multi_checkbox, options: [1, 2, 3], id: "foo-multi-checkbox" |
| 38 | + form_radio key: :foo_radio, options: [1, 2, 3], id: "foo-radio-checkbox" |
| 39 | + button 'Submit me!' |
| 40 | + end |
| 41 | + toggle show_on: "form_submitted", id: 'async-form' do |
| 42 | + plain "form submitted!" |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + def form_config |
| 47 | + return { |
| 48 | + for: :my_object, |
| 49 | + method: :post, |
| 50 | + path: form_data_access_submit_path, |
| 51 | + emit: "form_submitted" |
| 52 | + } |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + visit '/example' |
| 57 | + |
| 58 | + expect(page).to have_content('{ "foo_input": null, "foo_textarea": null, "foo_single_checkbox": null, "foo_multi_checkbox": [], "foo_radio": null, "foo_select": 2 }') |
| 59 | + |
| 60 | + fill_in "foo-input", with: "1" |
| 61 | + fill_in "foo-textarea", with: "2" |
| 62 | + select "3", from: "foo-select" |
| 63 | + check "foo-single-checkbox_1" |
| 64 | + check "foo-multi-checkbox_1" |
| 65 | + check "foo-multi-checkbox_2" |
| 66 | + choose "foo-radio-checkbox_3" |
| 67 | + |
| 68 | + expect(page).to have_content('{ "foo_input": "1", "foo_textarea": "2", "foo_single_checkbox": true, "foo_multi_checkbox": [ 1, 2 ], "foo_radio": 3, "foo_select": 3 }') |
| 69 | + |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | +end |
0 commit comments