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