From 4f2d96d763e70a1d886346776533eb73ce9b38c2 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 29 Nov 2018 15:18:01 +0800 Subject: [PATCH] Use correct placeholders for VO count_on_hand --- .../variant_overrides_controller.js.coffee | 10 ++++ .../_products_variants.html.haml | 2 +- config/locales/en.yml | 3 ++ spec/features/admin/variant_overrides_spec.rb | 4 +- ...ariant_overrides_controller_spec.js.coffee | 48 +++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 4294d88966..4788e367e5 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -110,6 +110,16 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", .error (data, status) -> $timeout -> StatusMessage.display 'failure', $scope.updateError(data, status) + $scope.countOnHandPlaceholder = (variant, hubId) -> + variantOverride = $scope.variantOverrides[hubId][variant.id] + + if variantOverride.on_demand + t('js.variants.on_demand.yes') + else if variantOverride.on_demand == false + '' + else + variant.on_hand + $scope.clearCountOnHandUnlessLimitedStock = (hubId, variantId) -> variantOverride = $scope.variantOverrides[hubId][variantId] unless variantOverride.on_demand == false && variantOverride.count_on_hand? diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index d0e714e9fa..2c915fa0ae 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -8,7 +8,7 @@ %td.price{ ng: { show: 'columns.price.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-price', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].price'}, placeholder: '{{ variant.price }}', 'ofn-track-variant-override' => 'price'} %td.on_hand{ ng: { show: 'columns.on_hand.visible' } } - %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'} + %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ countOnHandPlaceholder(variant, hub_id) }}', 'ofn-track-variant-override' => 'count_on_hand'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'clearCountOnHandUnlessLimitedStock(hub_id, variant.id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } %option{ value: '' }= t(".on_demand.use_producer_settings") diff --git a/config/locales/en.yml b/config/locales/en.yml index 7738fed822..879f431452 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2595,6 +2595,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using in your cart have reduced. Here's what's changed: now_out_of_stock: is now out of stock. only_n_remainging: "now only has %{num} remaining." + variants: + on_demand: + "yes": "On demand" variant_overrides: on_demand: "yes": "Yes" diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index e79e0293b9..120f5093cb 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -237,7 +237,7 @@ feature %q{ it "product values are affected by overrides" do page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23' - page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: '12' + page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: I18n.t("js.variants.on_demand.yes") expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.yes") end @@ -325,7 +325,7 @@ feature %q{ first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click page.should have_content 'Stocks reset to defaults.' vo.reload - page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: '12' + page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: I18n.t("js.variants.on_demand.yes") vo.count_on_hand.should == 1000 end diff --git a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee index 203e3bc9ce..e7e17648e8 100644 --- a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee @@ -120,3 +120,51 @@ describe "VariantOverridesCtrl", -> expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] expect(dirtyVariantOverride.count_on_hand).toBeNull() + + describe "count on hand placeholder", -> + beforeEach -> + scope.variantOverrides = {123: {}} + + describe "when variant is on demand", -> + variant = null + + beforeEach -> + # Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not + # enforced. + variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: t("on_demand")} + + it "is 'On demand' when variant override uses producer stock settings", -> + scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(t("on_demand")) + + it "is 'On demand' when variant override is on demand", -> + scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(t("js.variants.on_demand.yes")) + + it "is blank when variant override is limited stock", -> + scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe('') + + describe "when variant is limited stock", -> + variant = null + + beforeEach -> + variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20} + + it "is variant count on hand when variant override uses producer stock settings", -> + scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(20) + + it "is 'On demand' when variant override is on demand", -> + scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(t("js.variants.on_demand.yes")) + + it "is blank when variant override is limited stock", -> + scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe('')