mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Refactor product page system spec
Remove some duplication and group related test
This commit is contained in:
@@ -13,23 +13,18 @@ RSpec.describe '
|
||||
let!(:taxon) { create(:taxon) }
|
||||
let!(:stock_location) { create(:stock_location, backorderable_default: false) }
|
||||
let!(:shipping_category) { DefaultShippingCategory.find_or_create }
|
||||
|
||||
before do
|
||||
@supplier = create(:supplier_enterprise, name: 'New supplier')
|
||||
@distributors = (1..3).map { create(:distributor_enterprise) }
|
||||
@enterprise_fees = (0..2).map { |i| create(:enterprise_fee, enterprise: @distributors[i]) }
|
||||
end
|
||||
let!(:supplier) { create(:supplier_enterprise, name: 'New supplier') }
|
||||
|
||||
describe "creating a product" do
|
||||
let!(:tax_category) { create(:tax_category, name: 'Test Tax Category') }
|
||||
|
||||
before do
|
||||
login_as_admin
|
||||
visit spree.new_admin_product_path
|
||||
end
|
||||
|
||||
it "display all attributes when submitting with error: no name" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Products'
|
||||
click_link 'New Product'
|
||||
|
||||
select @supplier.name, from: 'product_supplier_id'
|
||||
select supplier.name, from: 'product_supplier_id'
|
||||
select "Weight (kg)", from: 'product_variant_unit_with_scale'
|
||||
fill_in 'product_unit_value', with: "5.00 g"
|
||||
assert_selector(:field, placeholder: "5kg g")
|
||||
@@ -44,7 +39,7 @@ RSpec.describe '
|
||||
click_button 'Create'
|
||||
|
||||
expect(page).to have_content "Name can't be blank"
|
||||
expect(page).to have_field 'product_supplier_id', with: @supplier.id
|
||||
expect(page).to have_field 'product_supplier_id', with: supplier.id
|
||||
expect(page).to have_field 'product_unit_value', with: "5.00 g"
|
||||
expect(page).to have_field 'product_display_as', with: "Big Box of Chocolates"
|
||||
expect(page).to have_field 'product_primary_taxon_id', with: taxon.id
|
||||
@@ -60,10 +55,6 @@ RSpec.describe '
|
||||
end
|
||||
|
||||
it "display all attributes when submitting with error: Unit Value must be grater than 0" do
|
||||
login_to_admin_section
|
||||
|
||||
visit spree.new_admin_product_path
|
||||
|
||||
select 'New supplier', from: 'product_supplier_id'
|
||||
fill_in 'product_name', with: "new product name"
|
||||
select "Weight (kg)", from: 'product_variant_unit_with_scale'
|
||||
@@ -80,7 +71,7 @@ RSpec.describe '
|
||||
click_button 'Create'
|
||||
|
||||
expect(page).to have_field 'product_name', with: "new product name"
|
||||
expect(page).to have_field 'product_supplier_id', with: @supplier.id
|
||||
expect(page).to have_field 'product_supplier_id', with: supplier.id
|
||||
expect(page).to have_field 'product_unit_value', with: "0 g"
|
||||
expect(page).to have_field 'product_display_as', with: "Big Box of Chocolates"
|
||||
expect(page).to have_field 'product_primary_taxon_id', with: taxon.id
|
||||
@@ -96,11 +87,6 @@ RSpec.describe '
|
||||
end
|
||||
|
||||
it "preserves 'Items' 'Unit Size' selection when submitting with error" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Products'
|
||||
click_link 'New Product'
|
||||
|
||||
select "Items", from: 'product_variant_unit_with_scale'
|
||||
|
||||
click_button 'Create'
|
||||
@@ -109,11 +95,6 @@ RSpec.describe '
|
||||
end
|
||||
|
||||
it "assigning important attributes" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Products'
|
||||
click_link 'New Product'
|
||||
|
||||
expect(find_field('product_shipping_category_id').text).to eq(shipping_category.name)
|
||||
|
||||
select 'New supplier', from: 'product_supplier_id'
|
||||
@@ -146,15 +127,10 @@ RSpec.describe '
|
||||
|
||||
variant = product.variants.first
|
||||
expect(variant.unit_presentation).to eq("5kg")
|
||||
expect(variant.supplier).to eq(@supplier)
|
||||
expect(variant.supplier).to eq(supplier)
|
||||
end
|
||||
|
||||
it "creating an on-demand product" do
|
||||
login_as_admin
|
||||
visit spree.admin_products_path
|
||||
|
||||
click_link 'New Product'
|
||||
|
||||
fill_in 'product_name', with: 'Hot Cakes'
|
||||
select 'New supplier', from: 'product_supplier_id'
|
||||
select "Weight (kg)", from: 'product_variant_unit_with_scale'
|
||||
@@ -177,11 +153,6 @@ RSpec.describe '
|
||||
end
|
||||
|
||||
it "creating product with empty unit value" do
|
||||
login_as_admin
|
||||
visit spree.admin_products_path
|
||||
|
||||
click_link 'New Product'
|
||||
|
||||
fill_in 'product_name', with: 'Hot Cakes'
|
||||
select 'New supplier', from: 'product_supplier_id'
|
||||
select "Weight (kg)", from: 'product_variant_unit_with_scale'
|
||||
@@ -228,9 +199,6 @@ RSpec.describe '
|
||||
context "when enable_localized_number is set to #{localized_number}" do
|
||||
before do
|
||||
allow(Spree::Config).to receive(:enable_localized_number?).and_return(localized_number)
|
||||
login_as_admin
|
||||
visit spree.admin_products_path
|
||||
click_link 'New Product'
|
||||
end
|
||||
|
||||
it "and price is #{price}" do
|
||||
@@ -370,23 +338,22 @@ RSpec.describe '
|
||||
let!(:tax_category) { create(:tax_category) }
|
||||
let(:filter) { { producerFilter: 2 } }
|
||||
let(:image_file_path) { Rails.root.join(file_fixture_path, "thinking-cat.jpg") }
|
||||
let(:supplier2) { create(:supplier_enterprise, name: 'Another Supplier') }
|
||||
let(:supplier_permitted) { create(:supplier_enterprise, name: 'Permitted Supplier') }
|
||||
let(:new_user) { create(:user) }
|
||||
|
||||
before do
|
||||
@new_user = create(:user)
|
||||
@supplier2 = create(:supplier_enterprise, name: 'Another Supplier')
|
||||
@supplier_permitted = create(:supplier_enterprise, name: 'Permitted Supplier')
|
||||
@new_user.enterprise_roles.build(enterprise: @supplier2).save
|
||||
@new_user.enterprise_roles.build(enterprise: @distributors[0]).save
|
||||
create(:enterprise_relationship, parent: @supplier_permitted, child: @supplier2,
|
||||
permissions_list: [:manage_products])
|
||||
new_user.enterprise_roles.build(enterprise: supplier2).save
|
||||
|
||||
login_as @new_user
|
||||
login_as new_user
|
||||
end
|
||||
|
||||
context "products do not require a tax category" do
|
||||
it "creating a new product" do
|
||||
visit spree.admin_products_path
|
||||
click_link 'New Product'
|
||||
create(:enterprise_relationship, parent: supplier_permitted, child: supplier2,
|
||||
permissions_list: [:manage_products])
|
||||
|
||||
visit spree.new_admin_product_path
|
||||
|
||||
fill_in 'product_name', with: 'A new product !!!'
|
||||
fill_in 'product_price', with: '19.99'
|
||||
@@ -400,8 +367,8 @@ RSpec.describe '
|
||||
|
||||
# Should only have suppliers listed which the user can manage
|
||||
expect(page).to have_select 'product_supplier_id',
|
||||
with_options: [@supplier2.name, @supplier_permitted.name]
|
||||
expect(page).not_to have_select 'product_supplier_id', with_options: [@supplier.name]
|
||||
with_options: [supplier2.name, supplier_permitted.name]
|
||||
expect(page).not_to have_select 'product_supplier_id', with_options: [supplier.name]
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
@@ -409,369 +376,350 @@ RSpec.describe '
|
||||
product = Spree::Product.find_by(name: 'A new product !!!')
|
||||
variant = product.variants.first
|
||||
expect(variant.tax_category).to be_nil
|
||||
expect(variant.supplier).to eq(@supplier2)
|
||||
expect(variant.supplier).to eq(supplier2)
|
||||
end
|
||||
end
|
||||
|
||||
it "editing a product" do
|
||||
product = create(:simple_product, name: 'a product', supplier_id: @supplier2.id)
|
||||
describe "editing page" do
|
||||
let!(:product) { create(:simple_product, name: 'a product', supplier_id: supplier2.id) }
|
||||
|
||||
visit spree.edit_admin_product_path product
|
||||
it "editing a product" do
|
||||
visit spree.edit_admin_product_path product
|
||||
|
||||
fill_in_trix_editor 'product_description', with: 'A description...'
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq('Product "a product" has been successfully updated!')
|
||||
product.reload
|
||||
expect(product.description).to eq("<div>A description...</div>")
|
||||
end
|
||||
fill_in_trix_editor 'product_description', with: 'A description...'
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq('Product "a product" has been successfully updated!')
|
||||
product.reload
|
||||
expect(product.description).to eq("<div>A description...</div>")
|
||||
end
|
||||
|
||||
it "editing a product comming from the bulk product update page with filter" do
|
||||
product = create(:simple_product, name: 'a product', supplier_id: @supplier2.id)
|
||||
it "editing a product comming from the bulk product update page with filter" do
|
||||
visit spree.edit_admin_product_path(product, filter)
|
||||
|
||||
visit spree.edit_admin_product_path(product, filter)
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq('Product "a product" has been successfully updated!')
|
||||
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq('Product "a product" has been successfully updated!')
|
||||
# Check the url still includes the filters
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
|
||||
# Check the url still includes the filters
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
# Link back to the bulk product update page should include the filters
|
||||
expected_admin_product_url =
|
||||
Regexp.new(Regexp.escape("#{spree.admin_products_path}#?#{filter.to_query}"))
|
||||
expect(page).to have_link('Back to products list',
|
||||
href: expected_admin_product_url)
|
||||
expect(page).to have_link('Cancel', href: expected_admin_product_url)
|
||||
|
||||
# Link back to the bulk product update page should include the filters
|
||||
expected_admin_product_url =
|
||||
Regexp.new(Regexp.escape("#{spree.admin_products_path}#?#{filter.to_query}"))
|
||||
expect(page).to have_link('Back to products list',
|
||||
href: expected_admin_product_url)
|
||||
expect(page).to have_link('Cancel', href: expected_admin_product_url)
|
||||
expected_product_url = Regexp.new(Regexp.escape(spree.edit_admin_product_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Product Details',
|
||||
href: expected_product_url)
|
||||
|
||||
expected_product_url = Regexp.new(Regexp.escape(spree.edit_admin_product_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Product Details',
|
||||
href: expected_product_url)
|
||||
|
||||
expected_product_image_url = Regexp.new(Regexp.escape(spree.admin_product_images_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Images',
|
||||
href: expected_product_image_url)
|
||||
|
||||
expected_product_variant_url = Regexp.new(Regexp.escape(spree.admin_product_variants_path(
|
||||
expected_product_image_url = Regexp.new(Regexp.escape(spree.admin_product_images_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Variants',
|
||||
href: expected_product_variant_url)
|
||||
expect(page).to have_link('Images',
|
||||
href: expected_product_image_url)
|
||||
|
||||
expected_product_properties_url =
|
||||
Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Product Properties',
|
||||
href: expected_product_properties_url)
|
||||
expected_product_variant_url = Regexp.new(Regexp.escape(spree.admin_product_variants_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Variants',
|
||||
href: expected_product_variant_url)
|
||||
|
||||
expected_product_group_buy_option_url =
|
||||
Regexp.new(Regexp.escape(spree.group_buy_options_admin_product_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Group Buy Options',
|
||||
href: expected_product_group_buy_option_url)
|
||||
expected_product_properties_url =
|
||||
Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Product Properties',
|
||||
href: expected_product_properties_url)
|
||||
|
||||
expected_product_seo_url = Regexp.new(Regexp.escape(spree.seo_admin_product_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Search', href: expected_product_seo_url)
|
||||
end
|
||||
expected_product_group_buy_option_url =
|
||||
Regexp.new(Regexp.escape(spree.group_buy_options_admin_product_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Group Buy Options',
|
||||
href: expected_product_group_buy_option_url)
|
||||
|
||||
it "editing product group buy options" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
visit spree.edit_admin_product_path product
|
||||
within('#sidebar') { click_link 'Group Buy Options' }
|
||||
choose('product_group_buy_1')
|
||||
fill_in 'Bulk unit size', with: '10'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
expect(flash_message).to eq("Product \"#{product.name}\" has been successfully updated!")
|
||||
product.reload
|
||||
expect(product.group_buy).to be true
|
||||
expect(product.group_buy_unit_size).to eq(10.0)
|
||||
end
|
||||
|
||||
it "loading editing product group buy options with url filters" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
visit spree.group_buy_options_admin_product_path(product, filter)
|
||||
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product,
|
||||
filter)))
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
|
||||
it "editing product group buy options with url filter" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
visit spree.group_buy_options_admin_product_path(product, filter)
|
||||
choose('product_group_buy_1')
|
||||
fill_in 'Bulk unit size', with: '10'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
end
|
||||
|
||||
it "editing product Search" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
visit spree.edit_admin_product_path product
|
||||
within('#sidebar') { click_link 'Search' }
|
||||
fill_in 'Product Search Keywords', with: 'Product Search Keywords'
|
||||
fill_in 'Notes', with: 'Just testing Notes'
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq("Product \"#{product.name}\" has been successfully updated!")
|
||||
product.reload
|
||||
expect(product.notes).to eq('Just testing Notes')
|
||||
expect(product.meta_keywords).to eq('Product Search Keywords')
|
||||
end
|
||||
|
||||
it "loading editing product Search with url filters" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
visit spree.seo_admin_product_path(product, filter)
|
||||
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product,
|
||||
filter)))
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
|
||||
it "editing product Search with url filter" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
visit spree.seo_admin_product_path(product, filter)
|
||||
|
||||
fill_in 'Product Search Keywords', with: 'Product Search Keywords'
|
||||
fill_in 'Notes', with: 'Just testing Notes'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
end
|
||||
|
||||
it "loading product properties page including url filters" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
visit spree.admin_product_product_properties_path(product, filter)
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
# we stay on the same url as the new image content is loaded via an ajax call
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_product_properties_path(product,
|
||||
filter)
|
||||
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(
|
||||
product, filter
|
||||
)))
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
|
||||
it "deleting product properties" do
|
||||
# Given a product with a property
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
product.set_property('fooprop', 'fooval')
|
||||
|
||||
# When I navigate to the product properties page
|
||||
visit spree.admin_product_product_properties_path(product)
|
||||
expect(page).to have_select2 'product_product_properties_attributes_0_property_name',
|
||||
selected: 'fooprop'
|
||||
expect(page).to have_field 'product_product_properties_attributes_0_value', with: 'fooval'
|
||||
|
||||
# And I delete the property
|
||||
accept_alert do
|
||||
page.all('a.delete-resource').first.click
|
||||
end
|
||||
click_button 'Update'
|
||||
|
||||
# Then the property should have been deleted
|
||||
expect(page).not_to have_field 'product_product_properties_attributes_0_property_name',
|
||||
with: 'fooprop'
|
||||
expect(page).not_to have_field 'product_product_properties_attributes_0_value', with: 'fooval'
|
||||
expect(product.reload.property('fooprop')).to be_nil
|
||||
end
|
||||
|
||||
it "deleting product properties including url filters" do
|
||||
# Given a product with a property
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
product.set_property('fooprop', 'fooval')
|
||||
|
||||
# When I navigate to the product properties page
|
||||
visit spree.admin_product_product_properties_path(product, filter)
|
||||
|
||||
# And I delete the property
|
||||
accept_alert do
|
||||
page.all('a.delete-resource').first.click
|
||||
expected_product_seo_url = Regexp.new(Regexp.escape(spree.seo_admin_product_path(
|
||||
product.id, filter
|
||||
)))
|
||||
expect(page).to have_link('Search', href: expected_product_seo_url)
|
||||
end
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_product_properties_path(product,
|
||||
filter)
|
||||
end
|
||||
it "editing product group buy options" do
|
||||
visit spree.edit_admin_product_path product
|
||||
within('#sidebar') { click_link 'Group Buy Options' }
|
||||
choose('product_group_buy_1')
|
||||
fill_in 'Bulk unit size', with: '10'
|
||||
|
||||
it "adding product properties including url filters" do
|
||||
# Given a product
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
product.set_property('fooprop', 'fooval')
|
||||
click_button 'Update'
|
||||
|
||||
# When I navigate to the product properties page
|
||||
visit spree.admin_product_product_properties_path(product, filter)
|
||||
expect(flash_message).to eq("Product \"#{product.name}\" has been successfully updated!")
|
||||
product.reload
|
||||
expect(product.group_buy).to be true
|
||||
expect(product.group_buy_unit_size).to eq(10.0)
|
||||
end
|
||||
|
||||
# And I add a property
|
||||
select 'fooprop', from: 'product_product_properties_attributes_0_property_name'
|
||||
fill_in 'product_product_properties_attributes_0_value', with: 'fooval2'
|
||||
it "loading editing product group buy options with url filters" do
|
||||
visit spree.group_buy_options_admin_product_path(product, filter)
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
end
|
||||
|
||||
it "loading new product image page" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
visit spree.admin_product_images_path(product)
|
||||
expect(page).to have_selector ".no-objects-found"
|
||||
|
||||
page.find('a#new_image_link').click
|
||||
expect(page).to have_selector "#image_attachment"
|
||||
end
|
||||
|
||||
it "loading new product image page including url filters" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
page.find('a#new_image_link').click
|
||||
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product,
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product,
|
||||
filter)))
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
|
||||
it "upload a new product image including url filters" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
it "editing product group buy options with url filter" do
|
||||
visit spree.group_buy_options_admin_product_path(product, filter)
|
||||
choose('product_group_buy_1')
|
||||
fill_in 'Bulk unit size', with: '10'
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
click_button 'Update'
|
||||
|
||||
page.find('a#new_image_link').click
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
end
|
||||
|
||||
attach_file('image_attachment', image_file_path)
|
||||
click_button "Create"
|
||||
it "editing product Search" do
|
||||
visit spree.edit_admin_product_path product
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
end
|
||||
within('#sidebar') { click_link 'Search' }
|
||||
fill_in 'Product Search Keywords', with: 'Product Search Keywords'
|
||||
fill_in 'Notes', with: 'Just testing Notes'
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq("Product \"#{product.name}\" has been successfully updated!")
|
||||
product.reload
|
||||
expect(product.notes).to eq('Just testing Notes')
|
||||
expect(product.meta_keywords).to eq('Product Search Keywords')
|
||||
end
|
||||
|
||||
it "loading image page including url filter" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
it "loading editing product Search with url filters" do
|
||||
visit spree.seo_admin_product_path(product, filter)
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
expected_new_image_link = Regexp.new(Regexp.escape(spree.new_admin_product_image_path(
|
||||
product, filter
|
||||
)))
|
||||
expect(page).to have_link('New Image', href: expected_new_image_link)
|
||||
end
|
||||
|
||||
it "loading edit product image page including url filter" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
image = white_logo_file
|
||||
image_object = Spree::Image.create(viewable_id: product.id,
|
||||
viewable_type: 'Spree::Product', alt: "position 1",
|
||||
attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
page.find("a.icon-edit").click
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}")
|
||||
.to eq spree.edit_admin_product_image_path(product, image_object, filter)
|
||||
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product,
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product,
|
||||
filter)))
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
expect(page).to have_link("Back To Images List", href: expected_cancel_link)
|
||||
end
|
||||
|
||||
it "updating a product image including url filter" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
image = white_logo_file
|
||||
image_object = Spree::Image.create(viewable_id: product.id,
|
||||
viewable_type: 'Spree::Product', alt: "position 1",
|
||||
attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
page.find("a.icon-edit").click
|
||||
|
||||
attach_file('image_attachment', image_file_path)
|
||||
click_button "Update"
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
end
|
||||
|
||||
it "checks error when creating product image with unsupported format" do
|
||||
unsupported_image_file_path = Rails.root.join("README.md").to_s
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
image = white_logo_file
|
||||
Spree::Image.create(viewable_id: product.id, viewable_type: 'Spree::Product',
|
||||
alt: "position 1", attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product)
|
||||
page.find('a#new_image_link').click
|
||||
attach_file('image_attachment', unsupported_image_file_path)
|
||||
click_button "Create"
|
||||
|
||||
expect(page).to have_text "Attachment has an invalid content type"
|
||||
expect(page).to have_text "Attachment is not a valid image"
|
||||
end
|
||||
|
||||
it "deleting product images" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
image = white_logo_file
|
||||
Spree::Image.create(viewable_id: product.id, viewable_type: 'Spree::Product',
|
||||
alt: "position 1", attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product)
|
||||
expect(page).to have_selector "table.index td img"
|
||||
expect(product.reload.image).not_to be_nil
|
||||
|
||||
accept_alert do
|
||||
page.find('a.delete-resource').click
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
|
||||
expect(page).not_to have_selector "table.index td img"
|
||||
expect(product.reload.image).to be_nil
|
||||
end
|
||||
it "editing product Search with url filter" do
|
||||
visit spree.seo_admin_product_path(product, filter)
|
||||
|
||||
it "deleting product image including url filter" do
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
image = white_logo_file
|
||||
Spree::Image.create(viewable_id: product.id, viewable_type: 'Spree::Product',
|
||||
alt: "position 1", attachment: image, position: 1)
|
||||
fill_in 'Product Search Keywords', with: 'Product Search Keywords'
|
||||
fill_in 'Notes', with: 'Just testing Notes'
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
click_button 'Update'
|
||||
|
||||
accept_alert do
|
||||
page.find('a.delete-resource').click
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
end
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
it "loading product properties page including url filters" do
|
||||
visit spree.admin_product_product_properties_path(product, filter)
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
# we stay on the same url as the new image content is loaded via an ajax call
|
||||
expect("#{uri.path}?#{uri.query}").to eq(
|
||||
spree.admin_product_product_properties_path(product, filter)
|
||||
)
|
||||
|
||||
expected_cancel_link = Regexp.new(
|
||||
Regexp.escape(spree.admin_product_product_properties_path(product, filter))
|
||||
)
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
end
|
||||
|
||||
describe "product properties" do
|
||||
# Given a product with a property
|
||||
let!(:product) {
|
||||
create(:simple_product, supplier_id: supplier2.id).tap do |product|
|
||||
product.set_property('fooprop', 'fooval')
|
||||
end
|
||||
}
|
||||
|
||||
it "deleting product properties" do
|
||||
# When I navigate to the product properties page
|
||||
visit spree.admin_product_product_properties_path(product)
|
||||
expect(page).to have_select2 'product_product_properties_attributes_0_property_name',
|
||||
selected: 'fooprop'
|
||||
expect(page).to have_field 'product_product_properties_attributes_0_value', with: 'fooval'
|
||||
|
||||
# And I delete the property
|
||||
accept_alert do
|
||||
page.all('a.delete-resource').first.click
|
||||
end
|
||||
click_button 'Update'
|
||||
|
||||
# Then the property should have been deleted
|
||||
expect(page).not_to have_field 'product_product_properties_attributes_0_property_name',
|
||||
with: 'fooprop'
|
||||
expect(page).not_to have_field 'product_product_properties_attributes_0_value',
|
||||
with: 'fooval'
|
||||
expect(product.reload.property('fooprop')).to be_nil
|
||||
end
|
||||
|
||||
it "deleting product properties including url filters" do
|
||||
# When I navigate to the product properties page
|
||||
visit spree.admin_product_product_properties_path(product, filter)
|
||||
|
||||
# And I delete the property
|
||||
accept_alert do
|
||||
page.all('a.delete-resource').first.click
|
||||
end
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq(
|
||||
spree.admin_product_product_properties_path(product, filter)
|
||||
)
|
||||
end
|
||||
|
||||
it "adding product properties including url filters" do
|
||||
# When I navigate to the product properties page
|
||||
visit spree.admin_product_product_properties_path(product, filter)
|
||||
|
||||
# And I add a property
|
||||
select 'fooprop', from: 'product_product_properties_attributes_0_property_name'
|
||||
fill_in 'product_product_properties_attributes_0_value', with: 'fooval2'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
|
||||
end
|
||||
end
|
||||
|
||||
describe "image page" do
|
||||
let!(:product) { create(:simple_product, supplier_id: supplier2.id) }
|
||||
|
||||
it "loading new product image page" do
|
||||
visit spree.admin_product_images_path(product)
|
||||
expect(page).to have_selector ".no-objects-found"
|
||||
|
||||
page.find('a#new_image_link').click
|
||||
expect(page).to have_selector "#image_attachment"
|
||||
end
|
||||
|
||||
it "loading new product image page including url filters" do
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
page.find('a#new_image_link').click
|
||||
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product,
|
||||
filter)))
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
end
|
||||
|
||||
it "upload a new product image including url filters" do
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
page.find('a#new_image_link').click
|
||||
|
||||
attach_file('image_attachment', image_file_path)
|
||||
click_button "Create"
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
end
|
||||
|
||||
it "loading image page including url filter" do
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
expected_new_image_link = Regexp.new(Regexp.escape(spree.new_admin_product_image_path(
|
||||
product, filter
|
||||
)))
|
||||
expect(page).to have_link('New Image', href: expected_new_image_link)
|
||||
end
|
||||
|
||||
it "loading edit product image page including url filter" do
|
||||
image = white_logo_file
|
||||
image_object = Spree::Image.create(viewable_id: product.id,
|
||||
viewable_type: 'Spree::Product', alt: "position 1",
|
||||
attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
page.find("a.icon-edit").click
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}")
|
||||
.to eq spree.edit_admin_product_image_path(product, image_object, filter)
|
||||
|
||||
expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product,
|
||||
filter)))
|
||||
expect(page).to have_link('Cancel', href: expected_cancel_link)
|
||||
expect(page).to have_link("Back To Images List", href: expected_cancel_link)
|
||||
end
|
||||
|
||||
it "updating a product image including url filter" do
|
||||
image = white_logo_file
|
||||
image_object = Spree::Image.create(viewable_id: product.id,
|
||||
viewable_type: 'Spree::Product', alt: "position 1",
|
||||
attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
page.find("a.icon-edit").click
|
||||
|
||||
attach_file('image_attachment', image_file_path)
|
||||
click_button "Update"
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
end
|
||||
|
||||
it "checks error when creating product image with unsupported format" do
|
||||
unsupported_image_file_path = Rails.root.join("README.md").to_s
|
||||
product = create(:simple_product, supplier_id: @supplier2.id)
|
||||
|
||||
image = white_logo_file
|
||||
Spree::Image.create(viewable_id: product.id, viewable_type: 'Spree::Product',
|
||||
alt: "position 1", attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product)
|
||||
page.find('a#new_image_link').click
|
||||
attach_file('image_attachment', unsupported_image_file_path)
|
||||
click_button "Create"
|
||||
|
||||
expect(page).to have_text "Attachment has an invalid content type"
|
||||
expect(page).to have_text "Attachment is not a valid image"
|
||||
end
|
||||
|
||||
it "deleting product images" do
|
||||
image = white_logo_file
|
||||
Spree::Image.create(viewable_id: product.id, viewable_type: 'Spree::Product',
|
||||
alt: "position 1", attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product)
|
||||
expect(page).to have_selector "table.index td img"
|
||||
expect(product.reload.image).not_to be_nil
|
||||
|
||||
accept_alert do
|
||||
page.find('a.delete-resource').click
|
||||
end
|
||||
|
||||
expect(page).not_to have_selector "table.index td img"
|
||||
expect(product.reload.image).to be_nil
|
||||
end
|
||||
|
||||
it "deleting product image including url filter" do
|
||||
image = white_logo_file
|
||||
Spree::Image.create(viewable_id: product.id, viewable_type: 'Spree::Product',
|
||||
alt: "position 1", attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product, filter)
|
||||
|
||||
accept_alert do
|
||||
page.find('a.delete-resource').click
|
||||
end
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
end
|
||||
end
|
||||
|
||||
context "editing a product's variant unit scale" do
|
||||
let(:product) { create(:simple_product, name: 'a product', supplier_id: @supplier2.id) }
|
||||
let(:product) { create(:simple_product, name: 'a product', supplier_id: supplier2.id) }
|
||||
|
||||
before do
|
||||
allow(Spree::Config).to receive(:available_units).and_return("g,lb,oz,kg,T,mL,L,kL")
|
||||
|
||||
Reference in New Issue
Block a user