mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Display variant overrides
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, hubs, producers, hubPermissions) ->
|
||||
angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, hubs, producers, hubPermissions, variantOverrides) ->
|
||||
$scope.hubs = hubs
|
||||
$scope.hub = null
|
||||
$scope.products = []
|
||||
$scope.producers = Indexer.index producers
|
||||
$scope.hubPermissions = hubPermissions
|
||||
$scope.variantOverrides = Indexer.index variantOverrides, 'variant_id'
|
||||
|
||||
$scope.initialise = ->
|
||||
SpreeApiAuth.authorise()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
%tr.variant{ng: {repeat: 'variant in product.variants'}}
|
||||
%td
|
||||
%td {{ variant.options_text }}
|
||||
%td {{ variant.price }}
|
||||
%td {{ variant.on_hand }}
|
||||
%td {{ variant.price }} - {{ variantOverrides[variant.id].price }}
|
||||
%td {{ variant.on_hand }} - {{ variantOverrides[variant.id].count_on_hand }}
|
||||
|
||||
@@ -89,6 +89,11 @@ FactoryGirl.define do
|
||||
incoming false
|
||||
end
|
||||
|
||||
factory :variant_override, :class => VariantOverride do
|
||||
price 77.77
|
||||
count_on_hand 11111
|
||||
end
|
||||
|
||||
factory :enterprise, :class => Enterprise do
|
||||
owner { FactoryGirl.create :user }
|
||||
sequence(:name) { |n| "Enterprise #{n}" }
|
||||
|
||||
@@ -47,24 +47,40 @@ feature %q{
|
||||
before do
|
||||
# Remove 'S' option value
|
||||
variant.option_values.first.destroy
|
||||
|
||||
visit '/admin/products/override_variants'
|
||||
select2_select hub.name, from: 'hub_id'
|
||||
click_button 'Go'
|
||||
end
|
||||
|
||||
it "displays the list of products with variants" do
|
||||
page.should have_table_row ['PRODUCER', 'PRODUCT', 'PRICE', 'ON HAND']
|
||||
page.should have_table_row [producer.name, product.name, '', '']
|
||||
page.should have_table_row ['', '1g', '1.23', '12']
|
||||
context "with no overrides" do
|
||||
before do
|
||||
visit '/admin/products/override_variants'
|
||||
select2_select hub.name, from: 'hub_id'
|
||||
click_button 'Go'
|
||||
end
|
||||
|
||||
it "displays the list of products with variants" do
|
||||
page.should have_table_row ['PRODUCER', 'PRODUCT', 'PRICE', 'ON HAND']
|
||||
page.should have_table_row [producer.name, product.name, '', '']
|
||||
page.should have_table_row ['', '1g', '1.23 -', '12 -']
|
||||
end
|
||||
|
||||
it "filters the products to those the hub can add to an order cycle" do
|
||||
page.should_not have_content producer2.name
|
||||
page.should_not have_content product2.name
|
||||
end
|
||||
end
|
||||
|
||||
it "filters the products to those the hub can add to an order cycle" do
|
||||
page.should_not have_content producer2.name
|
||||
page.should_not have_content product2.name
|
||||
end
|
||||
context "with overrides" do
|
||||
let!(:override) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111) }
|
||||
|
||||
it "products values are affected by overrides"
|
||||
before do
|
||||
visit '/admin/products/override_variants'
|
||||
select2_select hub.name, from: 'hub_id'
|
||||
click_button 'Go'
|
||||
end
|
||||
|
||||
it "product values are affected by overrides" do
|
||||
page.should have_table_row ['', '1g', '1.23 - 77.77', '12 - 11111']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ describe "OverrideVariantsCtrl", ->
|
||||
producers = [{id: 2, name: 'Producer'}]
|
||||
products = [{id: 1, name: 'Product'}]
|
||||
hubPermissions = {}
|
||||
variantOverrides = {}
|
||||
|
||||
beforeEach ->
|
||||
module 'ofn.admin'
|
||||
@@ -14,7 +15,7 @@ describe "OverrideVariantsCtrl", ->
|
||||
scope = {}
|
||||
|
||||
inject ($controller, Indexer) ->
|
||||
ctrl = $controller 'AdminOverrideVariantsCtrl', {$scope: scope, Indexer: Indexer, hubs: hubs, producers: producers, products: products, hubPermissions: hubPermissions}
|
||||
ctrl = $controller 'AdminOverrideVariantsCtrl', {$scope: scope, Indexer: Indexer, hubs: hubs, producers: producers, products: products, hubPermissions: hubPermissions, variantOverrides: variantOverrides}
|
||||
|
||||
it "initialises the hub list and the chosen hub", ->
|
||||
expect(scope.hubs).toEqual hubs
|
||||
|
||||
Reference in New Issue
Block a user