Make user aware of server side errors when saving subscription products and unit test products_panel_controller

This commit is contained in:
luisramos0
2019-12-09 14:21:08 +00:00
parent 1b29d474d0
commit f64e8bf50e
3 changed files with 46 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
describe "ProductsPanelController", ->
scope = null
StatusMessage = null
subscription = { shop_id: 1 }
beforeEach ->
module('admin.subscriptions')
inject ($controller, $rootScope, _StatusMessage_) ->
scope = $rootScope
scope.object = subscription
StatusMessage = _StatusMessage_
$controller 'ProductsPanelController', {$scope: scope, StatusMessage: _StatusMessage_}
describe "saving subscription", ->
update_promise_resolve = null
update_promise_reject = null
update_promise = null
beforeEach ->
update_promise = new Promise (resolve, reject) ->
update_promise_resolve = resolve
update_promise_reject = reject
subscription.update = jasmine.createSpy('update').and.returnValue(update_promise)
StatusMessage.display = jasmine.createSpy('display')
it "updates subscription and updates status message while in progress and on success", ->
scope.save()
expect(subscription.update).toHaveBeenCalled()
expect(StatusMessage.display).toHaveBeenCalledWith('progress', 'Saving...')
expect(scope.saving).toEqual(true)
update_promise.then ->
expect(StatusMessage.display.calls.all()[1].args).toEqual(['success', 'Changes saved.'])
expect(scope.saving).toEqual(false)
update_promise_resolve()
it "updates status message on errors", ->
scope.save()
update_promise.catch ->
expect(StatusMessage.display.calls.all()[1].args).toEqual(['failure', 'Error saving subscription'])
expect(scope.saving).toEqual(false)
update_promise_reject("error")