Tests EPICS dashboard

stable
Xavier Julián 2016-08-04 17:59:51 +02:00 committed by David Barragán Merino
parent 479d6f02e6
commit 9ed2e3abf2
13 changed files with 482 additions and 26 deletions

View File

@ -111,6 +111,7 @@ describe "ProjectMenu", ->
menu = ctrl.menu.toJS()
expect(menu).to.be.eql({
epics: false,
backlog: false,
kanban: false,
issues: false,
@ -119,11 +120,12 @@ describe "ProjectMenu", ->
it "all options enabled", () ->
project = Immutable.fromJS({
is_epics_activated: true,
is_backlog_activated: true,
is_kanban_activated: true,
is_issues_activated: true,
is_wiki_activated: true,
my_permissions: ["view_us", "view_issues", "view_wiki_pages"]
my_permissions: ["view_epics", "view_us", "view_issues", "view_wiki_pages"]
})
mocks.projectService.project = project
@ -136,6 +138,7 @@ describe "ProjectMenu", ->
menu = ctrl.menu.toJS()
expect(menu).to.be.eql({
epics: true,
backlog: true,
kanban: true,
issues: true,
@ -144,6 +147,7 @@ describe "ProjectMenu", ->
it "all options disabled because the user doesn't have permissions", () ->
project = Immutable.fromJS({
is_epics_activated: true,
is_backlog_activated: true,
is_kanban_activated: true,
is_issues_activated: true,
@ -161,6 +165,7 @@ describe "ProjectMenu", ->
menu = ctrl.menu.toJS()
expect(menu).to.be.eql({
epics: false,
backlog: false,
kanban: false,
issues: false,

View File

@ -27,40 +27,40 @@ class EpicRowController
constructor: (@rs, @confirm) ->
@.displayUserStories = false
@._calculateProgressBar()
@.displayAssignedTo = false
@.loadingStatus = false
_calculateProgressBar: () ->
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}%"
updateEpicStatus: (status) ->
id = @.epic.get('id')
version = @.epic.get('version')
@.loadingStatus = true
@.displayStatusList = false
patch = {
'status': status,
'version': version
'version': @.epic.get('version')
}
onSuccess = =>
@.loadingStatus = false
@.onUpdateEpic()
onError = (data) =>
@confirm.notify('error')
return @rs.epics.patch(id, patch).then(onSuccess, onError)
return @rs.epics.patch(@.epic.get('id'), patch).then(onSuccess, onError)
requestUserStories: (epic) ->
if @.displayUserStories == false
id = @.epic.get('id')
if !@.displayUserStories
onSuccess = (data) =>
@.epicStories = data
@ -69,7 +69,7 @@ class EpicRowController
onError = (data) =>
@confirm.notify('error')
return @rs.userstories.listInEpic(id).then(onSuccess, onError)
return @rs.userstories.listInEpic(@.epic.get('id')).then(onSuccess, onError)
else
@.displayUserStories = false
@ -83,7 +83,6 @@ class EpicRowController
onSuccess = =>
@.onUpdateEpic()
@confirm.notify('success')
onError = (data) =>
@confirm.notify('error')

View File

@ -0,0 +1,240 @@
###
# Copyright (C) 2014-2015 Taiga Agile LLC <taiga@taiga.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: epic-row.controller.spec.coffee
###
describe "EpicRow", ->
epicRowCtrl = null
provide = null
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
_mocks = () ->
module ($provide) ->
provide = $provide
_mockTgResources()
_mockTgConfirm()
return null
beforeEach ->
module "taigaEpics"
_mocks()
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({
status_extra_info: {
is_closed: false
}
user_stories_counts: {
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
EpicRowCtrl.onUpdateEpic = sinon.stub()
promise = mocks.tgResources.epics.patch.withArgs(EpicRowCtrl.epic.get('id'), EpicRowCtrl.patch).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
done()
it "Update Epic Status Error", (done) ->
EpicRowCtrl = controller "EpicRowCtrl"
EpicRowCtrl.epic = Immutable.fromJS({
id: 1,
version: 1
})
EpicRowCtrl.patch = {
'status': 'new',
'version': EpicRowCtrl.epic.get('version')
}
EpicRowCtrl.loadingStatus = true
EpicRowCtrl.onUpdateEpic = sinon.stub()
promise = mocks.tgResources.epics.patch.withArgs(EpicRowCtrl.epic.get('id'), EpicRowCtrl.patch).promise().reject(new Error('error'))
status = "new"
EpicRowCtrl.updateEpicStatus(status).then () ->
expect(mocks.tgConfirm.notify).have.been.calledWith('error')
done()
it "display User Stories", (done) ->
EpicRowCtrl = controller "EpicRowCtrl"
EpicRowCtrl.displayUserStories = false
EpicRowCtrl.epic = Immutable.fromJS({
id: 1
})
data = true
promise = mocks.tgResources.userstories.listInEpic.withArgs(EpicRowCtrl.epic.get('id')).promise().resolve(data)
EpicRowCtrl.requestUserStories(EpicRowCtrl.epic).then () ->
expect(EpicRowCtrl.displayUserStories).to.be.true
expect(EpicRowCtrl.epicStories).is.equal(data)
done()
it "display User Stories error", (done) ->
EpicRowCtrl = controller "EpicRowCtrl"
EpicRowCtrl.displayUserStories = false
EpicRowCtrl.epic = Immutable.fromJS({
id: 1
})
promise = mocks.tgResources.userstories.listInEpic.withArgs(EpicRowCtrl.epic.get('id')).promise().reject(new Error('error'))
EpicRowCtrl.requestUserStories(EpicRowCtrl.epic).then () ->
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({
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()
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()

View File

@ -21,7 +21,11 @@ module = angular.module('taigaEpics')
EpicRowDirective = () ->
link = (scope, el, attrs, ctrl) ->
ctrl._calculateProgressBar()
return {
link: link,
templateUrl:"epics/dashboard/epic-row/epic-row.html",
controller: "EpicRowCtrl",
controllerAs: "vm",

View File

@ -44,18 +44,19 @@
span {{vm.epic.getIn(['status_extra_info', 'name'])}}
.status(
ng-if="vm.column.status && vm.permissions.canEdit"
ng-mouseleave="displayStatusList = false"
ng-mouseleave="vm.displayStatusList = false"
)
button(
ng-click="displayStatusList = true"
ng-click="vm.displayStatusList = true"
ng-style="{'color': vm.epic.getIn(['status_extra_info', 'color'])}"
tg-loading="vm.loadingStatus"
)
span {{vm.epic.getIn(['status_extra_info', 'name'])}}
tg-svg(
svg-icon="icon-arrow-down"
)
ul.epic-statuses(ng-show="displayStatusList")
ul.epic-statuses(ng-if="vm.displayStatusList")
li(
ng-repeat="status in vm.project.epic_statuses | orderBy:'order'"
ng-click="vm.updateEpicStatus(status.id)"

View File

@ -19,8 +19,8 @@
background: rgba($red-light, .5);
}
&.is-closed {
.name {
color: $gray-light;
.name a {
color: lighten($gray-light, 15%);
text-decoration: line-through;
}
}

View File

@ -32,10 +32,9 @@ class EpicsDashboardController
constructor: (@rs, @resources, @params, @errorHandlingService, @lightboxFactory, @lightboxService, @confirm) ->
@.sectionName = "Epics"
@._loadProject()
@.createEpic = false
_loadProject: () ->
loadProject: () ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.is_epics_activated
@errorHandlingService.permissionDenied()
@ -43,7 +42,6 @@ class EpicsDashboardController
@.loadEpics()
loadEpics: () ->
console.log 'reload'
projectId = @.project.id
return @resources.epics.list(projectId).then (epics) =>
@.epics = epics

View File

@ -0,0 +1,142 @@
###
# Copyright (C) 2014-2015 Taiga Agile LLC <taiga@taiga.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: epic-row.controller.spec.coffee
###
describe "EpicsDashboard", ->
EpicsDashboardCtrl = null
provide = null
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
_mockRouteParams = () ->
mocks.routeparams = {
pslug: sinon.stub()
}
provide.value "$routeParams", mocks.routeparams
_mockTgErrorHandlingService = () ->
mocks.tgErrorHandlingService = {
permissionDenied: sinon.stub()
}
provide.value "tgErrorHandlingService", mocks.tgErrorHandlingService
_mockTgLightboxFactory = () ->
mocks.tgLightboxFactory = {
create: sinon.stub()
}
provide.value "tgLightboxFactory", mocks.tgLightboxFactory
_mockLightboxService = () ->
mocks.lightboxService = {
closeAll: sinon.stub()
}
provide.value "lightboxService", mocks.lightboxService
_mockTgConfirm = () ->
mocks.tgConfirm = {
notify: sinon.stub()
}
provide.value "$tgConfirm", mocks.tgConfirm
_mocks = () ->
module ($provide) ->
provide = $provide
_mockTgResources()
_mockTgResourcesNew()
_mockRouteParams()
_mockTgErrorHandlingService()
_mockTgLightboxFactory()
_mockLightboxService()
_mockTgConfirm()
return null
beforeEach ->
module "taigaEpics"
_mocks()
inject ($controller) ->
controller = $controller
EpicsDashboardCtrl = 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 () ->
expect(mocks.tgErrorHandlingService.permissionDenied).have.been.called
expect(EpicsDashboardCtrl.project).is.equal(project)
expect(EpicsDashboardCtrl.loadEpics).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 "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

View File

@ -1,4 +1,4 @@
.wrapper()
.wrapper(ng-init="vm.loadProject()")
tg-project-menu
section.main(role="main")
header.header-with-actions

View File

@ -34,7 +34,6 @@ class EpicsTableController
status: true,
progress: true
}
@._checkPermissions()
toggleEpicTableOptions: () ->
@.displayOptions = !@.displayOptions

View File

@ -0,0 +1,64 @@
###
# Copyright (C) 2014-2015 Taiga Agile LLC <taiga@taiga.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: epic-row.controller.spec.coffee
###
describe "EpicTable", ->
epicTableCtrl = null
provide = null
controller = null
mocks = {}
_mocks = () ->
module ($provide) ->
provide = $provide
return null
beforeEach ->
module "taigaEpics"
_mocks()
inject ($controller) ->
controller = $controller
it "toggle table options", () ->
epicTableCtrl = controller "EpicsTableCtrl"
epicTableCtrl.displayOptions = true
epicTableCtrl.toggleEpicTableOptions()
expect(epicTableCtrl.displayOptions).to.be.false
it "can edit", () ->
epicTableCtrl = controller "EpicsTableCtrl"
epicTableCtrl.project = {
my_permissions: [
'modify_epic'
]
}
epicTableCtrl._checkPermissions()
expect(epicTableCtrl.permissions.canEdit).to.be.true
it "can NOT edit", () ->
epicTableCtrl = controller "EpicsTableCtrl"
epicTableCtrl.project = {
my_permissions: [
'modify_us'
]
}
epicTableCtrl._checkPermissions()
expect(epicTableCtrl.permissions.canEdit).to.be.false

View File

@ -21,7 +21,11 @@ module = angular.module('taigaEpics')
EpicsTableDirective = () ->
link = (scope, el, attrs, ctrl) ->
ctrl._checkPermissions()
return {
link: link,
templateUrl:"epics/dashboard/epics-table/epics-table.html",
controller: "EpicsTableCtrl",
controllerAs: "vm",

View File

@ -72,7 +72,7 @@ describe "tgHome", ->
_setup()
_inject()
it.only "get work in progress by user", (done) ->
it "get work in progress by user", (done) ->
userId = 3
project1 = {id: 1, name: "fake1", slug: "project-1"}