Fix epics module unit tests
parent
7848cf826e
commit
1d22477410
|
@ -39,7 +39,6 @@ class CreateEpicController
|
|||
|
||||
@.newEpic = {
|
||||
color: getRandomDefaultColor()
|
||||
project: @.project.id
|
||||
status: @.project.default_epic_status
|
||||
tags: []
|
||||
}
|
||||
|
|
|
@ -23,42 +23,32 @@ describe "EpicRow", ->
|
|||
controller = null
|
||||
mocks = {}
|
||||
|
||||
_mockTgResources = () ->
|
||||
mocks.tgResources = {
|
||||
epics: {
|
||||
post: sinon.stub()
|
||||
}
|
||||
}
|
||||
|
||||
provide.value "tgResources", mocks.tgResources
|
||||
|
||||
_mockTgConfirm = () ->
|
||||
mocks.tgConfirm = {
|
||||
notify: sinon.stub()
|
||||
}
|
||||
provide.value "$tgConfirm", mocks.tgConfirm
|
||||
|
||||
_mockTgAttachmentsService = () ->
|
||||
mocks.tgAttachmentsService = {
|
||||
upload: sinon.stub()
|
||||
_mockTgProjectService = () ->
|
||||
mocks.tgProjectService = {
|
||||
project: {
|
||||
toJS: sinon.stub()
|
||||
}
|
||||
provide.value "tgAttachmentsService", mocks.tgAttachmentsService
|
||||
|
||||
_mockQ = () ->
|
||||
mocks.q = {
|
||||
all: sinon.spy()
|
||||
}
|
||||
provide.value "tgProjectService", mocks.tgProjectService
|
||||
|
||||
provide.value "$q", mocks.q
|
||||
|
||||
_mockTgEpicsService = () ->
|
||||
mocks.tgEpicsService = {
|
||||
createEpic: sinon.stub()
|
||||
}
|
||||
provide.value "tgEpicsService", mocks.tgEpicsService
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
_mockTgResources()
|
||||
_mockTgConfirm()
|
||||
_mockTgAttachmentsService()
|
||||
_mockQ()
|
||||
_mockTgProjectService()
|
||||
_mockTgEpicsService()
|
||||
return null
|
||||
|
||||
beforeEach ->
|
||||
|
@ -70,8 +60,11 @@ describe "EpicRow", ->
|
|||
controller = $controller
|
||||
|
||||
it "create Epic with invalid form", () ->
|
||||
mocks.tgProjectService.project.toJS.withArgs().returns(
|
||||
{id: 1, default_epic_status: 1}
|
||||
)
|
||||
|
||||
data = {
|
||||
project: {id: 1, default_epic_status: 1}
|
||||
validateForm: sinon.stub()
|
||||
setFormErrors: sinon.stub()
|
||||
onCreateEpic: sinon.stub()
|
||||
|
@ -84,11 +77,14 @@ describe "EpicRow", ->
|
|||
createEpicCtrl.createEpic()
|
||||
|
||||
expect(data.validateForm).have.been.called
|
||||
expect(mocks.tgResources.epics.post).not.have.been.called
|
||||
expect(mocks.tgEpicsService.createEpic).not.have.been.called
|
||||
|
||||
it "create Epic successfully", (done) ->
|
||||
mocks.tgProjectService.project.toJS.withArgs().returns(
|
||||
{id: 1, default_epic_status: 1}
|
||||
)
|
||||
|
||||
data = {
|
||||
project: {id: 1, default_epic_status: 1}
|
||||
validateForm: sinon.stub()
|
||||
setFormErrors: sinon.stub()
|
||||
onCreateEpic: sinon.stub()
|
||||
|
@ -97,12 +93,16 @@ describe "EpicRow", ->
|
|||
createEpicCtrl.attachments = Immutable.List([{file: "file1"}, {file: "file2"}])
|
||||
|
||||
data.validateForm.withArgs().returns(true)
|
||||
mocks.tgResources.epics.post.withArgs(createEpicCtrl.newEpic).promise().resolve(
|
||||
mocks.tgEpicsService.createEpic
|
||||
.withArgs(
|
||||
createEpicCtrl.newEpic,
|
||||
createEpicCtrl.attachments)
|
||||
.promise()
|
||||
.resolve(
|
||||
{data: {id: 1, project: 1}}
|
||||
)
|
||||
|
||||
createEpicCtrl.createEpic().then () ->
|
||||
expect(data.validateForm).have.been.called
|
||||
expect(mocks.tgAttachmentsService.upload).have.been.calledTwice
|
||||
expect(createEpicCtrl.onCreateEpic).have.been.called
|
||||
done()
|
||||
|
|
|
@ -40,13 +40,13 @@ class EpicRowController
|
|||
if @.epic.getIn(['status_extra_info', 'is_closed']) == true
|
||||
@.percentage = "100%"
|
||||
else
|
||||
@.opened = @.epic.getIn(['user_stories_counts', 'opened'])
|
||||
@.closed = @.epic.getIn(['user_stories_counts', 'closed'])
|
||||
@.total = @.opened + @.closed
|
||||
if @.total == 0
|
||||
opened = @.epic.getIn(['user_stories_counts', 'opened'])
|
||||
closed = @.epic.getIn(['user_stories_counts', 'closed'])
|
||||
total = opened + closed
|
||||
if total == 0
|
||||
@.percentage = "0%"
|
||||
else
|
||||
@.percentage = "#{@.closed * 100 / @.total}%"
|
||||
@.percentage = "#{closed * 100 / total}%"
|
||||
|
||||
canEditEpics: () ->
|
||||
return @projectService.hasPermission("modify_epic")
|
||||
|
|
|
@ -23,31 +23,34 @@ describe "EpicRow", ->
|
|||
controller = null
|
||||
mocks = {}
|
||||
|
||||
_mockTgResources = () ->
|
||||
mocks.tgResources = {
|
||||
epics: {
|
||||
patch: sinon.stub()
|
||||
},
|
||||
userstories: {
|
||||
listInEpic: sinon.stub()
|
||||
}
|
||||
}
|
||||
|
||||
provide.value "tgResources", mocks.tgResources
|
||||
|
||||
_mockTgConfirm = () ->
|
||||
mocks.tgConfirm = {
|
||||
notify: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$tgConfirm", mocks.tgConfirm
|
||||
|
||||
_mockTgProjectService = () ->
|
||||
mocks.tgProjectService = {
|
||||
project: {
|
||||
toJS: sinon.stub()
|
||||
}
|
||||
}
|
||||
provide.value "tgProjectService", mocks.tgProjectService
|
||||
|
||||
_mockTgEpicsService = () ->
|
||||
mocks.tgEpicsService = {
|
||||
listRelatedUserStories: sinon.stub()
|
||||
updateEpicStatus: sinon.stub()
|
||||
updateEpicAssignedTo: sinon.stub()
|
||||
}
|
||||
provide.value "tgEpicsService", mocks.tgEpicsService
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
_mockTgResources()
|
||||
_mockTgConfirm()
|
||||
|
||||
_mockTgProjectService()
|
||||
_mockTgEpicsService()
|
||||
return null
|
||||
|
||||
beforeEach ->
|
||||
|
@ -58,16 +61,9 @@ describe "EpicRow", ->
|
|||
inject ($controller) ->
|
||||
controller = $controller
|
||||
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
EpicRowCtrl.displayUserStories = false
|
||||
EpicRowCtrl.displayAssignedTo = false
|
||||
EpicRowCtrl.loadingStatus = false
|
||||
|
||||
it "calculate progress bar in open US", () ->
|
||||
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
status_extra_info: {
|
||||
is_closed: false
|
||||
}
|
||||
|
@ -76,16 +72,14 @@ describe "EpicRow", ->
|
|||
closed: 10
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
EpicRowCtrl._calculateProgressBar()
|
||||
expect(EpicRowCtrl.opened).to.be.equal(10)
|
||||
expect(EpicRowCtrl.closed).to.be.equal(10)
|
||||
expect(EpicRowCtrl.total).to.be.equal(20)
|
||||
expect(EpicRowCtrl.percentage).to.be.equal("50%")
|
||||
ctrl._calculateProgressBar()
|
||||
expect(ctrl.percentage).to.be.equal("50%")
|
||||
|
||||
it "calculate progress bar in zero US", () ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
status_extra_info: {
|
||||
is_closed: false
|
||||
}
|
||||
|
@ -94,147 +88,112 @@ describe "EpicRow", ->
|
|||
closed: 0
|
||||
}
|
||||
})
|
||||
EpicRowCtrl._calculateProgressBar()
|
||||
expect(EpicRowCtrl.opened).to.be.equal(0)
|
||||
expect(EpicRowCtrl.closed).to.be.equal(0)
|
||||
expect(EpicRowCtrl.total).to.be.equal(0)
|
||||
expect(EpicRowCtrl.percentage).to.be.equal("0%")
|
||||
}
|
||||
expect(ctrl.percentage).to.be.equal("0%")
|
||||
|
||||
it "calculate progress bar in zero US", () ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
status_extra_info: {
|
||||
is_closed: true
|
||||
}
|
||||
})
|
||||
EpicRowCtrl._calculateProgressBar()
|
||||
expect(EpicRowCtrl.percentage).to.be.equal("100%")
|
||||
}
|
||||
expect(ctrl.percentage).to.be.equal("100%")
|
||||
|
||||
it "Update Epic Status Success", (done) ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
id: 1,
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
id: 1
|
||||
version: 1
|
||||
})
|
||||
|
||||
EpicRowCtrl.patch = {
|
||||
'status': 'new',
|
||||
'version': EpicRowCtrl.epic.get('version')
|
||||
}
|
||||
|
||||
EpicRowCtrl.loadingStatus = true
|
||||
EpicRowCtrl.onUpdateEpic = sinon.stub()
|
||||
statusId = 1
|
||||
|
||||
promise = mocks.tgResources.epics.patch.withArgs(EpicRowCtrl.epic.get('id'), EpicRowCtrl.patch).promise().resolve()
|
||||
promise = mocks.tgEpicsService.updateEpicStatus
|
||||
.withArgs(ctrl.epic, statusId)
|
||||
.promise()
|
||||
.resolve()
|
||||
|
||||
status = "new"
|
||||
EpicRowCtrl.updateEpicStatus(status).then () ->
|
||||
expect(EpicRowCtrl.loadingStatus).to.be.false
|
||||
expect(EpicRowCtrl.displayStatusList).to.be.false
|
||||
expect(EpicRowCtrl.onUpdateEpic).to.be.called
|
||||
ctrl.loadingStatus = true
|
||||
ctrl.displayStatusList = true
|
||||
|
||||
ctrl.updateStatus(statusId).then () ->
|
||||
expect(ctrl.loadingStatus).to.be.false
|
||||
expect(ctrl.displayStatusList).to.be.false
|
||||
done()
|
||||
|
||||
it "Update Epic Status Error", (done) ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
id: 1,
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
id: 1
|
||||
version: 1
|
||||
})
|
||||
|
||||
EpicRowCtrl.patch = {
|
||||
'status': 'new',
|
||||
'version': EpicRowCtrl.epic.get('version')
|
||||
}
|
||||
|
||||
EpicRowCtrl.loadingStatus = true
|
||||
EpicRowCtrl.onUpdateEpic = sinon.stub()
|
||||
statusId = 1
|
||||
|
||||
promise = mocks.tgResources.epics.patch.withArgs(EpicRowCtrl.epic.get('id'), EpicRowCtrl.patch).promise().reject(new Error('error'))
|
||||
promise = mocks.tgEpicsService.updateEpicStatus
|
||||
.withArgs(ctrl.epic, statusId)
|
||||
.promise()
|
||||
.reject(new Error('error'))
|
||||
|
||||
status = "new"
|
||||
EpicRowCtrl.updateEpicStatus(status).then () ->
|
||||
ctrl.updateStatus(statusId).then () ->
|
||||
expect(ctrl.loadingStatus).to.be.false
|
||||
expect(ctrl.displayStatusList).to.be.false
|
||||
expect(mocks.tgConfirm.notify).have.been.calledWith('error')
|
||||
done()
|
||||
|
||||
it "display User Stories", (done) ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
|
||||
EpicRowCtrl.displayUserStories = false
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
id: 1
|
||||
})
|
||||
data = true
|
||||
}
|
||||
|
||||
promise = mocks.tgResources.userstories.listInEpic.withArgs(EpicRowCtrl.epic.get('id')).promise().resolve(data)
|
||||
ctrl.displayUserStories = false
|
||||
|
||||
EpicRowCtrl.requestUserStories(EpicRowCtrl.epic).then () ->
|
||||
expect(EpicRowCtrl.displayUserStories).to.be.true
|
||||
expect(EpicRowCtrl.epicStories).is.equal(data)
|
||||
data = Immutable.List()
|
||||
|
||||
promise = mocks.tgEpicsService.listRelatedUserStories
|
||||
.withArgs(ctrl.epic)
|
||||
.promise()
|
||||
.resolve(data)
|
||||
|
||||
ctrl.toggleUserStoryList().then () ->
|
||||
expect(ctrl.displayUserStories).to.be.true
|
||||
expect(ctrl.epicStories).is.equal(data)
|
||||
done()
|
||||
|
||||
it "display User Stories error", (done) ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
EpicRowCtrl.displayUserStories = false
|
||||
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
id: 1
|
||||
})
|
||||
}
|
||||
|
||||
promise = mocks.tgResources.userstories.listInEpic.withArgs(EpicRowCtrl.epic.get('id')).promise().reject(new Error('error'))
|
||||
ctrl.displayUserStories = false
|
||||
|
||||
EpicRowCtrl.requestUserStories(EpicRowCtrl.epic).then () ->
|
||||
promise = mocks.tgEpicsService.listRelatedUserStories
|
||||
.withArgs(ctrl.epic)
|
||||
.promise()
|
||||
.reject(new Error('error'))
|
||||
|
||||
ctrl.toggleUserStoryList().then () ->
|
||||
expect(ctrl.displayUserStories).to.be.false
|
||||
expect(mocks.tgConfirm.notify).have.been.calledWith('error')
|
||||
done()
|
||||
|
||||
it "DO NOT display User Stories", () ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
EpicRowCtrl.displayUserStories = true
|
||||
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
it "display User Stories error", ->
|
||||
ctrl = controller "EpicRowCtrl", null, {
|
||||
epic: Immutable.fromJS({
|
||||
id: 1
|
||||
})
|
||||
EpicRowCtrl.requestUserStories(EpicRowCtrl.epic)
|
||||
expect(EpicRowCtrl.displayUserStories).to.be.false
|
||||
|
||||
it "On remove assigned", () ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
id: 1,
|
||||
version: 1
|
||||
})
|
||||
EpicRowCtrl.patch = {
|
||||
'assigned_to': null,
|
||||
'version': EpicRowCtrl.epic.get('version')
|
||||
}
|
||||
EpicRowCtrl.onUpdateEpic = sinon.stub()
|
||||
|
||||
promise = mocks.tgResources.epics.patch.withArgs(EpicRowCtrl.epic.get('id'), EpicRowCtrl.patch).promise().resolve()
|
||||
|
||||
EpicRowCtrl.onRemoveAssigned().then () ->
|
||||
expect(EpicRowCtrl.onUpdateEpic).to.have.been.called
|
||||
|
||||
it "On assign to", (done) ->
|
||||
EpicRowCtrl = controller "EpicRowCtrl"
|
||||
EpicRowCtrl.epic = Immutable.fromJS({
|
||||
id: 1,
|
||||
version: 1
|
||||
})
|
||||
id = EpicRowCtrl.epic.get('id')
|
||||
version = EpicRowCtrl.epic.get('version')
|
||||
member = {
|
||||
id: 1
|
||||
}
|
||||
EpicRowCtrl.patch = {
|
||||
assigned_to: member.id
|
||||
version: EpicRowCtrl.epic.get('version')
|
||||
}
|
||||
|
||||
EpicRowCtrl.onUpdateEpic = sinon.stub()
|
||||
ctrl.displayUserStories = true
|
||||
|
||||
promise = mocks.tgResources.epics.patch.withArgs(id, EpicRowCtrl.patch).promise().resolve(member)
|
||||
EpicRowCtrl.onAssignTo(member).then () ->
|
||||
expect(EpicRowCtrl.onUpdateEpic).to.have.been.called
|
||||
expect(mocks.tgConfirm.notify).have.been.calledWith('success')
|
||||
done()
|
||||
ctrl.toggleUserStoryList()
|
||||
|
||||
expect(ctrl.displayUserStories).to.be.false
|
||||
|
|
|
@ -39,16 +39,16 @@ class EpicsDashboardController
|
|||
taiga.defineImmutableProperty @, 'project', () => return @projectService.project
|
||||
taiga.defineImmutableProperty @, 'epics', () => return @epicsService.epics
|
||||
|
||||
@._loadInitialData()
|
||||
|
||||
_loadInitialData: () ->
|
||||
loadInitialData: () ->
|
||||
@epicsService.clear()
|
||||
@projectService.setProjectBySlug(@params.pslug)
|
||||
return @projectService.setProjectBySlug(@params.pslug)
|
||||
.then () =>
|
||||
if not @.project.get("is_epics_activated") or not @projectService.hasPermission("view_epics")
|
||||
@errorHandlingService.permissionDenied()
|
||||
if not @projectService.isEpicsDashboardEnabled()
|
||||
return @errorHandlingService.notFound()
|
||||
if not @projectService.hasPermission("view_epics")
|
||||
return @errorHandlingService.permissionDenied()
|
||||
|
||||
@epicsService.fetchEpics()
|
||||
return @epicsService.fetchEpics()
|
||||
|
||||
canCreateEpics: () ->
|
||||
return @projectService.hasPermission("add_epic")
|
||||
|
|
|
@ -23,41 +23,38 @@ describe "EpicsDashboard", ->
|
|||
controller = null
|
||||
mocks = {}
|
||||
|
||||
_mockTgResources = () ->
|
||||
mocks.tgResources = {
|
||||
projects: {
|
||||
getBySlug: sinon.stub()
|
||||
}
|
||||
}
|
||||
|
||||
provide.value "$tgResources", mocks.tgResources
|
||||
|
||||
_mockTgResourcesNew = () ->
|
||||
mocks.tgResourcesNew = {
|
||||
epics: {
|
||||
list: sinon.stub()
|
||||
}
|
||||
}
|
||||
|
||||
provide.value "tgResources", mocks.tgResourcesNew
|
||||
|
||||
_mockTgConfirm = () ->
|
||||
mocks.tgConfirm = {
|
||||
notify: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$tgConfirm", mocks.tgConfirm
|
||||
|
||||
_mockTgProjectService = () ->
|
||||
mocks.tgProjectService = {
|
||||
setProjectBySlug: sinon.stub()
|
||||
hasPermission: sinon.stub()
|
||||
isEpicsDashboardEnabled: sinon.stub()
|
||||
}
|
||||
provide.value "tgProjectService", mocks.tgProjectService
|
||||
|
||||
_mockTgEpicsService = () ->
|
||||
mocks.tgEpicsService = {
|
||||
clear: sinon.stub()
|
||||
fetchEpics: sinon.stub()
|
||||
}
|
||||
provide.value "tgEpicsService", mocks.tgEpicsService
|
||||
|
||||
_mockRouteParams = () ->
|
||||
mocks.routeparams = {
|
||||
mocks.routeParams = {
|
||||
pslug: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$routeParams", mocks.routeparams
|
||||
provide.value "$routeParams", mocks.routeParams
|
||||
|
||||
_mockTgErrorHandlingService = () ->
|
||||
mocks.tgErrorHandlingService = {
|
||||
permissionDenied: sinon.stub()
|
||||
notFound: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "tgErrorHandlingService", mocks.tgErrorHandlingService
|
||||
|
@ -76,23 +73,16 @@ describe "EpicsDashboard", ->
|
|||
|
||||
provide.value "lightboxService", mocks.lightboxService
|
||||
|
||||
_mockTgConfirm = () ->
|
||||
mocks.tgConfirm = {
|
||||
notify: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$tgConfirm", mocks.tgConfirm
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
_mockTgResources()
|
||||
_mockTgResourcesNew()
|
||||
_mockTgConfirm()
|
||||
_mockTgProjectService()
|
||||
_mockTgEpicsService()
|
||||
_mockRouteParams()
|
||||
_mockTgErrorHandlingService()
|
||||
_mockTgLightboxFactory()
|
||||
_mockLightboxService()
|
||||
_mockTgConfirm()
|
||||
|
||||
return null
|
||||
|
||||
|
@ -104,39 +94,70 @@ describe "EpicsDashboard", ->
|
|||
inject ($controller) ->
|
||||
controller = $controller
|
||||
|
||||
EpicsDashboardCtrl = controller "EpicsDashboardCtrl"
|
||||
it "load data because epics panel is enabled and user has permissions", (done) ->
|
||||
ctrl = controller("EpicsDashboardCtrl")
|
||||
|
||||
it "load projects", (done) ->
|
||||
EpicsDashboardCtrl = controller "EpicsDashboardCtrl"
|
||||
params = mocks.routeparams.pslug
|
||||
EpicsDashboardCtrl.loadEpics = sinon.stub()
|
||||
project = {
|
||||
is_epics_activated: false
|
||||
}
|
||||
promise = mocks.tgResources.projects.getBySlug.withArgs(params).promise().resolve(project)
|
||||
EpicsDashboardCtrl.loadProject().then () ->
|
||||
mocks.tgProjectService.setProjectBySlug
|
||||
.promise()
|
||||
.resolve("ok")
|
||||
mocks.tgProjectService.hasPermission
|
||||
.returns(true)
|
||||
mocks.tgProjectService.isEpicsDashboardEnabled
|
||||
.returns(true)
|
||||
|
||||
ctrl.loadInitialData().then () ->
|
||||
expect(mocks.tgErrorHandlingService.permissionDenied).not.have.been.called
|
||||
expect(mocks.tgErrorHandlingService.notFound).not.have.been.called
|
||||
expect(mocks.tgEpicsService.fetchEpics).have.been.called
|
||||
done()
|
||||
|
||||
it "not load data because epics panel is not enabled", (done) ->
|
||||
ctrl = controller("EpicsDashboardCtrl")
|
||||
|
||||
mocks.tgProjectService.setProjectBySlug
|
||||
.promise()
|
||||
.resolve("ok")
|
||||
mocks.tgProjectService.hasPermission
|
||||
.returns(true)
|
||||
mocks.tgProjectService.isEpicsDashboardEnabled
|
||||
.returns(false)
|
||||
|
||||
ctrl.loadInitialData().then () ->
|
||||
expect(mocks.tgErrorHandlingService.permissionDenied).not.have.been.called
|
||||
expect(mocks.tgErrorHandlingService.notFound).have.been.called
|
||||
expect(mocks.tgEpicsService.fetchEpics).not.have.been.called
|
||||
done()
|
||||
|
||||
it "not load data because user has not permissions", (done) ->
|
||||
ctrl = controller("EpicsDashboardCtrl")
|
||||
|
||||
mocks.tgProjectService.setProjectBySlug
|
||||
.promise()
|
||||
.resolve("ok")
|
||||
mocks.tgProjectService.hasPermission
|
||||
.returns(false)
|
||||
mocks.tgProjectService.isEpicsDashboardEnabled
|
||||
.returns(true)
|
||||
|
||||
ctrl.loadInitialData().then () ->
|
||||
expect(mocks.tgErrorHandlingService.permissionDenied).have.been.called
|
||||
expect(EpicsDashboardCtrl.project).is.equal(project)
|
||||
expect(EpicsDashboardCtrl.loadEpics).have.been.called
|
||||
expect(mocks.tgErrorHandlingService.notFound).not.have.been.called
|
||||
expect(mocks.tgEpicsService.fetchEpics).not.have.been.called
|
||||
done()
|
||||
|
||||
it "load epics", (done) ->
|
||||
EpicsDashboardCtrl = controller "EpicsDashboardCtrl"
|
||||
EpicsDashboardCtrl.project = {
|
||||
id: 1
|
||||
}
|
||||
epics = {
|
||||
id: 1
|
||||
}
|
||||
promise = mocks.tgResourcesNew.epics.list.withArgs(EpicsDashboardCtrl.project.id).promise().resolve(epics)
|
||||
EpicsDashboardCtrl.loadEpics().then () ->
|
||||
expect(EpicsDashboardCtrl.epics).is.equal(epics)
|
||||
done()
|
||||
it "not load data because epics panel is not enabled and user has not permissions", (done) ->
|
||||
ctrl = controller("EpicsDashboardCtrl")
|
||||
|
||||
it "on create epic", () ->
|
||||
EpicsDashboardCtrl = controller "EpicsDashboardCtrl"
|
||||
EpicsDashboardCtrl.loadEpics = sinon.stub()
|
||||
EpicsDashboardCtrl._onCreateEpic()
|
||||
expect(mocks.lightboxService.closeAll).have.been.called
|
||||
expect(mocks.tgConfirm.notify).have.been.calledWith("success")
|
||||
expect(EpicsDashboardCtrl.loadEpics).have.been.called
|
||||
mocks.tgProjectService.setProjectBySlug
|
||||
.promise()
|
||||
.resolve("ok")
|
||||
mocks.tgProjectService.hasPermission
|
||||
.returns(false)
|
||||
mocks.tgProjectService.isEpicsDashboardEnabled
|
||||
.returns(false)
|
||||
|
||||
ctrl.loadInitialData().then () ->
|
||||
expect(mocks.tgErrorHandlingService.permissionDenied).not.have.been.called
|
||||
expect(mocks.tgErrorHandlingService.notFound).have.been.called
|
||||
expect(mocks.tgEpicsService.fetchEpics).not.have.been.called
|
||||
done()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.wrapper(ng-init="vm.loadProject()")
|
||||
.wrapper(ng-init="vm.loadInitialData()")
|
||||
tg-project-menu
|
||||
section.main(role="main")
|
||||
header.header-with-actions
|
||||
|
|
|
@ -23,10 +23,23 @@ describe "EpicTable", ->
|
|||
controller = null
|
||||
mocks = {}
|
||||
|
||||
_mockTgConfirm = () ->
|
||||
mocks.tgConfirm = {
|
||||
notify: sinon.stub()
|
||||
}
|
||||
provide.value "$tgConfirm", mocks.tgConfirm
|
||||
|
||||
_mockTgEpicsService = () ->
|
||||
mocks.tgEpicsService = {
|
||||
createEpic: sinon.stub()
|
||||
}
|
||||
provide.value "tgEpicsService", mocks.tgEpicsService
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
|
||||
_mockTgConfirm()
|
||||
_mockTgEpicsService()
|
||||
return null
|
||||
|
||||
beforeEach ->
|
||||
|
@ -38,36 +51,7 @@ describe "EpicTable", ->
|
|||
controller = $controller
|
||||
|
||||
it "toggle table options", () ->
|
||||
data = {
|
||||
project: {
|
||||
my_permissions: [
|
||||
'modify_epic'
|
||||
]
|
||||
}
|
||||
}
|
||||
epicTableCtrl = controller "EpicsTableCtrl", null, data
|
||||
epicTableCtrl = controller "EpicsTableCtrl"
|
||||
epicTableCtrl.displayOptions = true
|
||||
epicTableCtrl.toggleEpicTableOptions()
|
||||
expect(epicTableCtrl.displayOptions).to.be.false
|
||||
|
||||
it "can edit", () ->
|
||||
data = {
|
||||
project: {
|
||||
my_permissions: [
|
||||
'modify_epic'
|
||||
]
|
||||
}
|
||||
}
|
||||
epicTableCtrl = controller "EpicsTableCtrl", null, data
|
||||
expect(epicTableCtrl.permissions.canEdit).to.be.true
|
||||
|
||||
it "can NOT edit", () ->
|
||||
data = {
|
||||
project: {
|
||||
my_permissions: [
|
||||
'modify_us'
|
||||
]
|
||||
}
|
||||
}
|
||||
epicTableCtrl = controller "EpicsTableCtrl", null, data
|
||||
expect(epicTableCtrl.permissions.canEdit).to.be.false
|
||||
|
|
|
@ -32,11 +32,17 @@ describe "RelatedUserStories", ->
|
|||
|
||||
provide.value "tgResources", mocks.tgResources
|
||||
|
||||
_mockTgEpicsService = () ->
|
||||
mocks.tgEpicsService = {
|
||||
}
|
||||
|
||||
provide.value "tgEpicsService", mocks.tgEpicsService
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
_mockTgResources()
|
||||
|
||||
_mockTgEpicsService()
|
||||
return null
|
||||
|
||||
beforeEach ->
|
||||
|
@ -47,20 +53,19 @@ describe "RelatedUserStories", ->
|
|||
inject ($controller) ->
|
||||
controller = $controller
|
||||
|
||||
RelatedUserStoriesCtrl = controller "RelatedUserStoriesCtrl"
|
||||
|
||||
it "load related userstories", (done) ->
|
||||
ctrl = controller "RelatedUserStoriesCtrl"
|
||||
userstories = Immutable.fromJS([
|
||||
{
|
||||
id: 1
|
||||
}
|
||||
])
|
||||
|
||||
RelatedUserStoriesCtrl.epic = Immutable.fromJS({
|
||||
ctrl.epic = Immutable.fromJS({
|
||||
id: 66
|
||||
})
|
||||
|
||||
promise = mocks.tgResources.userstories.listInEpic.withArgs(66).promise().resolve(userstories)
|
||||
RelatedUserStoriesCtrl.loadRelatedUserstories().then () ->
|
||||
expect(RelatedUserStoriesCtrl.userstories).is.equal(userstories)
|
||||
ctrl.loadRelatedUserstories().then () ->
|
||||
expect(ctrl.userstories).is.equal(userstories)
|
||||
done()
|
||||
|
|
|
@ -36,6 +36,12 @@ class ProjectService
|
|||
taiga.defineImmutableProperty @, "sectionsBreadcrumb", () => return @._sectionsBreadcrumb
|
||||
taiga.defineImmutableProperty @, "activeMembers", () => return @._activeMembers
|
||||
|
||||
cleanProject: () ->
|
||||
@._project = null
|
||||
@._activeMembers = Immutable.List()
|
||||
@._section = null
|
||||
@._sectionsBreadcrumb = Immutable.List()
|
||||
|
||||
setSection: (section) ->
|
||||
@._section = section
|
||||
|
||||
|
@ -44,6 +50,10 @@ class ProjectService
|
|||
else
|
||||
@._sectionsBreadcrumb = Immutable.List()
|
||||
|
||||
setProject: (project) ->
|
||||
@._project = project
|
||||
@._activeMembers = @._project.get('members').filter (member) -> member.get('is_active')
|
||||
|
||||
setProjectBySlug: (pslug) ->
|
||||
return new Promise (resolve, reject) =>
|
||||
if !@.project || @.project.get('slug') != pslug
|
||||
|
@ -57,23 +67,15 @@ class ProjectService
|
|||
|
||||
else resolve()
|
||||
|
||||
setProject: (project) ->
|
||||
@._project = project
|
||||
@._activeMembers = @._project.get('members').filter (member) -> member.get('is_active')
|
||||
|
||||
cleanProject: () ->
|
||||
@._project = null
|
||||
@._activeMembers = Immutable.List()
|
||||
@._section = null
|
||||
@._sectionsBreadcrumb = Immutable.List()
|
||||
|
||||
hasPermission: (permission) ->
|
||||
return @._project.get('my_permissions').indexOf(permission) != -1
|
||||
|
||||
fetchProject: () ->
|
||||
pslug = @.project.get('slug')
|
||||
|
||||
return @projectsService.getProjectBySlug(pslug).then (project) => @.setProject(project)
|
||||
|
||||
hasPermission: (permission) ->
|
||||
return @._project.get('my_permissions').indexOf(permission) != -1
|
||||
|
||||
isEpicsDashboardEnabled: ->
|
||||
return @._project.get("is_epics_activated")
|
||||
|
||||
angular.module("taigaCommon").service("tgProjectService", ProjectService)
|
||||
|
|
Loading…
Reference in New Issue