Hide address form fields when adding/editing contact in registrar area

#290
This commit is contained in:
Artur Beljajev 2017-01-02 13:02:50 +02:00
parent 9a152b8289
commit 878748836f
4 changed files with 54 additions and 65 deletions

View file

@ -0,0 +1,38 @@
require 'rails_helper'
RSpec.describe 'registrar/contacts/_form' do
let(:contact) { instance_spy(Depp::Contact) }
before :example do
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {}))
assign(:contact, contact)
stub_template 'registrar/shared/_error_messages' => ''
stub_template 'registrar/contacts/form_partials/_general' => ''
stub_template 'registrar/contacts/form_partials/_address' => 'address info'
stub_template 'registrar/contacts/form_partials/_code' => ''
stub_template 'registrar/contacts/form_partials/_legal_document' => ''
end
context 'when address processing is enabled' do
before do
allow(view).to receive(:address_processing?).and_return(true)
end
it 'has address' do
render
expect(rendered).to have_text('address info')
end
end
context 'when address processing is disabled' do
before do
allow(view).to receive(:address_processing?).and_return(false)
end
it 'has no address' do
render
expect(rendered).to_not have_text('address info')
end
end
end

View file

@ -1,51 +0,0 @@
require 'rails_helper'
module RequiredAddressFieldsHelper
def define_field_examples(attr_name)
describe "#{attr_name} field" do
let(:field) { page.find("[name='depp_contact[#{attr_name}]']") }
context 'when address processing is enabled' do
before do
allow(view).to receive(:address_processing?).and_return(true)
end
it 'is required' do
render
expect(field[:required]).to eq('required')
end
end
context 'when address processing is disabled' do
before do
allow(view).to receive(:address_processing?).and_return(false)
end
it 'is optional' do
render
expect(field[:required]).to be_nil
end
end
end
end
end
RSpec.describe 'registrar/contacts/form_partials/_address' do
extend RequiredAddressFieldsHelper
let(:contact) { instance_spy(Depp::Contact) }
before do
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:depp_contact, contact, view, {}))
end
required_address_attributes = %i(
street
city
zip
country_code
)
required_address_attributes.each do |attr_name|
define_field_examples(attr_name)
end
end