diff --git a/app/views/properties/_overview_fields.html.erb b/app/views/properties/_overview_fields.html.erb index 7f7201d7d..c3fd55f34 100644 --- a/app/views/properties/_overview_fields.html.erb +++ b/app/views/properties/_overview_fields.html.erb @@ -6,13 +6,14 @@ placeholder: "Vacation home", required: true %> - <%= form.select :subtype, - Property::SUBTYPES.map { |k, v| [v[:long], k] }, - { prompt: "Select type", label: "Property type" }, required: true %> - + <%= form.hidden_field :accountable_type, value: "Property" %> <%= form.fields_for :accountable do |property_form| %> + <%= property_form.select :subtype, + Property::SUBTYPES.map { |k, v| [v[:long], k] }, + { prompt: "Select type", label: "Property type" }, required: true %> +
<%= property_form.number_field :year_built, label: "Year Built (optional)", diff --git a/test/fixtures/properties.yml b/test/fixtures/properties.yml index c330c7f3b..94f4ad6c3 100644 --- a/test/fixtures/properties.yml +++ b/test/fixtures/properties.yml @@ -1,4 +1,10 @@ one: year_built: 2002 area_value: 1000 - area_unit: "sqft" \ No newline at end of file + area_unit: "sqft" + +primary_residence: + id: c506b873-dd1b-4136-8564-02367303946a + subtype: Single Family Home + created_at: <%= Time.current %> + updated_at: <%= Time.current %> diff --git a/test/system/property_test.rb b/test/system/property_test.rb new file mode 100644 index 000000000..769c338f4 --- /dev/null +++ b/test/system/property_test.rb @@ -0,0 +1,69 @@ +require "application_system_test_case" + +class PropertiesEditTest < ApplicationSystemTestCase + setup do + sign_in @user = users(:family_admin) + + Family.any_instance.stubs(:get_link_token).returns("test-link-token") + + visit root_url + open_new_account_modal + create_new_property_account + end + + test "can persist property subtype" do + click_link "[system test] Property Account" + find("[data-testid='account-menu']").click + click_on "Edit" + assert_selector "#account_accountable_attributes_subtype" + assert_selector( + "#account_accountable_attributes_subtype option[selected]", + text: "Single Family Home" + ) + end + + private + + def open_new_account_modal + within "[data-controller='DS--tabs']" do + click_button "All" + click_link "New account" + end + end + + def create_new_property_account + click_link "Property" + + account_name = "[system test] Property Account" + fill_in "Name*", with: account_name + select "Single Family Home", from: "Property type*" + fill_in "Year Built (optional)", with: 2005 + fill_in "Area (optional)", with: 2250 + + click_button "Next" + + # Step 2: Enter balance information + assert_text "Value" + fill_in "account[balance]", with: 500000 + click_button "Next" + + # Step 3: Enter address information + assert_text "Address" + fill_in "Address Line 1", with: "123 Main St" + fill_in "City", with: "San Francisco" + fill_in "State/Region", with: "CA" + fill_in "Postal Code", with: "94101" + fill_in "Country", with: "US" + + click_button "Save" + + # Verify account was created and is now active + assert_text account_name + + created_account = Account.order(:created_at).last + assert_equal "active", created_account.status + assert_equal 500000, created_account.balance + assert_equal "123 Main St", created_account.property.address.line1 + assert_equal "San Francisco", created_account.property.address.locality + end +end