mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Rename JS file so that it is loaded after the spree code it is overriding. Admin can't add products outside distribution to an order.
This commit is contained in:
@@ -9,7 +9,11 @@ feature %q{
|
||||
|
||||
background do
|
||||
@user = create(:user)
|
||||
@order = create(:order_with_totals_and_distribution, user: @user, state: 'complete', payment_state: 'balance_due')
|
||||
@product = create(:simple_product)
|
||||
@distributor = create(:distributor_enterprise)
|
||||
@order_cycle = create(:simple_order_cycle, distributors: [@distributor], variants: [@product.master])
|
||||
|
||||
@order = create(:order_with_totals_and_distribution, user: @user, distributor: @distributor, order_cycle: @order_cycle, state: 'complete', payment_state: 'balance_due')
|
||||
|
||||
# ensure order has a payment to capture
|
||||
@order.finalize!
|
||||
@@ -43,6 +47,29 @@ feature %q{
|
||||
o.order_cycle.should == order_cycle
|
||||
end
|
||||
|
||||
scenario "can add a product to an existing order", js: true do
|
||||
login_to_admin_section
|
||||
visit '/admin/orders'
|
||||
page.find('td.actions a.icon-edit').click
|
||||
|
||||
targetted_select2_search @product.name, from: ".variant_autocomplete", dropdown_css: ".select2-search"
|
||||
|
||||
click_icon :plus
|
||||
|
||||
page.should have_selector 'td', text: @product.name
|
||||
@order.line_items(true).map(&:product).should include @product
|
||||
end
|
||||
|
||||
scenario "can't add products to an order outside the order's hub and order cycle", js: true do
|
||||
product = create(:simple_product)
|
||||
|
||||
login_to_admin_section
|
||||
visit '/admin/orders'
|
||||
page.find('td.actions a.icon-edit').click
|
||||
|
||||
page.should_not have_select2_option product.name, from: ".variant_autocomplete", dropdown_css: ".select2-search"
|
||||
end
|
||||
|
||||
scenario "can't change distributor or order cycle once order has been finalized" do
|
||||
@order.update_attributes order_cycle_id: nil
|
||||
|
||||
|
||||
@@ -129,6 +129,15 @@ module WebHelper
|
||||
targetted_select2(value, options)
|
||||
end
|
||||
|
||||
def have_select2_option(value, options)
|
||||
container = options[:dropdown_css] || ".select2-with-searchbox"
|
||||
page.execute_script %Q{$('#{options[:from]}').select2('open')}
|
||||
page.execute_script "$('#{container} input.select2-input').val('#{value}').trigger('keyup-change');"
|
||||
sleep 1
|
||||
have_selector "div.select2-result-label", text: value
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def wait_for_ajax
|
||||
wait_until { page.evaluate_script("$.active") == 0 }
|
||||
|
||||
Reference in New Issue
Block a user