Skip to content

Commit

Permalink
ucfopen#48 Added a couple of tests for new code in widget service.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrenjaminBanklin committed Feb 27, 2019
1 parent f7f0125 commit 7c9cabd
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/js/services/srv-widget.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('widgetSrv', () => {
expect(_service.getWidgetsByType).toBeDefined()
expect(_service.getWidget).toBeDefined()
expect(_service.getWidgetInfo).toBeDefined()
expect(_service.lockWidget).toBeDefined()
expect(_service.sortWidgets).toBeDefined()
expect(_service.saveWidget).toBeDefined()
expect(_service.removeWidget).toBeDefined()
Expand Down Expand Up @@ -401,4 +402,49 @@ describe('widgetSrv', () => {
$scope.$digest() // processes promise
expect(_selectedWidgetSrv.notifyAccessDenied).toHaveBeenCalled()
})

it('rejects with a message when a widget is already locked', () => {
mockSendPromiseOnce(false)

let promiseSpy = jest.fn()
let promiseCatch = jest.fn()
_service
.lockWidget(1)
.then(promiseSpy)
.catch(promiseCatch)
$scope.$digest() // processes promise

expect(Materia.Coms.Json.send).toHaveBeenCalledWith('widget_instance_lock', [1])
expect(promiseSpy).not.toHaveBeenCalled()
expect(promiseCatch).toHaveBeenCalledWith('This widget is currently locked, you will be able to edit this widget when it is no longer being edited by somebody else.')
})

it('locks a widget', () => {
mockSendPromiseOnce(true)

let promiseSpy = jest.fn()
let promiseCatch = jest.fn()
_service
.lockWidget(1)
.then(promiseSpy)
.catch(promiseCatch)
$scope.$digest() // processes promise

expect(Materia.Coms.Json.send).toHaveBeenCalledWith('widget_instance_lock', [1])
expect(promiseSpy).toHaveBeenCalledWith(1)
expect(promiseCatch).not.toHaveBeenCalled()
})

it('checks whether a widget can be published by the current user', () => {
mockSendPromiseOnce(true)

let promiseSpy = jest.fn()
_service
.canBePublishedByCurrentUser(1)
.then(promiseSpy)
$scope.$digest() // processes promise

expect(Materia.Coms.Json.send).toHaveBeenCalledWith('widget_publish_perms_verify', [1])
expect(promiseSpy).toHaveBeenCalledWith(true)
})
})

0 comments on commit 7c9cabd

Please sign in to comment.