mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Preventing shop from being changed when unsaved customer changes exist
Also making layout of filters on customer index more consistent with other pages
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
describe "CustomersCtrl", ->
|
||||
scope = null
|
||||
http = null
|
||||
shops = null
|
||||
|
||||
beforeEach ->
|
||||
module('admin.customers')
|
||||
@@ -8,28 +9,46 @@ describe "CustomersCtrl", ->
|
||||
$provide.value 'columns', []
|
||||
null
|
||||
|
||||
shops = [
|
||||
{ name: "Shop 1", id: 1 }
|
||||
{ name: "Shop 2", id: 2 }
|
||||
{ name: "Shop 3", id: 3 }
|
||||
]
|
||||
|
||||
|
||||
inject ($controller, $rootScope, _CustomerResource_, $httpBackend) ->
|
||||
scope = $rootScope
|
||||
http = $httpBackend
|
||||
$controller 'customersCtrl', {$scope: scope, CustomerResource: _CustomerResource_, shops: {}}
|
||||
$controller 'customersCtrl', {$scope: scope, CustomerResource: _CustomerResource_, shops: shops}
|
||||
jasmine.addMatchers
|
||||
toDeepEqual: (util, customEqualityTesters) ->
|
||||
compare: (actual, expected) ->
|
||||
{ pass: angular.equals(actual, expected) }
|
||||
|
||||
it "has no shop pre-selected", ->
|
||||
expect(scope.CurrentShop.shop).toEqual {}
|
||||
it "has no shop pre-selected", inject (CurrentShop) ->
|
||||
expect(CurrentShop.shop).toEqual {}
|
||||
|
||||
describe "setting the shop on scope", ->
|
||||
customer = { id: 5, email: 'someone@email.com'}
|
||||
customers = [customer]
|
||||
|
||||
beforeEach ->
|
||||
http.expectGET('/admin/customers.json?enterprise_id=1').respond 200, customers
|
||||
beforeEach inject (pendingChanges) ->
|
||||
spyOn(pendingChanges, "removeAll")
|
||||
scope.customers_form = jasmine.createSpyObj('customers_form', ['$setPristine'])
|
||||
http.expectGET('/admin/customers.json?enterprise_id=3').respond 200, customers
|
||||
scope.$apply ->
|
||||
scope.CurrentShop.shop = {id: 1}
|
||||
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.customers_form.$setPristine).toHaveBeenCalled()
|
||||
|
||||
it "clears all changes", inject (pendingChanges) ->
|
||||
expect(pendingChanges.removeAll).toHaveBeenCalled()
|
||||
|
||||
it "retrievs the list of customers", ->
|
||||
expect(scope.customers).toDeepEqual customers
|
||||
|
||||
@@ -38,7 +57,7 @@ describe "CustomersCtrl", ->
|
||||
email = "customer@example.org"
|
||||
newCustomer = {id: 6, email: email}
|
||||
customers.unshift(newCustomer)
|
||||
http.expectPOST('/admin/customers.json?email=' + email + '&enterprise_id=1').respond 200, newCustomer
|
||||
http.expectPOST('/admin/customers.json?email=' + email + '&enterprise_id=3').respond 200, newCustomer
|
||||
scope.add(email)
|
||||
http.flush()
|
||||
expect(scope.customers).toDeepEqual customers
|
||||
@@ -60,7 +79,7 @@ describe "CustomersCtrl", ->
|
||||
{ text: 'three' }
|
||||
]
|
||||
beforeEach ->
|
||||
http.expectGET('/admin/tag_rules/map_by_tag.json?enterprise_id=1').respond 200, tags
|
||||
http.expectGET('/admin/tag_rules/map_by_tag.json?enterprise_id=3').respond 200, tags
|
||||
|
||||
it "retrieves the tag list", ->
|
||||
promise = scope.findTags('')
|
||||
|
||||
Reference in New Issue
Block a user