From 32d16eacd2bd45afbae8d4956d1e286ed07aaca7 Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 29 Jul 2022 10:58:29 +0100 Subject: [PATCH] Fix Rubocop Metrics/AbcSize and Layout/LineLength errors in complex_creating_specific_time_spec.rb Not sure if this is correct but it removes the Rubocop violations. --- .../complex_creating_specific_time_spec.rb | 120 +++++++++++------- 1 file changed, 71 insertions(+), 49 deletions(-) diff --git a/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb b/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb index 5c41022952..25ee70aed4 100644 --- a/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb +++ b/spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb @@ -28,7 +28,9 @@ describe ' # And some enterprise fees let!(:supplier_fee) { create(:enterprise_fee, enterprise: supplier, name: 'Supplier fee') } let!(:coordinator_fee) { create(:enterprise_fee, enterprise: coordinator, name: 'Coord fee') } - let!(:distributor_fee) { create(:enterprise_fee, enterprise: distributor, name: 'Distributor fee') } + let!(:distributor_fee) do + create(:enterprise_fee, enterprise: distributor, name: 'Distributor fee') + end before do # Relationships required for interface to work @@ -79,34 +81,26 @@ describe ' end def select_opening_and_closing_times - # If I fill in the basic fields - find('#order_cycle_orders_open_at').click - # select date - select_date_from_datepicker Time.zone.at(order_cycle_opening_time) - # select time - within(".flatpickr-calendar.open .flatpickr-time") do - find('.flatpickr-hour').set('%02d' % order_cycle_opening_time.hour) - find('.flatpickr-minute').set('%02d' % order_cycle_opening_time.min) - end - # hide the datetimepicker - find("body").send_keys(:escape) + select_time("#order_cycle_orders_open_at", order_cycle_opening_time) + select_time("#order_cycle_orders_close_at", order_cycle_opening_time) + end - find('#order_cycle_orders_close_at').click + def select_time(selector, time) + # If I fill in the basic fields + find(selector).click # select date - select_date_from_datepicker Time.zone.at(order_cycle_closing_time) + select_date_from_datepicker Time.zone.at(time) # select time within(".flatpickr-calendar.open .flatpickr-time") do - find('.flatpickr-hour').set('%02d' % order_cycle_closing_time.hour) - find('.flatpickr-minute').set('%02d' % order_cycle_closing_time.min) + find('.flatpickr-hour').set('%02d' % time.hour) + find('.flatpickr-minute').set('%02d' % time.min) end # hide the datetimepicker find("body").send_keys(:escape) end def add_supplier_with_fees - # I should not be able to add a blank supplier - expect(page).to have_select 'new_supplier_id', selected: '' - expect(page).to have_button 'Add supplier', disabled: true + expect_not_able_to_add_blank_supplier # And I add a supplier and some products select 'My supplier', from: 'new_supplier_id' @@ -116,10 +110,7 @@ describe ' check "order_cycle_incoming_exchange_0_variants_#{v1.id}" check "order_cycle_incoming_exchange_0_variants_#{v2.id}" - # I should not be able to re-add the supplier - expect(page).not_to have_select 'new_supplier_id', with_options: ['My supplier'] - expect(page).to have_button 'Add supplier', disabled: true - expect(page.all("td.supplier_name").map(&:text)).to eq(['My supplier']) + expect_not_able_to_readd_supplier('My supplier') # And I add a supplier fee within("tr.supplier-#{supplier.id}") { click_button 'Add fee' } @@ -130,6 +121,17 @@ describe ' click_button 'Save and Next' end + def expect_not_able_to_add_blank_supplier + expect(page).to have_select 'new_supplier_id', selected: '' + expect(page).to have_button 'Add supplier', disabled: true + end + + def expect_not_able_to_readd_supplier(supplier_name) + expect(page).not_to have_select 'new_supplier_id', with_options: [supplier_name] + expect(page).to have_button 'Add supplier', disabled: true + expect(page.all("td.supplier_name").map(&:text)).to eq([supplier_name]) + end + def add_distributor_with_fees # And I add a distributor with the same products select 'My distributor', from: 'new_distributor_id' @@ -168,20 +170,27 @@ describe ' expect(page).to have_unchecked_field "Select all" + expect_checking_select_all_shipping_methods_works + expect_unchecking_select_all_shipping_methods_works + + # Our final selection: + check "Pickup - always available" + click_button 'Save and Back to List' + end + + def expect_checking_select_all_shipping_methods_works # Now test that the "Select all" input is doing what it's supposed to: check "Select all" expect(page).to have_checked_field "Pickup - always available" expect(page).to have_checked_field "Delivery - sometimes available" + end + def expect_unchecking_select_all_shipping_methods_works uncheck "Select all" expect(page).to have_unchecked_field "Pickup - always available" expect(page).to have_unchecked_field "Delivery - sometimes available" - - # Our final selection: - check "Pickup - always available" - click_button 'Save and Back to List' end def expect_all_data_saved @@ -189,34 +198,47 @@ describe ' toggle_columns "Producers", "Shops" expect(page).to have_input "oc#{oc.id}[name]", value: "Plums & Avos" - expect(page).to have_input "oc#{oc.id}[orders_open_at]", - value: Time.zone.at(order_cycle_opening_time), visible: false - expect(page).to have_input "oc#{oc.id}[orders_close_at]", - value: Time.zone.at(order_cycle_closing_time), visible: false expect(page).to have_content "My coordinator" - + expect_opening_and_closing_times_saved expect(page).to have_selector 'td.producers', text: 'My supplier' expect(page).to have_selector 'td.shops', text: 'My distributor' - # And it should have some fees - expect(oc.exchanges.incoming.first.enterprise_fees).to eq([supplier_fee]) - expect(oc.coordinator_fees).to eq([coordinator_fee]) - expect(oc.exchanges.outgoing.first.enterprise_fees).to eq([distributor_fee]) - - # And it should have some variants selected - expect(oc.exchanges.first.variants.count).to eq(2) - expect(oc.exchanges.last.variants.count).to eq(2) - - # And my receival and pickup time and instructions should have been saved - exchange = oc.exchanges.incoming.first - expect(exchange.receival_instructions).to eq('receival instructions') - - exchange = oc.exchanges.outgoing.first - expect(exchange.pickup_time).to eq('pickup time') - expect(exchange.pickup_instructions).to eq('pickup instructions') - expect(exchange.tag_list).to eq(['wholesale']) + expect_fees_saved + expect_variants_saved + expect_receival_instructions_saved + expect_pickup_time_and_instructions_saved # And the shipping method should be attached expect(oc.shipping_methods.map(&:name)).to eq(["Pickup - always available"]) end + + def expect_opening_and_closing_times_saved + expect(page).to have_input "oc#{oc.id}[orders_open_at]", + value: Time.zone.at(order_cycle_opening_time), visible: false + expect(page).to have_input "oc#{oc.id}[orders_close_at]", + value: Time.zone.at(order_cycle_closing_time), visible: false + end + + def expect_fees_saved + expect(oc.exchanges.incoming.first.enterprise_fees).to eq([supplier_fee]) + expect(oc.coordinator_fees).to eq([coordinator_fee]) + expect(oc.exchanges.outgoing.first.enterprise_fees).to eq([distributor_fee]) + end + + def expect_variants_saved + expect(oc.exchanges.first.variants.count).to eq(2) + expect(oc.exchanges.last.variants.count).to eq(2) + end + + def expect_receival_instructions_saved + exchange = oc.exchanges.incoming.first + expect(exchange.receival_instructions).to eq('receival instructions') + end + + def expect_pickup_time_and_instructions_saved + exchange = oc.exchanges.outgoing.first + expect(exchange.pickup_time).to eq('pickup time') + expect(exchange.pickup_instructions).to eq('pickup instructions') + expect(exchange.tag_list).to eq(['wholesale']) + end end