Adding tests for home service

stable
Alejandro Alonso 2015-04-30 11:38:36 +02:00 committed by Juanfran
parent bb3496f3d8
commit 7e98130323
2 changed files with 123 additions and 4 deletions

View File

@ -3,11 +3,11 @@ class HomeService extends taiga.Service
constructor: (@q, @rs, @rootScope, @projectUrl) ->
@.workInProgress = Immutable.Map()
@.inProgress = false
@._inProgress = false
fetchWorkInProgress: (userId) ->
if not @.inProgress
@.inProgress = true
if not @._inProgress
@._inProgress = true
params = {
status__is_closed: false
assigned_to: userId
@ -52,7 +52,7 @@ class HomeService extends taiga.Service
}
})
@.inProgress = false
@._inProgress = false
return workPromise

View File

@ -0,0 +1,119 @@
describe "tgHome", ->
homeService = provide = timeout = null
mocks = {}
_mockResources = () ->
mocks.resources = {}
mocks.resources.userstories = {
listInAllProjects: sinon.stub()
}
mocks.resources.tasks = {
listInAllProjects: sinon.stub()
}
mocks.resources.issues = {
listInAllProjects: sinon.stub()
}
paramsAssignedTo = {
status__is_closed: false
assigned_to: 1
}
paramsWatching = {
status__is_closed: false
watchers: 1
}
mocks.thenStubAssignedToUserstories = sinon.stub()
mocks.resources.userstories.listInAllProjects.withArgs(paramsAssignedTo).returns({
then: mocks.thenStubAssignedToUserstories
})
mocks.thenStubAssignedToTasks = sinon.stub()
mocks.resources.tasks.listInAllProjects.withArgs(paramsAssignedTo).returns({
then: mocks.thenStubAssignedToTasks
})
mocks.thenStubAssignedToIssues = sinon.stub()
mocks.resources.issues.listInAllProjects.withArgs(paramsAssignedTo).returns({
then: mocks.thenStubAssignedToIssues
})
mocks.thenStubWatchingUserstories = sinon.stub()
mocks.resources.userstories.listInAllProjects.withArgs(paramsWatching).returns({
then: mocks.thenStubWatchingUserstories
})
mocks.thenStubWatchingTasks = sinon.stub()
mocks.resources.tasks.listInAllProjects.withArgs(paramsWatching).returns({
then: mocks.thenStubWatchingTasks
})
mocks.thenStubWatchingIssues = sinon.stub()
mocks.resources.issues.listInAllProjects.withArgs(paramsWatching).returns({
then: mocks.thenStubWatchingIssues
})
provide.value "$tgResources", mocks.resources
_mockProjectUrl = () ->
mocks.projectUrl = {get: sinon.stub()}
mocks.projectUrl.get = (project) ->
return "url-" + project.id
provide.value "$projectUrl", mocks.projectUrl
_inject = (callback) ->
inject (_$q_, _$tgResources_, _$rootScope_, _$projectUrl_, _$timeout_, _tgHomeService_) ->
timeout = _$timeout_
homeService = _tgHomeService_
callback() if callback
_mocks = () ->
module ($provide) ->
provide = $provide
_mockResources()
_mockProjectUrl()
return null
_setup = ->
_mocks()
beforeEach ->
module "taigaHome"
_setup()
_inject()
describe "fetch items", ->
it "work in progress filled", () ->
homeService.fetchWorkInProgress(1)
mocks.thenStubAssignedToUserstories.callArg(0, [{"id": 1}])
mocks.thenStubAssignedToTasks.callArg(0, [{"id": 2}])
mocks.thenStubAssignedToIssues.callArg(0, [{"id": 3}])
mocks.thenStubWatchingUserstories.callArg(0, [{"id": 4}])
mocks.thenStubWatchingTasks.callArg(0, [{"id": 5}])
mocks.thenStubWatchingIssues.callArg(0, [{"id": 6}])
timeout.flush()
expect(homeService.workInProgress.toJS()).to.be.eql({
assignedTo: {
userStories: [{"id": 1}]
tasks: [{"id": 2}]
issues: [{"id": 3}]
}
watching: {
userStories: [{"id": 4}]
tasks: [{"id": 5}]
issues: [{"id": 6}]
}
})
it "_inProgress change to false when tgResources end", () ->
homeService.fetchWorkInProgress(1)
expect(homeService._inProgress).to.be.true
timeout.flush()
expect(homeService._inProgress).to.be.false