Skip to content

Commit

Permalink
Merge pull request #7260 from jibees/7069-add-automated-tests-for-uni…
Browse files Browse the repository at this point in the history
…t-price-in-backoffice

Add automated tests for unit price in backoffice
  • Loading branch information
andrewpbrett authored Apr 3, 2021
2 parents cb0644c + 9126901 commit b584659
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/views/spree/admin/products/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
%input{ type: 'hidden', 'ng-value' => 'product.variant_unit_scale', name: 'product[variant_unit_scale]' }
.two.columns
= f.field_container :unit_value do
= f.label :product_unit_value_with_description, t(".value"), 'ng-disabled' => "!hasUnit(product)"
= f.label :unit_value_with_description, t(".value"), 'ng-disabled' => "!hasUnit(product)"
%span.required *
%input.fullwidth{ id: 'product_unit_value_with_description', 'ng-model' => 'product.master.unit_value_with_description', :type => 'text', placeholder: "eg. 2", 'ng-disabled' => "!hasUnit(product)" }
%input{ type: 'hidden', 'ng-value' => 'product.master.unit_value', name: 'product[unit_value]' }
Expand Down Expand Up @@ -62,7 +62,8 @@
"question-mark-with-tooltip-placement" => "top",
"question-mark-with-tooltip-animation" => true,
key: "'js.admin.unit_price_tooltip'"}
= f.text_field :price, {"class" => 'fullwidth', "disabled" => true, "ng-model" => "unit_price"}
%input{ "type" => "text", "id" => "product_unit_price", "name" => "product[unit_price]",
"class" => 'fullwidth', "disabled" => true, "ng-model" => "unit_price"}
%div{style: "color: black"}
= t(".unit_price_legend")
.sixteen.columns.alpha
Expand Down
5 changes: 3 additions & 2 deletions app/views/spree/admin/variants/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- if product_has_variant_unit_option_type?(@product)
- if @product.variant_unit != 'items'
.field
= f.label :unit_value, "#{t('admin.'+@product.variant_unit)} ({{unitName(#{@product.variant_unit_scale}, '#{@product.variant_unit}')}})"
= label_tag :unit_value_human, "#{t('admin.'+@product.variant_unit)} ({{unitName(#{@product.variant_unit_scale}, '#{@product.variant_unit}')}})"
= hidden_field_tag 'product_variant_unit_scale', @product.variant_unit_scale
= text_field_tag :unit_value_human, nil, {class: "fullwidth", 'ng-model' => 'unit_value_human', 'ng-change' => 'updateValue()'}
= f.text_field :unit_value, {hidden: true, 'ng-value' => 'unit_value'}
Expand Down Expand Up @@ -46,7 +46,8 @@
"question-mark-with-tooltip-placement" => "top",
"question-mark-with-tooltip-animation" => true,
key: "'js.admin.unit_price_tooltip'"}
= f.text_field :price, {"class" => 'fullwidth', "disabled" => true, "ng-model" => "unit_price"}
%input{ "type" => "text", "id" => "variant_unit_price", "name" => "variant[unit_price]",
"class" => 'fullwidth', "disabled" => true, "ng-model" => "unit_price"}
%div{style: "color: black"}
= t("spree.admin.products.new.unit_price_legend")
%div{ 'set-on-demand' => '' }
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
form:
sku: "SKU"
price: "Price"
unit_price: "Unit Price"
display_as: "Display As"
display_name: "Display Name"
display_as_placeholder: 'eg. 2 kg'
Expand Down
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" 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 'Value', with: '1'
fill_in 'Price', with: '1'

expect(find_field("Unit Price", disabled: true).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 'Weight (g)', with: '1'
fill_in 'Price', with: '1'

expect(find_field("Unit Price", disabled: true).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_field("Unit Price", disabled: true).value).to eq '$1,000.00 / kg'
end
end
end

0 comments on commit b584659

Please sign in to comment.