DRY specs with new helper

This commit is contained in:
Maikel Linke
2019-01-11 17:14:46 +11:00
parent 4920782742
commit cbdda54989
8 changed files with 40 additions and 71 deletions

View File

@@ -4,6 +4,7 @@ feature %q{
As an Administrator
I want to be able to manage orders in bulk
} , js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -189,11 +190,7 @@ feature %q{
context "modifying the weight/volume of a line item" do
it "price is altered" do
visit '/admin/orders/bulk_management'
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Weight/Volume").click
find("div#columns-dropdown div.menu div.menu_item", text: "Price").click
# hide dropdown
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Weight/Volume", "Price"
within "tr#li_#{li1.id}" do
expect(page).to have_field "price", with: "50.00"
fill_in "final_weight_volume", :with => 2000
@@ -210,9 +207,7 @@ feature %q{
context "modifying the quantity of a line item" do
it "price is altered" do
visit '/admin/orders/bulk_management'
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Price").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Price"
within "tr#li_#{li1.id}" do
expect(page).to have_field "price", with: "#{format("%.2f",li1.price * 5)}"
fill_in "quantity", :with => 6
@@ -224,9 +219,7 @@ feature %q{
context "modifying the quantity of a line item" do
it "weight/volume is altered" do
visit '/admin/orders/bulk_management'
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Weight/Volume").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Weight/Volume"
within "tr#li_#{li1.id}" do
expect(page).to have_field "final_weight_volume", with: "#{li1.final_weight_volume.round}"
fill_in "quantity", :with => 6
@@ -246,9 +239,7 @@ feature %q{
expect(page).to have_selector "th", :text => "QUANTITY"
expect(page).to have_selector "th", :text => "MAX"
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Producer").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Producer"
expect(page).to have_no_selector "th", :text => "PRODUCER"
expect(page).to have_selector "th", :text => "NAME"

View File

@@ -4,6 +4,7 @@ feature %q{
As an Administrator
I want to be able to manage products in bulk
} , js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -46,9 +47,7 @@ feature %q{
p2 = FactoryBot.create(:product, available_on: Date.current-1)
visit spree.admin_products_path
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Available On").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Available On"
expect(page).to have_field "available_on", with: p1.available_on.strftime("%F %T")
expect(page).to have_field "available_on", with: p2.available_on.strftime("%F %T")
@@ -246,12 +245,7 @@ feature %q{
quick_login_as_admin
visit spree.admin_products_path
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Available On").click
find("div#columns-dropdown div.menu div.menu_item", text: /^Category?/).click
find("div#columns-dropdown div.menu div.menu_item", text: "Inherits Properties?").click
find("div#columns-dropdown div.menu div.menu_item", text: "SKU").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Available On", /^Category?/, "Inherits Properties?", "SKU"
within "tr#p_#{p.id}" do
expect(page).to have_field "product_name", with: p.name
@@ -318,9 +312,7 @@ feature %q{
expect(page).to have_selector "a.view-variants", count: 1
find("a.view-variants").trigger('click')
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "SKU").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "SKU"
expect(page).to have_field "variant_sku", with: "VARIANTSKU"
expect(page).to have_field "variant_price", with: "3.0"
@@ -566,9 +558,7 @@ feature %q{
visit spree.admin_products_path
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Available On").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Available On"
expect(page).to have_selector "th", :text => "NAME"
expect(page).to have_selector "th", :text => "PRODUCER"
@@ -576,9 +566,7 @@ feature %q{
expect(page).to have_selector "th", :text => "ON HAND"
expect(page).to have_selector "th", :text => "AV. ON"
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: /^.{0,1}Producer$/).click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns /^.{0,1}Producer$/
expect(page).to have_no_selector "th", :text => "PRODUCER"
expect(page).to have_selector "th", :text => "NAME"
@@ -701,9 +689,7 @@ feature %q{
v = p.variants.first
visit spree.admin_products_path
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Available On").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Available On"
within "tr#p_#{p.id}" do
expect(page).to have_field "product_name", with: p.name

View File

@@ -1,6 +1,7 @@
require 'spec_helper'
feature 'Customers' do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -66,8 +67,7 @@ feature 'Customers' do
# Toggling columns
expect(page).to have_selector "th.email"
expect(page).to have_content customer1.email
first("div#columns-dropdown", :text => "COLUMNS").click
first("div#columns-dropdown div.menu div.menu_item", text: "Email").click
toggle_columns "Email"
expect(page).to have_no_selector "th.email"
expect(page).to have_no_content customer1.email

View File

@@ -4,6 +4,7 @@ feature %q{
As an administrator
I want to manage order cycles
}, js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -45,10 +46,7 @@ feature %q{
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc5.id}.closed"
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc6.id}.closed"
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Producers").click
find("div#columns-dropdown div.menu div.menu_item", text: "Shops").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Producers", "Shops"
# And I should see all the details for an order cycle
within('table#listing_order_cycles tbody tr:nth-child(2)') do
@@ -245,10 +243,7 @@ feature %q{
oc = OrderCycle.last
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Producers").click
find("div#columns-dropdown div.menu div.menu_item", text: "Shops").click
find("div#columns-dropdown", :text => "COLUMNS").click
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: order_cycle_opening_time
@@ -388,10 +383,7 @@ feature %q{
oc = OrderCycle.last
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Producers").click
find("div#columns-dropdown div.menu div.menu_item", text: "Shops").click
find("div#columns-dropdown", :text => "COLUMNS").click
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: order_cycle_opening_time
@@ -705,10 +697,7 @@ feature %q{
expect(page).to have_selector "tr.order-cycle-#{oc_user_coordinating.id}"
expect(page).to_not have_selector "tr.order-cycle-#{oc_for_other_user.id}"
find("div#columns-dropdown", :text => "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Producers").click
find("div#columns-dropdown div.menu div.menu_item", text: "Shops").click
find("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Producers", "Shops"
# The order cycle should show all enterprises in the order cycle
page.should have_selector 'td.producers', text: supplier_managed.name

View File

@@ -2,6 +2,7 @@ require 'spec_helper'
require 'open_food_network/permissions'
feature "Product Import", js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -156,9 +157,7 @@ feature "Product Import", js: true do
expect(page).to have_field "product_name", with: carrots.name
expect(page).to have_field "product_name", with: potatoes.name
find("div#columns-dropdown", text: "COLUMNS").click
find("div#columns-dropdown div.menu div.menu_item", text: "Import").click
find("div#columns-dropdown", text: "COLUMNS").click
toggle_columns "Import"
within "tr#p_#{carrots.id} td.import_date" do
expect(page).to have_content Time.zone.now.year

View File

@@ -1,6 +1,7 @@
require 'spec_helper'
feature 'Subscriptions' do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -62,8 +63,7 @@ feature 'Subscriptions' do
# Toggling columns
expect(page).to have_selector "th.customer"
expect(page).to have_content subscription.customer.email
first("div#columns-dropdown", :text => "COLUMNS").click
first("div#columns-dropdown div.menu div.menu_item", text: "Customer").click
toggle_columns "Customer"
expect(page).to have_no_selector "th.customer"
expect(page).to have_no_content subscription.customer.email

View File

@@ -6,6 +6,7 @@ feature %q{
I want to override the stock level and price of those products
Without affecting other hubs that share the same products
}, js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -112,9 +113,7 @@ feature %q{
expect(page).to have_selector "tr#v_#{variant_related.id}"
# Show/Hide products
first("div#columns-dropdown", :text => "COLUMNS").click
first("div#columns-dropdown div.menu div.menu_item", text: "Hide").click
first("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Hide"
expect(page).to have_selector "tr#v_#{variant.id}"
expect(page).to have_selector "tr#v_#{variant_related.id}"
within "tr#v_#{variant.id}" do click_button 'Hide' end
@@ -134,9 +133,7 @@ feature %q{
end
it "creates new overrides" do
first("div#columns-dropdown", :text => "COLUMNS").click
first("div#columns-dropdown div.menu div.menu_item", text: "SKU").click
first("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "SKU"
fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU'
fill_in "variant-overrides-#{variant.id}-price", with: '777.77'
@@ -287,15 +284,10 @@ feature %q{
# Any new fields added to the VO model need to be added to this test
it "deletes overrides when values are cleared" do
first("div#columns-dropdown", :text => "COLUMNS").click
first("div#columns-dropdown div.menu div.menu_item", text: "Enable Stock Reset?").click
first("div#columns-dropdown div.menu div.menu_item", text: "Tags").click
first("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Enable Stock Reset?", "Tags"
# Clearing values by 'inheriting'
first("div#columns-dropdown", :text => "COLUMNS").click
first("div#columns-dropdown div.menu div.menu_item", text: "Inherit?").click
first("div#columns-dropdown", :text => "COLUMNS").click
toggle_columns "Inherit?"
check "variant-overrides-#{variant3.id}-inherit"
# Clearing values manually

View File

@@ -2,4 +2,16 @@ module AdminHelper
def have_admin_menu_item(menu_item_name)
have_selector "ul[data-hook='admin_tabs'] li", text: menu_item_name
end
def toggle_columns(*labels)
# open dropdown
find("div#columns-dropdown", text: "COLUMNS").click
labels.each do |label|
find("div#columns-dropdown div.menu div.menu_item", text: label).click
end
# close dropdown
find("div#columns-dropdown", text: "COLUMNS").click
end
end