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 c0c6144f49..4294d88966 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,12 +110,6 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", .error (data, status) -> $timeout -> StatusMessage.display 'failure', $scope.updateError(data, status) - $scope.selectLimitedStockIfCountOnHandSet = (hubId, variantId) -> - variantOverride = $scope.variantOverrides[hubId][variantId] - if variantOverride.count_on_hand? && variantOverride.count_on_hand != '' && variantOverride.on_demand != false - variantOverride.on_demand = false - DirtyVariantOverrides.set hubId, variantId, variantOverride.id, 'on_demand', false - $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 38614ad2ba..d0e714e9fa 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', change: 'selectLimitedStockIfCountOnHandSet(hub_id, variant.id)' }, 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: '{{ variant.on_hand }}', '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/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 9be249de4d..e79e0293b9 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -140,8 +140,8 @@ feature %q{ fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU' fill_in "variant-overrides-#{variant.id}-price", with: '777.77' + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' - select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" page.should have_content "Changes to one override remain unsaved." expect do @@ -154,14 +154,15 @@ feature %q{ vo.hub_id.should == hub.id vo.sku.should == "NEWSKU" vo.price.should == 777.77 + expect(vo.on_demand).to eq(false) vo.count_on_hand.should == 123 - vo.on_demand.should == true end describe "creating and then updating the new override" do it "updates the same override instead of creating a duplicate" do # When I create a new override fill_in "variant-overrides-#{variant.id}-price", with: '777.77' + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' page.should have_content "Changes to one override remain unsaved." @@ -186,6 +187,7 @@ feature %q{ vo.variant_id.should == variant.id vo.hub_id.should == hub.id vo.price.should == 111.11 + expect(vo.on_demand).to eq(false) vo.count_on_hand.should == 111 end end @@ -241,6 +243,7 @@ feature %q{ it "updates existing overrides" do fill_in "variant-overrides-#{variant.id}-price", with: '22.22' + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '8888' page.should have_content "Changes to one override remain unsaved." @@ -253,6 +256,7 @@ feature %q{ vo.variant_id.should == variant.id vo.hub_id.should == hub.id vo.price.should == 22.22 + expect(vo.on_demand).to eq(false) vo.count_on_hand.should == 8888 end @@ -341,27 +345,15 @@ feature %q{ end describe "ensuring that on demand and count on hand settings are compatible" do - it "changes to limited stock when count on hand is set" do - # It sets on_demand to false when count_on_hand is filled. - fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" - expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.no") - - # It saves the changes. - click_button I18n.t("save_changes") - expect(page).to have_content I18n.t("js.changes_saved") - - vo.reload - expect(vo.count_on_hand).to eq(200) - expect(vo.on_demand).to eq(false) - end - it "clears count on hand when not limited stock" do # It clears count_on_hand when selecting true on_demand. + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" # It clears count_on_hand when selecting nil on_demand. + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" 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 1ac20b4318..203e3bc9ce 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 @@ -89,36 +89,6 @@ describe "VariantOverridesCtrl", -> expect(StatusMessage.display).toHaveBeenCalledWith 'success', 'Stocks reset to defaults.' describe "ensuring that on demand and count on hand settings are compatible", -> - describe "changing to limited stock when count on hand is set", -> - beforeEach -> - scope.variantOverrides = {123: {2: {id: 5, on_demand: true}}} - - describe "when count on hand is set", -> - beforeEach -> - scope.variantOverrides[123][2].count_on_hand = 1 - - it "changes to limited stock and registers dirty attribute", -> - scope.selectLimitedStockIfCountOnHandSet(123, 2) - expect(scope.variantOverrides[123][2].on_demand).toBe(false) - dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] - expect(dirtyVariantOverride.on_demand).toBe(false) - - describe "when count on hand is null", -> - beforeEach -> - scope.variantOverrides[123][2].count_on_hand = null - - it "does not change to limited stock", -> - scope.selectLimitedStockIfCountOnHandSet(123, 2) - expect(scope.variantOverrides[123][2].on_demand).toBe(true) - - describe "when count on hand is blank string", -> - beforeEach -> - scope.variantOverrides[123][2].count_on_hand = '' - - it "does not change to limited stock", -> - scope.selectLimitedStockIfCountOnHandSet(123, 2) - expect(scope.variantOverrides[123][2].on_demand).toBe(true) - describe "clearing count on hand when not limited stock", -> beforeEach -> scope.variantOverrides = {123: {2: {id: 5, count_on_hand: 1}}}