Skip to content

Commit

Permalink
Add tests around unit price in backoffice
Browse files Browse the repository at this point in the history
3 cases:
 - creating a new product
 - creating a new variant
 - editing an existing variant
  • Loading branch information
jibees committed Mar 29, 2021
1 parent 2b46378 commit 96dfc13
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions spec/features/admin/unit_price_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

require 'spec_helper'

feature '
As an admin
I want to check the unit price of my products/variants
' do
include AuthenticationHelper
include WebHelper

let!(:stock_location) { create(:stock_location, backorderable_default: false) }

before do
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:unit_price, anything) { true }
end

describe "product", js: true do
scenario "creating a new product", :debug do
login_as_admin_and_visit spree.admin_products_path
click_link 'New Product'
select "Weight (kg)", from: 'product_variant_unit_with_scale'
fill_in 'product_unit_value_with_description', with: '1'
fill_in 'product[price]', with: '1'

expect(find("#variant_unit_price", :visible => false).value).to eq '$1.00 / kg'
end
end

describe "variant", js: true do
scenario "creating a new variant" do
product = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1")
login_as_admin_and_visit spree.admin_product_variants_path product
click_link 'New Variant'
fill_in 'unit_value_human', with: '1'
fill_in 'variant[price]', with: '1'

expect(find("#variant_unit_price", :visible => false).value).to eq '$1,000.00 / kg'
end

scenario "editing a variant" do
product = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1")
variant = product.variants.first
variant.update(price: 1.0)
login_as_admin_and_visit spree.edit_admin_product_variant_path(product, variant)

expect(find("#variant_unit_price", :visible => false).value).to eq '$1,000.00 / kg'
end
end
end

0 comments on commit 96dfc13

Please sign in to comment.