@ -30,7 +30,9 @@
describe ( 'QueryService' , function ( ) {
describe ( 'QueryService' , function ( ) {
var QueryService , PathHelper , query , queryData , stateParams = { } ;
var QueryService , PathHelper , query , queryData , stateParams = { } , $rootScope ,
$httpBackend ;
beforeEach ( module ( 'openproject.layout' ,
beforeEach ( module ( 'openproject.layout' ,
'openproject.models' ,
'openproject.models' ,
@ -46,8 +48,11 @@ describe('QueryService', function() {
$provide . constant ( 'ConfigurationService' , configurationService ) ;
$provide . constant ( 'ConfigurationService' , configurationService ) ;
} ) ) ;
} ) ) ;
beforeEach ( inject ( function ( _QueryService _ ) {
beforeEach ( inject ( function ( _QueryService _ , _$rootScope _ , _$httpBackend _ , _PathHelper _ ) {
QueryService = _QueryService _ ;
QueryService = _QueryService _ ;
$rootScope = _$rootScope _ ;
PathHelper = _PathHelper _ ;
$httpBackend = _$httpBackend _ ;
} ) ) ;
} ) ) ;
describe ( 'query setup' , function ( ) {
describe ( 'query setup' , function ( ) {
@ -85,6 +90,35 @@ describe('QueryService', function() {
} ) ;
} ) ;
describe ( 'deleteQuery' , function ( ) {
var spy ;
beforeEach ( function ( ) {
spy = sinon . spy ( $rootScope , '$broadcast' ) ;
queryData = { name : '_' , 'project_id' : 1 } ;
QueryService . initQuery ( 1 , queryData ) ;
var path = PathHelper . apiProjectQueryPath ( 1 , 1 ) ;
$httpBackend . when ( 'DELETE' , new RegExp ( path + '*' ) ) . respond ( 200 , [ ] ) ;
$httpBackend . when (
'GET' ,
PathHelper . apiProjectCustomFieldsPath ( 1 )
) . respond ( 200 , [ ] ) ;
$httpBackend . when (
'GET' ,
PathHelper . apiProjectGroupedQueriesPath ( 1 )
) . respond ( 200 , [ ] ) ;
QueryService . deleteQuery ( ) ;
$httpBackend . flush ( ) ;
} ) ;
afterEach ( function ( ) {
spy . restore ( ) ;
} ) ;
it ( 'should broadcast a query deletion message' , function ( ) {
expect ( $rootScope . $broadcast . calledWith ( 'openproject.layout.removeMenuItem' ) ) . to . be . true ;
} ) ;
} ) ;
describe ( 'getQueryName' , function ( ) {
describe ( 'getQueryName' , function ( ) {
var defaultTitle = 'Work Packages' ;
var defaultTitle = 'Work Packages' ;
@ -122,7 +156,6 @@ describe('QueryService', function() {
describe ( 'loadAvailableGroupedQueries' , function ( ) {
describe ( 'loadAvailableGroupedQueries' , function ( ) {
var projectIdentifier = 'test_project' ,
var projectIdentifier = 'test_project' ,
$httpBackend ,
$httpBackend ,
$rootScope ,
path ,
path ,
groupedQueries ;
groupedQueries ;
@ -131,10 +164,9 @@ describe('QueryService', function() {
$httpBackend . flush ( ) ;
$httpBackend . flush ( ) ;
}
}
beforeEach ( inject ( function ( _$httpBackend _ , _PathHelper _ , _$rootScope _ ) {
beforeEach ( inject ( function ( _$httpBackend _ , _PathHelper _ ) {
$httpBackend = _$httpBackend _ ;
$httpBackend = _$httpBackend _ ;
PathHelper = _PathHelper _ ;
PathHelper = _PathHelper _ ;
$rootScope = _$rootScope _ ;
path = PathHelper . apiProjectGroupedQueriesPath ( projectIdentifier ) ;
path = PathHelper . apiProjectGroupedQueriesPath ( projectIdentifier ) ;
groupedQueries = {
groupedQueries = {