|
| 1 | +require 'rails_helper' |
| 2 | +require_relative "../../support/form_test_controller" |
| 3 | + |
| 4 | +RSpec.describe "Bootstrap::Form::Textarea", type: :feature, js: true do |
| 5 | + include Utils |
| 6 | + |
| 7 | + before :all do |
| 8 | + Rails.application.routes.append do |
| 9 | + scope "form_text_input_spec" do |
| 10 | + post '/textarea_success_form_test', to: 'form_test#success_submit', as: 'textarea_success_form_test' |
| 11 | + post '/textarea_failure_form_test', to: 'form_test#failure_submit', as: 'textarea_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 'renders basic bootstrap textarea field' do |
| 22 | + form_config = get_form_config(path: textarea_success_form_test_path) |
| 23 | + matestack_render do |
| 24 | + matestack_form form_config do |
| 25 | + bs_form_textarea key: :foo, type: :text |
| 26 | + bs_form_submit text: "Submit" |
| 27 | + end |
| 28 | + end |
| 29 | + visit example_path |
| 30 | + expect(page).to have_selector('form > div.matestack-ui-bootstrap-textarea > textarea.form-control#foo') |
| 31 | + |
| 32 | + fill_in "foo", with: "bar" |
| 33 | + |
| 34 | + expect_any_instance_of(FormTestController).to receive(:expect_params) |
| 35 | + .with(hash_including(wrapper: { foo: "bar" })) |
| 36 | + |
| 37 | + click_button "Submit" |
| 38 | + end |
| 39 | + |
| 40 | + it 'renders basic bootstrap textarea field with server errors' do |
| 41 | + form_config = get_form_config(path: textarea_failure_form_test_path) |
| 42 | + matestack_render do |
| 43 | + matestack_form form_config do |
| 44 | + bs_form_textarea key: :foo, type: :text |
| 45 | + bs_form_submit text: "Submit" |
| 46 | + end |
| 47 | + end |
| 48 | + visit example_path |
| 49 | + |
| 50 | + click_button "Submit" |
| 51 | + |
| 52 | + expect(page).to have_xpath('//form//textarea[@id="foo" and contains(@class, "form-control") and contains(@class, "is-invalid")]') |
| 53 | + |
| 54 | + expect(page).to have_xpath('//form//div[contains(@class, "invalid-feedback") and contains(text(), "can\'t be blank")]') |
| 55 | + expect(page).to have_xpath('//form//div[contains(@class, "invalid-feedback") and contains(text(), "is invalid")]') |
| 56 | + end |
| 57 | + |
| 58 | + it 'renders basic bootstrap textarea field with additional custom class' do |
| 59 | + form_config = get_form_config(path: textarea_success_form_test_path) |
| 60 | + matestack_render do |
| 61 | + matestack_form form_config do |
| 62 | + bs_form_textarea key: :foo, type: :text, class: "some-class" |
| 63 | + bs_form_submit text: "Submit" |
| 64 | + end |
| 65 | + end |
| 66 | + visit example_path |
| 67 | + expect(page).to have_xpath('//form//textarea[@id="foo" and contains(@class, "form-control") and contains(@class, "some-class")]') |
| 68 | + end |
| 69 | + |
| 70 | + it 'renders basic bootstrap textarea field with label' do |
| 71 | + form_config = get_form_config(path: textarea_success_form_test_path) |
| 72 | + matestack_render do |
| 73 | + matestack_form form_config do |
| 74 | + bs_form_textarea key: :foo, type: :text, label: "Some label" |
| 75 | + bs_form_submit text: "Submit" |
| 76 | + end |
| 77 | + end |
| 78 | + visit example_path |
| 79 | + expect(page).to have_xpath('//form//label[@for="foo" and @class="form-label" and contains(text(), "Some label")]') |
| 80 | + end |
| 81 | + |
| 82 | + it 'renders basic bootstrap textarea field with placeholder' do |
| 83 | + form_config = get_form_config(path: textarea_success_form_test_path) |
| 84 | + matestack_render do |
| 85 | + matestack_form form_config do |
| 86 | + bs_form_textarea key: :foo, type: :text, placeholder: "fill!" |
| 87 | + bs_form_submit text: "Submit" |
| 88 | + end |
| 89 | + end |
| 90 | + visit example_path |
| 91 | + expect(page).to have_xpath('//form//textarea[@id="foo" and @placeholder="fill!" and contains(@class, "form-control")]') |
| 92 | + end |
| 93 | + |
| 94 | + it 'renders basic bootstrap textarea field with form text' do |
| 95 | + form_config = get_form_config(path: textarea_success_form_test_path) |
| 96 | + matestack_render do |
| 97 | + matestack_form form_config do |
| 98 | + bs_form_textarea key: :foo, type: :text, form_text: "some notes" |
| 99 | + bs_form_submit text: "Submit" |
| 100 | + end |
| 101 | + end |
| 102 | + visit example_path |
| 103 | + expect(page).to have_xpath('//form//div[@id="form_text_for_foo" and contains(@class, "form-text") and contains(text(), "some notes")]') |
| 104 | + end |
| 105 | + |
| 106 | + it 'renders basic bootstrap textarea field with form rows and cols' do |
| 107 | + form_config = get_form_config(path: textarea_success_form_test_path) |
| 108 | + matestack_render do |
| 109 | + matestack_form form_config do |
| 110 | + bs_form_textarea key: :foo1, id: :foo1, type: :text, rows: 3, cols: 10 |
| 111 | + bs_form_textarea key: :foo2, id: :foo2, type: :text, rows: 10, cols: 30 |
| 112 | + bs_form_submit text: "Submit" |
| 113 | + end |
| 114 | + end |
| 115 | + visit example_path |
| 116 | + expect(page.find('textarea#foo1')['rows']).to eq '3' |
| 117 | + expect(page.find('textarea#foo1')['cols']).to eq '10' |
| 118 | + expect(page.find('textarea#foo2')['rows']).to eq '10' |
| 119 | + expect(page.find('textarea#foo2')['cols']).to eq '30' |
| 120 | + end |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +end |
0 commit comments