Files
openfoodnetwork/spec/system/admin/customers_spec.rb
Neal Chambers e923defd55 Safely autocorrect Layout/TrailingWhitespace
Inspecting 1479 files
...................................................................................................................................................C..C.......................................................................................................C.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.....C..................C.............................................................................................C...................................................................C.......................................................................................................................................................................C....................................................C.............C...........CC.........C......C.CC.C....................C........................................................

Offenses:

app/controllers/spree/users_controller.rb:36:37: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
            partial("layouts/alert",
                                    ^
app/controllers/spree/users_controller.rb:51:35: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          partial("layouts/alert",
                                  ^
app/controllers/user_confirmations_controller.rb:27:33: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        partial("layouts/alert",
                                ^
app/models/enterprise.rb:117:24: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
  validates :instagram,
                       ^
spec/controllers/spree/credit_cards_controller_spec.rb:250:64: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                  create(:stored_credit_card, user_id: user.id,
                                                               ^
spec/controllers/user_confirmations_controller_spec.rb:45:44: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        session[:confirmation_return_url] =
                                           ^
spec/factories/order_factory.rb:40:67: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
            order.payments << build(:payment, amount: order.total,
                                                                  ^
spec/lib/reports/packing/packing_report_spec.rb:59:40: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        build(:line_item_with_shipment,
                                       ^
spec/lib/reports/packing/packing_report_spec.rb:63:40: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        build(:line_item_with_shipment,
                                       ^
spec/models/enterprise_spec.rb:521:67: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        expect(Enterprise.supplying_variant_in([p1.variants.first,
                                                                  ^
spec/models/enterprise_spec.rb:906:77: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      create(:enterprise_relationship, parent: distributor, child: supplier,
                                                                            ^
spec/services/products_renderer_spec.rb:22:73: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      create(:product, name: "banana bread", primary_taxon_id: cakes.id,
                                                                        ^
spec/services/products_renderer_spec.rb:88:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_apples.product_properties.create!({ property_id: property_organic.id,
                                                                                       ^
spec/services/products_renderer_spec.rb:90:87: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          products_renderer = ProductsRenderer.new(distributor, order_cycle, customer,
                                                                                      ^
spec/services/products_renderer_spec.rb:97:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          fruits_supplier.producer_properties.create!({ property_id: property_organic.id,
                                                                                         ^
spec/services/products_renderer_spec.rb:99:87: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          products_renderer = ProductsRenderer.new(distributor, order_cycle, customer,
                                                                                      ^
spec/services/products_renderer_spec.rb:109:93: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_apples.product_properties.create!({ property_id: property_conventional.id,
                                                                                            ^
spec/services/products_renderer_spec.rb:111:94: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_banana_bread.product_properties.create!({ property_id: property_organic.id,
                                                                                             ^
spec/services/products_renderer_spec.rb:113:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_cherries.product_properties.create!({ property_id: property_organic.id,
                                                                                         ^
spec/services/products_renderer_spec.rb:115:91: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_doughnuts.product_properties.create!({ property_id: property_organic.id,
                                                                                          ^
spec/services/products_renderer_spec.rb:117:87: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          products_renderer = ProductsRenderer.new(distributor, order_cycle, customer,
                                                                                      ^
spec/support/request/stripe_stubs.rb:17:81: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
  def stub_payment_intent_get_request(response: {}, stripe_account_header: true,
                                                                                ^
spec/support/request/stripe_stubs.rb:172:6: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    {
     ^
spec/support/request/stripe_stubs.rb:175:24: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        object: "list",
                       ^
spec/support/request/stripe_stubs.rb:176:25: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        has_more: false,
                        ^
spec/system/admin/bulk_order_management_spec.rb:792:99: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      it "displays only line items whose orders meet the date restriction criteria, when changed",
                                                                                                  ^
spec/system/admin/bulk_order_management_spec.rb:1071:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/bulk_order_management_spec.rb:1121:82: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      shared_examples "display only group by information for selected variant" do
                                                                                 ^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:1143:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/bulk_order_management_spec.rb:1166:12: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        end
           ^
spec/system/admin/customers_spec.rb:18:98: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        create(:customer, first_name: 'John', last_name: 'Doe', enterprise: managed_distributor1,
                                                                                                 ^
spec/system/admin/enterprise_fees_spec.rb:102:37: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Inherit From Product',
                                    ^
spec/system/admin/enterprise_fees_spec.rb:128:38: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Weight (per kg or lb)',
                                     ^
spec/system/admin/enterprise_fees_spec.rb:132:37: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Flat Rate (per item)',
                                    ^
spec/system/admin/enterprise_fees_spec.rb:153:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
spec/system/admin/enterprise_fees_spec.rb:153:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/enterprise_fees_spec.rb:157:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/enterprise_fees_spec.rb:159:38: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Flat Rate (per order)',
                                     ^
spec/system/admin/enterprise_fees_spec.rb:222:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:22:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:27:32: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      find("#admin-menu").click
                               ^^^^^^^
spec/system/admin/flatpickr_spec.rb:32:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:34:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:41:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_cycles/complex_editing_spec.rb:74:33: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    expect(page).to have_select(
                                ^
spec/system/admin/order_cycles/complex_editing_spec.rb:110:33: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    expect(page).to have_select(
                                ^
spec/system/admin/order_cycles/list_spec.rb:147:46: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(find('input.datetimepicker',
                                             ^
spec/system/admin/order_cycles/list_spec.rb:160:46: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(find('input.datetimepicker',
                                             ^
spec/system/admin/order_cycles/list_spec.rb:188:46: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(find('input.datetimepicker',
                                             ^
spec/system/admin/order_cycles/simple_spec.rb:447:43: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        expect(page).not_to have_selector(
                                          ^
spec/system/admin/order_spec.rb:92:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:207:30: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          within(".modal") do
                             ^
spec/system/admin/order_spec.rb:235:21: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      login_as_admin
                    ^^
spec/system/admin/order_spec.rb:240:16: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      before do
               ^
spec/system/admin/order_spec.rb:247:62: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    context "when using the cancel option in the dropdown" do
                                                             ^^
spec/system/admin/order_spec.rb:248:16: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      before do
               ^
spec/system/admin/order_spec.rb:299:53: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        expect(page).to have_content "Are you sure?"
                                                    ^^^^^^^^
spec/system/admin/order_spec.rb:327:36: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        find("a.delete-item").click
                                   ^
spec/system/admin/order_spec.rb:401:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:405:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:598:59: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(page).to have_link "Resend Confirmation",
                                                          ^
spec/system/admin/order_spec.rb:617:52: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(page).to have_link "Cancel Order",
                                                   ^
spec/system/admin/order_spec.rb:633:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:635:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
spec/system/admin/order_spec.rb:635:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:674:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:735:35: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          within "#order-total" do
                                  ^
spec/system/admin/order_spec.rb:762:39: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
              within "#order-total" do
                                      ^
spec/system/admin/order_spec.rb:778:41: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                within "#order-total" do
                                        ^
spec/system/admin/order_spec.rb:780:20: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                end
                   ^^
spec/system/admin/order_spec.rb:796:39: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
              within "#order-total" do
                                      ^
spec/system/admin/order_spec.rb:807:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                # Since the order is completed, the price is not supposed to be updated
                                                                                       ^
spec/system/admin/order_spec.rb:813:41: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                within "#order-total" do
                                        ^
spec/system/admin/order_spec.rb:815:20: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                end
                   ^^
spec/system/admin/order_spec.rb:924:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:959:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:981:16: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      before do
               ^^
spec/system/admin/order_spec.rb:992:8: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    end
       ^^
spec/system/admin/order_spec.rb:1002:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/shipping_methods_spec.rb:50:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/shipping_methods_spec.rb:92:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.

1479 files inspected, 81 offenses detected, 81 offenses corrected
2023-07-27 09:58:33 +10:00

405 lines
15 KiB
Ruby

# frozen_string_literal: true
require 'system_helper'
describe 'Customers' do
include AdminHelper
include AuthenticationHelper
include WebHelper
context "as an enterprise user" do
let(:user) { create(:user, enterprise_limit: 10) }
let(:managed_distributor1) { create(:distributor_enterprise, owner: user) }
let(:managed_distributor2) { create(:distributor_enterprise, owner: user) }
let(:unmanaged_distributor) { create(:distributor_enterprise) }
describe "using the customers index" do
let!(:customer1) {
create(:customer, first_name: 'John', last_name: 'Doe', enterprise: managed_distributor1,
code: nil, created_manually: true)
}
let!(:customer2) {
create(:customer, enterprise: managed_distributor1, created_manually: true, code: nil)
}
let!(:customer3) {
create(:customer, enterprise: unmanaged_distributor, created_manually: true,)
}
let!(:customer4) {
create(:customer, enterprise: managed_distributor2, created_manually: true,)
}
before do
login_as user
visit admin_customers_path
end
it "passes the smoke test" do
# Prompts for a hub for a list of my managed enterprises
expect(page)
.to have_select2 "shop_id", with_options: [managed_distributor1.name,
managed_distributor2.name], without_options: [unmanaged_distributor.name]
select2_select managed_distributor2.name, from: "shop_id"
# Loads the right customers; positive assertion first, so DOM content is loaded
expect(page).to have_selector "tr#c_#{customer4.id}"
expect(page).to have_no_selector "tr#c_#{customer1.id}"
expect(page).to have_no_selector "tr#c_#{customer2.id}"
expect(page).to have_no_selector "tr#c_#{customer3.id}"
# Changing Shops
select2_select managed_distributor1.name, from: "shop_id"
# Loads the right customers
expect(page).to have_selector "tr#c_#{customer1.id}"
expect(page).to have_selector "tr#c_#{customer2.id}"
expect(page).to have_no_selector "tr#c_#{customer3.id}"
expect(page).to have_no_selector "tr#c_#{customer4.id}"
# Searching
fill_in "quick_search", with: customer2.email
expect(page).to have_no_selector "tr#c_#{customer1.id}"
expect(page).to have_selector "tr#c_#{customer2.id}"
fill_in "quick_search", with: ""
# Sorting when the header of a sortable column is clicked
customer_emails = [customer1.email, customer2.email].sort
within "#customers thead" do
click_on "Email"
end
expect(page).to have_selector("#customers .customer:nth-child(1) .email",
text: customer_emails[0])
expect(page).to have_selector("#customers .customer:nth-child(2) .email",
text: customer_emails[1])
# Then sorting in reverse when the header is clicked again
within "#customers thead" do
click_on "Email"
end
expect(page).to have_selector("#customers .customer:nth-child(1) .email",
text: customer_emails[1])
expect(page).to have_selector("#customers .customer:nth-child(2) .email",
text: customer_emails[0])
# Toggling columns
expect(page).to have_selector "th.email"
expect(page).to have_content customer1.email
toggle_columns "Email"
expect(page).to have_no_selector "th.email"
expect(page).to have_no_content customer1.email
# Deleting
create(:subscription, customer: customer1)
expect{
within "tr#c_#{customer1.id}" do
accept_alert do
find("a.delete-customer").click
end
end
expect(page).to have_selector "#info-dialog .text",
text: 'Delete failed: This customer has ' \
'active subscriptions. Cancel them first.'
click_button "OK"
}.to_not change{ Customer.count }
expect{
within "tr#c_#{customer2.id}" do
accept_alert do
find("a.delete-customer").click
end
end
expect(page).to have_no_selector "tr#c_#{customer2.id}"
}.to change{ Customer.count }.by(-1)
end
describe "for a shop with multiple customers" do
let!(:order1) {
create(:order, total: 0, payment_total: 88, distributor: managed_distributor1, user: nil,
state: 'complete', customer: customer1)
}
let!(:order2) {
create(:order, total: 99, payment_total: 0, distributor: managed_distributor1, user: nil,
state: 'complete', customer: customer2)
}
let!(:order3) {
create(:order, total: 0, payment_total: 0, distributor: managed_distributor1, user: nil,
state: 'complete', customer: customer4)
}
let!(:payment_method) {
create(:stripe_sca_payment_method, distributors: [managed_distributor1])
}
let!(:payment1) {
create(:payment, :completed, order: order1, payment_method: payment_method,
response_code: 'pi_123', amount: 88.00)
}
before do
customer4.update enterprise: managed_distributor1
end
context "with one payment only" do
it "displays customer balances" do
select2_select managed_distributor1.name, from: "shop_id"
within "tr#c_#{customer1.id}" do
expect(page).to have_content "CREDIT OWED"
expect(page).to have_content "$88.00"
end
within "tr#c_#{customer2.id}" do
expect(page).to have_content "BALANCE DUE"
expect(page).to have_content "$-99.00"
end
within "tr#c_#{customer4.id}" do
expect(page).to_not have_content "CREDIT OWED"
expect(page).to_not have_content "BALANCE DUE"
expect(page).to have_content "$0.00"
end
end
end
context "with an additional negative payment (or refund)" do
let!(:payment2) {
create(:payment, :completed, order: order1, payment_method: payment_method,
response_code: 'pi_123', amount: -25.00)
}
before do
order1.user = user
order1.save!
end
it "displays an updated customer balance" do
visit spree.admin_order_payments_path order1
expect(page).to have_content "$#{payment2.amount}"
visit admin_customers_path
select2_select managed_distributor1.name, from: "shop_id"
within "tr#c_#{customer1.id}" do
expect(page).to have_content "CREDIT OWED"
expect(page).to have_content "$63.00"
end
end
end
end
it "allows updating of attributes" do
select2_select managed_distributor1.name, from: "shop_id"
within "tr#c_#{customer1.id}" do
expect(find_field('first_name').value).to eq 'John'
expect(find_field('last_name').value).to eq 'Doe'
fill_in "code", with: "new-customer-code"
expect(page).to have_css "input[name=code].update-pending"
fill_in "first_name", with: "customer abc"
expect(page).to have_css "input[name=first_name].update-pending"
find(:css, "tags-input .tags input").set "awesome\n"
expect(page).to have_css ".tag_watcher.update-pending"
end
expect(page).to have_content 'You have unsaved changes'
click_button "Save Changes"
# Every says it updated
expect(page).to have_css "input[name=code].update-success"
expect(page).to have_css "input[name=first_name].update-success"
expect(page).to have_css ".tag_watcher.update-success"
# And it actually did
expect(customer1.reload.code).to eq "new-customer-code"
expect(customer1.reload.first_name).to eq "customer abc"
expect(customer1.tag_list).to eq ["awesome"]
# Clearing attributes
within "tr#c_#{customer1.id}" do
fill_in "code", with: ""
expect(page).to have_css "input[name=code].update-pending"
fill_in "first_name", with: ""
expect(page).to have_css "input[name=first_name].update-pending"
find("tags-input li.tag-item a.remove-button").click
expect(page).to have_css ".tag_watcher.update-pending"
end
click_button "Save Changes"
# Every says it updated
expect(page).to have_css "input[name=code].update-success"
expect(page).to have_css "input[name=first_name].update-success"
expect(page).to have_css ".tag_watcher.update-success"
# And it actually did
expect(customer1.reload.code).to be nil
expect(customer1.reload.first_name).to eq ''
expect(customer1.tag_list).to eq []
end
it "prevents duplicate codes from being saved" do
select2_select managed_distributor1.name, from: "shop_id"
within "tr#c_#{customer1.id}" do
fill_in "code", with: "new-customer-code"
expect(page).to have_css "input[name=code].update-pending"
end
click_button "Save Changes"
within "tr#c_#{customer1.id}" do
expect(page).to have_css "input[name=code].update-success"
end
within "tr#c_#{customer2.id}" do
fill_in "code", with: "new-customer-code"
expect(page).to have_content "This code is used already."
end
click_button "Save Changes"
within "tr#c_#{customer2.id}" do
expect(page).to have_css "input[name=code].update-error"
end
expect(page).to have_content "Oh no! I was unable to save your changes"
expect(customer1.reload.code).to eq "new-customer-code"
expect(customer2.reload.code).to be nil
end
describe 'updating a customer addresses' do
before do
select2_select managed_distributor2.name, from: "shop_id"
end
it 'updates the existing billing address' do
expect(page).to have_content 'BILLING ADDRESS'
first('#bill-address-link').click
wait_for_modal_fade_in
expect(page).to have_content 'Edit Billing Address'
expect(page).to have_select2 'country_id', selected: 'Australia'
expect(page).to have_select2 'state_id', selected: 'Victoria'
fill_in 'address1', with: ""
click_button 'Update Address'
expect(page).to have_content 'Please input all of the required fields'
fill_in 'address1', with: "New Address1"
click_button 'Update Address'
expect(page).to have_content 'Address updated successfully.'
expect(page).to have_link 'New Address1'
expect(customer4.reload.bill_address.address1).to eq 'New Address1'
first('#bill-address-link').click
expect(page).to have_content 'Edit Billing Address'
expect(page).to_not have_content 'Please input all of the required fields'
end
it 'creates a new shipping address' do
expect(page).to have_content 'SHIPPING ADDRESS'
first('#ship-address-link').click
wait_for_modal_fade_in
expect(page).to have_content 'Edit Shipping Address'
fill_in 'firstname', with: "First"
fill_in 'lastname', with: "Last"
fill_in 'address1', with: "New Address1"
fill_in 'phone', with: "12345678"
fill_in 'city', with: "Melbourne"
fill_in 'zipcode', with: "3000"
select2_select 'Australia', from: 'country_id'
select2_select 'Victoria', from: 'state_id'
click_button 'Update Address'
expect(page).to have_content 'Address updated successfully.'
expect(page).to have_link 'New Address1'
ship_address = customer4.reload.ship_address
expect(ship_address.firstname).to eq 'First'
expect(ship_address.lastname).to eq 'Last'
expect(ship_address.address1).to eq 'New Address1'
expect(ship_address.phone).to eq '12345678'
expect(ship_address.city).to eq 'Melbourne'
end
# Modal animations are defined in:
# app/assets/javascripts/admin/utils/services/dialog_defaults.js.coffee
#
# Without waiting, `fill_in` can fail randomly:
# https://github.com/teamcapybara/capybara/issues/1890
def wait_for_modal_fade_in(time = 0.4)
sleep time
end
end
describe "creating a new customer" do
context "when no shop has been selected" do
it "asks the user to select a shop" do
accept_alert 'Please select a shop first' do
click_link('New Customer')
end
end
end
context "when a shop is selected" do
before do
select2_select managed_distributor1.name, from: "shop_id"
customer1.update!(created_manually: false)
end
it "creates customers when the email provided is valid" do
# When an invalid email without domain is used it is checked by a regex, in the UI
expect{
click_link('New Customer')
fill_in 'email', with: "email_with_no_domain@"
click_button 'Add Customer'
expect(page).to have_selector "#new-customer-dialog .error",
text: "Please enter a valid email address"
}.to_not change{ Customer.of(managed_distributor1).count }
# When an invalid email with domain is used it's checked by "valid_email2" gem #7886
expect{
fill_in 'email', with: "invalid_email_with_no_complete_domain@incomplete"
click_button 'Add Customer'
expect(page).to have_selector "#new-customer-dialog .error",
text: "Email is invalid"
}.to_not change{ Customer.of(managed_distributor1).count }
# When a new valid email is used
expect{
fill_in 'email', with: "new@email.com"
click_button 'Add Customer'
expect(page).not_to have_selector "#new-customer-dialog"
}.to change{ Customer.of(managed_distributor1).count }.from(2).to(3)
end
it "shows a hidden customer when trying to create it" do
click_link('New Customer')
fill_in 'email', with: customer1.email
expect do
click_button 'Add Customer'
expect(page).not_to have_selector "#new-customer-dialog"
customer1.reload
end
.to change { customer1.created_manually }.from(false).to(true)
.and change { Customer.count }.by(0)
expect(page).to have_content customer1.email
expect(page).to have_field "first_name", with: "John"
expect(page).to have_field "last_name", with: "Doe"
end
end
end
end
end
end