mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
SO Index: User must select a shop first in order to load relevant standing orders
This commit is contained in:
@@ -7,16 +7,30 @@ feature 'Standing Orders' do
|
||||
context "as an enterprise user", js: true do
|
||||
let!(:user) { create_enterprise_user(enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise, owner: user) }
|
||||
let!(:shop2) { create(:distributor_enterprise, owner: user) }
|
||||
let!(:shop_unmanaged) { create(:distributor_enterprise) }
|
||||
|
||||
before { quick_login_as user }
|
||||
|
||||
context 'listing standing orders' do
|
||||
let!(:standing_order) { create(:standing_order, shop: shop) }
|
||||
let!(:standing_order2) { create(:standing_order, shop: shop2) }
|
||||
let!(:standing_order_unmanaged) { create(:standing_order, shop: shop_unmanaged) }
|
||||
|
||||
it "passes the smoke test" do
|
||||
visit admin_standing_orders_path
|
||||
|
||||
expect(page).to have_selector 'table#standing_orders td.customer', text: standing_order.customer.email
|
||||
expect(page).to have_select2 "shop_id", with_options: [shop.name, shop2.name], without_options: [shop_unmanaged.name]
|
||||
|
||||
select2_select shop2.name, from: "shop_id"
|
||||
|
||||
# Loads standing orders for that shop
|
||||
expect(page).to have_selector "tr#so_#{standing_order2.id}"
|
||||
expect(page).to have_no_selector "tr#so_#{standing_order.id}"
|
||||
expect(page).to have_no_selector "tr#so_#{standing_order_unmanaged.id}"
|
||||
within "tr#so_#{standing_order2.id}" do
|
||||
expect(page).to have_selector "td.customer", text: standing_order2.customer.email
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
describe "StandingOrdersCtrl", ->
|
||||
scope = null
|
||||
http = null
|
||||
shops = null
|
||||
shops = [
|
||||
{ name: "Shop 1", id: 1 }
|
||||
{ name: "Shop 2", id: 2 }
|
||||
{ name: "Shop 3", id: 3 }
|
||||
]
|
||||
|
||||
beforeEach ->
|
||||
module('admin.standingOrders')
|
||||
# module ($provide) ->
|
||||
# $provide.value 'columns', []
|
||||
# null
|
||||
|
||||
# shops = [
|
||||
# { name: "Shop 1", id: 1 }
|
||||
# { name: "Shop 2", id: 2 }
|
||||
# { name: "Shop 3", id: 3 }
|
||||
# ]
|
||||
module ($provide) ->
|
||||
# $provide.value 'columns', []
|
||||
$provide.value 'shops', shops
|
||||
null
|
||||
|
||||
inject ($controller, $rootScope, _StandingOrderResource_, $httpBackend) ->
|
||||
scope = $rootScope
|
||||
@@ -24,28 +23,20 @@ describe "StandingOrdersCtrl", ->
|
||||
compare: (actual, expected) ->
|
||||
{ pass: angular.equals(actual, expected) }
|
||||
|
||||
# it "has no shop pre-selected", inject (CurrentShop) ->
|
||||
# expect(CurrentShop.shop).toEqual {}
|
||||
it "has no shop pre-selected", ->
|
||||
expect(scope.shop_id).toEqual null
|
||||
|
||||
describe "initialization", -> # setting shop_id on scope
|
||||
describe "setting shop_id on scope", ->
|
||||
standingOrder = { id: 5, customer_id: 3, schedule_id: 1}
|
||||
standingOrders = [standingOrder]
|
||||
|
||||
beforeEach inject ->
|
||||
scope.standing_orders_form = jasmine.createSpyObj('standing_orders_form', ['$setPristine'])
|
||||
http.expectGET('/admin/standing_orders.json?ams_prefix=index').respond 200, standingOrders
|
||||
# scope.$apply ->
|
||||
# scope.shop_id = 3
|
||||
beforeEach ->
|
||||
http.expectGET('/admin/standing_orders.json?ams_prefix=index&q%5Bshop_id_eq%5D=3').respond 200, standingOrders
|
||||
scope.$apply -> scope.shop_id = 3
|
||||
http.flush()
|
||||
|
||||
# it "sets the CurrentShop", inject (CurrentShop) ->
|
||||
# expect(CurrentShop.shop).toEqual shops[2]
|
||||
#
|
||||
# it "sets the form state to pristine", ->
|
||||
# expect(scope.standingOrders_form.$setPristine).toHaveBeenCalled()
|
||||
#
|
||||
# it "clears all changes", inject (pendingChanges) ->
|
||||
# expect(pendingChanges.removeAll).toHaveBeenCalled()
|
||||
|
||||
it "retrieves the list of standingOrders", ->
|
||||
expect(scope.standingOrders).toDeepEqual standingOrders
|
||||
|
||||
Reference in New Issue
Block a user