2015-08-26 18:35:26 +03:00
import '../support/node' ;
Refactor Inventories > Inventory Manage module (#2013)
* refactor InventoryManage modules, resolves #1748, #1354, #1754, #1960, #1961, #1962, #1963, #1965
* refactor InventoryManage modules, resolves #1748, #1354, #1754, #1960, #1961, #1962, #1963, #1965
* instantiate lookupfields with correct values / endpoint queries #1979
* fix groups/host list sort and remove some unnecessary service abstractions #1979
* fix childless delete wording
* add host > toggle enabled/disabled
* fix breadcrumb indexing
* remove extra required asterisk from inventory script lookup field
* fix delete prompt styling
* remove group badge linking, add toolip
* full width host var form, fix add/edit group inventory source vars
* restrict copy/moving multiselect to one item
* break word on host/group names and support multiple rows of breakcrumbs
* hide trailing breadcrumb slash at root group view
* fix failing unit test dependency path, hook up system tracking
* fix ec2 group by label rendering in group > edit view, fix add/edit/adhoc breadcrumb display when breadcrumbs are 2+ rows
* fix select spacing on copy/move groups
* limit group/host/copyMove search to current context
* refresh status icons on page/search event
* move status indicators to left side of lists
* fix typo in select2 init
* fix assorted typos
* $track by statement needs to tail | filterBy:xyz
* fix JSHint failure
* PR feedback, hook up filter for hosts with active failures, hook up status tooltips/popovers
2016-05-25 02:16:00 +03:00
import adhocModule from 'inventories/manage/adhoc/main' ;
2015-08-26 18:35:26 +03:00
import RestStub from '../support/rest-stub' ;
describe ( "adhoc.controller" , function ( ) {
2016-01-06 22:40:07 +03:00
var $scope , $rootScope , $location , $stateParams , $stateExtender ,
2015-08-26 18:35:26 +03:00
CheckPasswords , PromptForPasswords , CreateLaunchDialog , AdhocForm ,
GenerateForm , Rest , ProcessErrors , ClearScope , GetBasePath , GetChoices ,
KindChange , LookUpInit , CredentialList , Empty , Wait ;
var $controller , ctrl , generateFormCallback , waitCallback , locationCallback ,
2016-01-06 22:40:07 +03:00
getBasePath , processErrorsCallback , restCallback , stateExtenderCallback ;
2015-08-26 18:35:26 +03:00
beforeEach ( "instantiate the adhoc module" , function ( ) {
angular . mock . module ( adhocModule . name ) ;
} ) ;
before ( "create spies" , function ( ) {
getBasePath = function ( path ) {
return '/' + path + '/' ;
} ;
generateFormCallback = {
inject : angular . noop
} ;
waitCallback = sinon . spy ( ) ;
locationCallback = {
path : sinon . spy ( )
} ;
processErrorsCallback = sinon . spy ( ) ;
restCallback = new RestStub ( ) ;
2016-01-06 22:40:07 +03:00
stateExtenderCallback = {
addState : angular . noop
}
2015-08-26 18:35:26 +03:00
} ) ;
2016-04-26 22:16:51 +03:00
2015-08-26 18:35:26 +03:00
beforeEach ( "mock dependencies" , angular . mock . module ( [ '$provide' , function ( _provide _ ) {
var $provide = _provide _ ;
$provide . value ( '$location' , locationCallback ) ;
$provide . value ( 'CheckPasswords' , angular . noop ) ;
$provide . value ( 'PromptForPasswords' , angular . noop ) ;
$provide . value ( 'CreateLaunchDialog' , angular . noop ) ;
$provide . value ( 'AdhocForm' , angular . noop ) ;
$provide . value ( 'GenerateForm' , generateFormCallback ) ;
$provide . value ( 'Rest' , restCallback ) ;
$provide . value ( 'ProcessErrors' , processErrorsCallback ) ;
$provide . value ( 'ClearScope' , angular . noop ) ;
$provide . value ( 'GetBasePath' , getBasePath ) ;
$provide . value ( 'GetChoices' , angular . noop ) ;
$provide . value ( 'KindChange' , angular . noop ) ;
$provide . value ( 'LookUpInit' , angular . noop ) ;
$provide . value ( 'CredentialList' , angular . noop ) ;
$provide . value ( 'Empty' , angular . noop ) ;
$provide . value ( 'Wait' , waitCallback ) ;
2016-01-06 22:40:07 +03:00
$provide . value ( '$stateExtender' , stateExtenderCallback ) ;
$provide . value ( '$stateParams' , angular . noop ) ;
2016-02-25 17:43:20 +03:00
$provide . value ( '$state' , angular . noop ) ;
2015-08-26 18:35:26 +03:00
} ] ) ) ;
2016-04-26 22:16:51 +03:00
beforeEach ( "put the controller in scope" , inject ( function ( $rootScope , $controller ) {
var scope = $rootScope . $new ( ) ;
ctrl = $controller ( 'adhocController' , { $scope : scope } ) ;
} ) ) ;
2015-08-26 18:35:26 +03:00
beforeEach ( "put $q in scope" , window . inject ( [ '$q' , function ( $q ) {
restCallback . $q = $q ;
} ] ) ) ;
2016-04-26 22:16:51 +03:00
/ *
2015-08-26 18:35:26 +03:00
describe ( "setAvailableUrls" , function ( ) {
it ( 'should only have the specified urls ' +
'available for adhoc commands' , function ( ) {
var urls = ctrl . privateFn . setAvailableUrls ( ) ;
expect ( urls ) . to . have . keys ( 'adhocUrl' , 'inventoryUrl' ,
'machineCredentialUrl' ) ;
var count = 0 ;
var i ;
for ( i in urls ) {
if ( urls . hasOwnProperty ( i ) ) {
count ++ ;
}
}
expect ( count ) . to . equal ( 3 ) ;
} ) ;
2016-04-26 22:16:51 +03:00
2015-08-26 18:35:26 +03:00
} ) ;
describe ( "setFieldDefaults" , function ( ) {
it ( 'should set the select form field defaults' +
'based on user settings' , function ( ) {
var verbosity _options = [
{ label : "0 (Foo)" , value : 0 , name : "0 (Foo)" ,
isDefault : false } ,
{ label : "1 (Bar)" , value : 1 , name : "1 (Bar)" ,
isDefault : true } ,
] ,
forks _field = { } ;
forks _field . default = 3 ;
$scope . $apply ( function ( ) {
ctrl . privateFn . setFieldDefaults ( verbosity _options ,
forks _field . default ) ;
} ) ;
expect ( $scope . forks ) . to . equal ( forks _field . default ) ;
expect ( $scope . verbosity . value ) . to . equal ( 1 ) ;
} ) ;
} ) ;
describe ( "setLoadingStartStop" , function ( ) {
it ( 'should start the controller working state when the form is ' +
'loading' , function ( ) {
waitCallback . reset ( ) ;
ctrl . privateFn . setLoadingStartStop ( ) ;
expect ( waitCallback ) . to . have . been . calledWith ( "start" ) ;
} ) ;
it ( 'should stop the indicator after all REST calls in the form load have ' +
'completed' , function ( ) {
var forks _field = { } ,
adhoc _verbosity _options = { } ;
forks _field . default = "1" ;
$scope . $apply ( function ( ) {
$scope . forks _field = forks _field ;
$scope . adhoc _verbosity _options = adhoc _verbosity _options ;
} ) ;
waitCallback . reset ( ) ;
$scope . $emit ( 'adhocFormReady' ) ;
$scope . $emit ( 'adhocFormReady' ) ;
expect ( waitCallback ) . to . have . been . calledWith ( "stop" ) ;
} ) ;
} ) ;
describe ( "instantiateArgumentHelp" , function ( ) {
it ( "should initially provide a canned argument help response" , function ( ) {
expect ( $scope . argsPopOver ) . to . equal ( '<p>These arguments are used ' +
'with the specified module.</p>' ) ;
} ) ;
it ( "should change the help response when the module changes" , function ( ) {
$scope . $apply ( function ( ) {
$scope . module _name = { value : 'foo' } ;
} ) ;
expect ( $scope . argsPopOver ) . to . equal ( '<p>These arguments are used ' +
'with the specified module. You can find information about ' +
'the foo module <a ' +
'id=\"adhoc_module_arguments_docs_link_for_module_foo\" ' +
'href=\"http://docs.ansible.com/foo_module.html\" ' +
'target=\"_blank\">here</a>.</p>' ) ;
} ) ;
it ( "should change the help response when the module changes again" , function ( ) {
$scope . $apply ( function ( ) {
$scope . module _name = { value : 'bar' } ;
} ) ;
expect ( $scope . argsPopOver ) . to . equal ( '<p>These arguments are used ' +
'with the specified module. You can find information about ' +
'the bar module <a ' +
'id=\"adhoc_module_arguments_docs_link_for_module_bar\" ' +
'href=\"http://docs.ansible.com/bar_module.html\" ' +
'target=\"_blank\">here</a>.</p>' ) ;
} ) ;
it ( "should change the help response back to the canned response " +
"when no module is selected" , function ( ) {
$scope . $apply ( function ( ) {
$scope . module _name = null ;
} ) ;
expect ( $scope . argsPopOver ) . to . equal ( '<p>These arguments are used ' +
'with the specified module.</p>' ) ;
} ) ;
} ) ;
describe ( "instantiateHostPatterns" , function ( ) {
it ( "should initialize the limit object based on the provided host " +
"pattern" , function ( ) {
ctrl . privateFn . instantiateHostPatterns ( "foo:bar" ) ;
expect ( $scope . limit ) . to . equal ( "foo:bar" ) ;
} ) ;
it ( "should set the providedHostPatterns variable to the provided host " +
"pattern so it is accesible on form reset" , function ( ) {
ctrl . privateFn . instantiateHostPatterns ( "foo:bar" ) ;
expect ( $scope . providedHostPatterns ) . to . equal ( "foo:bar" ) ;
} ) ;
it ( "should remove the hostPattern from rootScope after it has been " +
"utilized" , function ( ) {
$rootScope . hostPatterns = "foo" ;
expect ( $rootScope . hostPatterns ) . to . exist ;
ctrl . privateFn . instantiateHostPatterns ( "foo" ) ;
expect ( $rootScope . hostPatterns ) . to . not . exist ;
} ) ;
} ) ;
2016-04-26 22:16:51 +03:00
* /
2015-08-26 18:35:26 +03:00
} ) ;