@ -26,9 +26,19 @@
// See doc/COPYRIGHT.rdoc for more details.
// ++
describe ( 'WorkPackagesListController' , function ( ) {
var scope , ctrl , win , testProjectService , testWorkPackageService , testQueryService ,
testPaginationService , testApiWorkPackages , testAuthorisationService ;
var expect = chai . expect ;
describe ( 'WorkPackagesListController' , ( ) = > {
var scope ;
var ctrl ;
var win ;
var wpListServiceMock ;
var testProjectService ;
var testWorkPackageService ;
var testQueryService ;
var testPaginationService ;
var testApiWorkPackages ;
var testAuthorisationService ;
var testQueries ;
var buildController ;
var stateParams = { } ;
@ -36,19 +46,18 @@ describe('WorkPackagesListController', function() {
beforeEach ( angular . mock . module ( 'openproject.api' , 'openproject.workPackages.controllers' ,
'openproject.workPackages.services' , 'ng-context-menu' , 'btford.modal' , 'openproject.layout' ,
'openproject.services' , 'openproject.wpButtons' ) ) ;
beforeEach ( angular . mock . module ( 'openproject.templates' , function ( $provide ) {
var configurationService = { } ;
configurationService . isTimezoneSet = sinon . stub ( ) . returns ( false ) ;
beforeEach ( angular . mock . module ( 'openproject.templates' , ( $provide ) = > {
var configurationService = {
isTimezoneSet : sinon.stub ( ) . returns ( false )
} ;
$provide . constant ( '$stateParams' , stateParams ) ;
$provide . constant ( 'ConfigurationService' , configurationService ) ;
} ) ) ;
beforeEach ( inject ( function ( $rootScope , $controller , $timeout , $q ) {
beforeEach ( angular . mock . inject ( ( $rootScope , $controller , $timeout , $q , $cacheFactory ) = > {
scope = $rootScope . $new ( ) ;
win = {
location : { pathname : '' }
win = {
location : { pathname : '' }
} ;
var defaultWorkPackagesData = {
@ -63,63 +72,57 @@ describe('WorkPackagesListController', function() {
var workPackagesDataByQueryId = {
meta : {
query : {
props : { id : 1 } ,
props : { id : 1 } ,
_links : [ ]
} ,
sums : [ null ]
} ,
work_packages : [ ]
} ;
var columnData = {
} ;
var availableQueryiesData = {
} ;
var columnData = { } ;
var availableQueryiesData = { } ;
var projectData = { embedded : { types : [ ] } } ;
var projectsData = [ projectData ] ;
var projectData = { embedded : { types : [ ] } } ;
var projectsData = [ projectData ] ;
testQueries = {
'1' : {
id : 1 ,
columns : [ 'type' ] ,
getSortation : function ( ) { return null ; } ,
isNew : function ( ) { return false ; }
getSortation : ( ) = > null ,
isNew : ( ) = > false
} ,
'2' : {
id : 2 ,
columns : [ 'type' ] ,
getSortation : function ( ) { return null ; } ,
isNew : function ( ) { return false ; }
getSortation : ( ) = > null ,
isNew : ( ) = > false
}
} ;
testProjectService = {
getProject : function ( ) {
return $timeout ( function ( ) {
return projectData ;
} , 10 ) ;
getProject : ( ) = > {
return $timeout ( ( ) = > projectData , 10 ) ;
} ,
getProjects : function ( ) {
return $timeout ( function ( ) {
return projectsData ;
} , 10 ) ;
getProjects : ( ) = > {
return $timeout ( ( ) = > projectsData , 10 ) ;
}
} ;
var wpCache = $cacheFactory ( 'workPackageCache' ) ;
testWorkPackageService = {
getWorkPackages : function ( ) {
return $timeout ( function ( ) {
return defaultWorkPackagesData ;
} , 10 ) ;
getWorkPackages : ( ) = > {
return $timeout ( ( ) = > defaultWorkPackagesData , 10 ) ;
} ,
getWorkPackagesByQueryId : function ( ) {
return $timeout ( function ( ) {
return workPackagesDataByQueryId ;
} , 10 ) ;
getWorkPackagesByQueryId : ( ) = > {
return $timeout ( ( ) = > workPackagesDataByQueryId , 10 ) ;
} ,
cache() {
return wpCache ;
}
} ;
testApiWorkPackages = {
list : function ( ) {
list : ( ) = > {
var deferred = $q . defer ( ) ;
deferred . resolve ( {
"_type" : "Collection" ,
@ -130,68 +133,79 @@ describe('WorkPackagesListController', function() {
} ;
testQueryService = {
getQuery : function ( ) {
getQuery : ( ) = > {
return {
getQueryString : function ( ) {
getQueryString : ( ) = > {
}
} ;
} ,
initQuery : function ( id ) {
initQuery : ( id ) = > {
var queryId = id || 1 ;
return testQueries [ queryId ] ;
} ,
clearQuery : function ( ) { } ,
loadAvailableColumns : function ( ) {
return $timeout ( function ( ) {
return columnData ;
} , 10 ) ;
clearQuery : ( ) = > {
} ,
loadAvailableGroupedQueries : function ( ) {
return $timeout ( function ( ) {
return availableQueryiesData ;
} , 10 ) ;
loadAvailableColumns : ( ) = > {
return $timeout ( ( ) = > columnData , 10 ) ;
} ,
loadAvailableUnusedColumns : function ( ) {
return $timeout ( function ( ) {
return columnData ;
} , 10 ) ;
loadAvailableGroupedQueries : ( ) = > {
return $timeout ( ( ) = > availableQueryiesData , 10 ) ;
} ,
getTotalEntries : function ( ) {
loadAvailableUnusedColumns : ( ) = > {
return $timeout ( ( ) = > columnData , 10 ) ;
} ,
setTotalEntries : function ( ) {
return 10 ;
getTotalEntries : ( ) = > {
} ,
setTotalEntries : ( ) = > 10 ,
} ;
testPaginationService = {
setPerPageOptions : function ( ) {
setPerPageOptions : ( ) = > {
} ,
setPerPage : function ( ) {
setPerPage : ( ) = > {
} ,
setPage : function ( ) {
setPage : ( ) = > {
}
} ;
testAuthorisationService = {
initModelAuth : function ( model , links ) {
initModelAuth : ( ) = > {
}
} ;
buildController = function ( params , state , location ) {
scope . projectIdentifier = 'test' ;
wpListServiceMock = {
fromQueryParams() {
return $q . when ( {
meta : {
query : { } ,
columns : { } ,
export_formats : { }
} ,
resource : {
total : 10
} ,
work_packages : [
{ }
]
} ) ;
}
} ;
buildController = ( params , state , location ) = > {
scope . projectIdentifier = 'test' ;
ctrl = $controller ( "WorkPackagesListController" , {
$scope : scope ,
$scope : scope ,
$window : win ,
QueryService : testQueryService ,
PaginationService : testPaginationService ,
ProjectService : testProjectService ,
QueryService : testQueryService ,
PaginationService : testPaginationService ,
ProjectService : testProjectService ,
WorkPackageService : testWorkPackageService ,
apiWorkPackages : testApiWorkPackages ,
$stateParams : params ,
$state : state ,
$location : location ,
apiWorkPackages : testApiWorkPackages ,
$stateParams : params ,
$state : state ,
$location : location ,
wpListService : wpListServiceMock
} ) ;
$timeout . flush ( ) ;
@ -199,124 +213,121 @@ describe('WorkPackagesListController', function() {
} ) ) ;
describe ( 'initialisation of default query' , function ( ) {
var testParams , testState , testLocation ;
describe ( 'initialisation of default query' , ( ) = > {
var testParams ;
var testState ;
var testLocation ;
beforeEach ( function ( ) {
testParams = { projectPath : '/projects/my-project' } ;
beforeEach ( ( ) = > {
testParams = { projectPath : '/projects/my-project' } ;
testState = {
params : testParams ,
href : function ( ) { return '' ; }
href : ( ) = > ''
} ;
testLocation = {
search : function ( ) {
return { } ;
} ,
search : ( ) = > ( { } ) ,
url : angular.identity
} ;
buildController ( testParams , testState , testLocation ) ;
} ) ;
it ( 'should initialise' , function ( ) {
expect ( scope . settingUpPage ) . to . be . defined ;
expect ( scope . operatorsAndLabelsByFilterType ) . to . be . defined ;
expect ( scope . disableFilters ) . to . eq ( false ) ;
expect ( scope . disableNewWorkPackage ) . to . eq ( true ) ;
it ( 'should initialise' , ( ) = > {
expect ( scope . operatorsAndLabelsByFilterType ) . to . exist ;
expect ( scope . disableFilters ) . to . be . false ;
expect ( scope . disableNewWorkPackage ) . to . be . true ;
expect ( scope . query . id ) . to . eq ( testQueries [ '1' ] . id ) ;
expect ( scope . showFiltersOptions ) . to . eq ( false ) ;
expect ( scope . showFiltersOptions ) . to . be . false ;
} ) ;
context ( 'second initialisation' , function ( ) {
beforeEach ( function ( ) {
context ( 'second initialisation' , ( ) = > {
beforeEach ( ( ) = > {
scope . toggleShowFilterOptions ( ) ;
buildController ( testParams , testState , testLocation ) ;
} ) ;
it ( 'should persist the showFiltersOptions value' , function ( ) {
expect ( scope . showFiltersOptions ) . to . eq ( true ) ;
it ( 'should persist the showFiltersOptions value' , ( ) = > {
expect ( scope . showFiltersOptions ) . to . be . true ;
} ) ;
} ) ;
} ) ;
describe ( 'initialisation of query by id' , function ( ) {
var testParams , testState , testLocation ;
describe ( 'initialisation of query by id' , ( ) = > {
var testParams ;
var testState ;
var testLocation ;
beforeEach ( function ( ) {
testParams = { projectPath : '/projects/my-project' } ;
beforeEach ( ( ) = > {
testParams = { projectPath : '/projects/my-project' } ;
testState = {
params : {
query_id : testQueries [ '2' ] . id
} ,
href : function ( ) { return '' ; }
href : ( ) = > ''
} ;
testLocation = {
search : function ( ) {
return { } ;
} ,
search : ( ) = > ( { } ) ,
url : angular.identity
} ;
buildController ( testParams , testState , testLocation ) ;
} ) ;
it ( 'should initialise' , function ( ) {
it ( 'should initialise' , ( ) = > {
expect ( scope . query . id ) . to . eq ( testQueries [ '2' ] . id ) ;
} ) ;
} ) ;
describe ( 'getFilterCount' , function ( ) {
beforeEach ( function ( ) {
describe ( 'getFilterCount' , ( ) = > {
beforeEach ( ( ) = > {
var testState = {
params : {
query_id : testQueries [ '2' ] . id
} ,
href : function ( ) { return '' ; }
href : ( ) = > ''
} ;
var testLocation = {
search : function ( ) {
return { } ;
} ,
search : ( ) = > ( { } ) ,
url : angular.identity
} ;
buildController ( { projectPath : '' } , testState , testLocation ) ;
} ) ;
it ( 'returns 0 with no filters' , function ( ) {
it ( 'returns 0 with no filters' , ( ) = > {
expect ( scope . getFilterCount ( ) ) . to . eq ( 0 ) ;
} ) ;
it ( 'returns the filter count with filters' , function ( ) {
it ( 'returns the filter count with filters' , ( ) = > {
scope . query . filters = [ { } , { } ] ;
expect ( scope . getFilterCount ( ) ) . to . eq ( 2 ) ;
} ) ;
it ( 'returns the filter count with deactivated filters' , function ( ) {
scope . query . filters = [ { } , { deactivated : true } , { deactivated : true } ] ;
it ( 'returns the filter count with deactivated filters' , ( ) = > {
scope . query . filters = [ { } , { deactivated : true } , { deactivated : true } ] ;
expect ( scope . getFilterCount ( ) ) . to . eq ( 1 ) ;
} ) ;
} ) ;
describe ( 'setting projectIdentifier' , function ( ) {
var testParams , testState , testLocation ;
describe ( 'setting projectIdentifier' , ( ) = > {
var testParams ;
var testState ;
var testLocation ;
beforeEach ( function ( ) {
testParams = { projectPath : 'my-project' } ;
beforeEach ( ( ) = > {
testParams = { projectPath : 'my-project' } ;
testState = {
href : function ( ) { return '' } ,
href : ( ) = > '' ,
params : testParams
} ;
testLocation = {
search : function ( ) { return { } } ,
search : ( ) = > ( { } ) ,
url : angular.identity
} ;
buildController ( testParams , testState , testLocation ) ;
} ) ;
it ( 'should set the projectIdentifier' , function ( ) {
it ( 'should set the projectIdentifier' , ( ) = > {
expect ( scope . projectIdentifier ) . to . eq ( 'my-project' ) ;
} ) ;
} ) ;