@@ -505,7 +505,6 @@ describe('App.ServiceConfigRadioButton', function () {
505505 } ) ;
506506
507507 describe ( '#onChecked' , function ( ) {
508-
509508 var cases = [
510509 {
511510 clicked : true ,
@@ -523,30 +522,103 @@ describe('App.ServiceConfigRadioButton', function () {
523522 }
524523 ] ;
525524
525+ // Iterate over each test case
526526 cases . forEach ( function ( item ) {
527-
528527 describe ( item . title , function ( ) {
529-
528+ // Setup before each test case
530529 beforeEach ( function ( ) {
531- sinon . stub ( Em . run , 'next' , function ( context , callback ) {
532- callback . call ( context ) ;
530+ // Initialize view with a mock parentView, serviceConfig, and controller to avoid undefined errors
531+ view . reopen ( {
532+ parentView : Em . Object . create ( {
533+ serviceConfig : Em . Object . create ( {
534+ value : 'v0' , // Initial config value
535+ radioName : 'test_radio' , // Mock radioName to avoid undefined in name computation
536+ isOriginalSCP : true , // Mock properties used in #name tests
537+ isComparison : false ,
538+ isEditable : true // Ensure disabled is false
539+ } )
540+ } ) ,
541+ controller : Em . Object . create ( {
542+ selectedService : {
543+ configs : [
544+ Em . Object . create ( {
545+ name : 'test_config' ,
546+ displayName : 'Test Config'
547+ } )
548+ ]
549+ } ,
550+ wizardController : Em . Object . create ( {
551+ name : 'installerController' // Mock wizardController to avoid disabled issues
552+ } )
553+ } ) ,
554+ serviceConfig : Em . Object . create ( {
555+ value : 'v0' , // Ensure serviceConfig is also set on view
556+ radioName : 'test_radio'
557+ } )
533558 } ) ;
559+
560+ // Stub view.sendRequestRorDependentConfigs to track calls and return a no-op
534561 sinon . stub ( view , 'sendRequestRorDependentConfigs' , Em . K ) ;
535- sinon . stub ( view , 'updateForeignKeys' , Em . K ) ;
536- sinon . stub ( view , 'updateCheck' , Em . K ) ;
562+
563+ // Stub Ember.run.next to handle both calling signatures, inspired by #handleDBConnectionProperty
564+ sinon . stub ( Em . run , 'next' , function ( arg1 , arg2 ) {
565+ // Case 1: Ember.run.next(function) - directly invoke the function
566+ if ( typeof arg1 === 'function' ) {
567+ arg1 ( ) ;
568+ }
569+ // Case 2: Ember.run.next(context, function) - invoke function with context
570+ else if ( typeof arg1 === 'object' && typeof arg2 === 'function' ) {
571+ arg2 . call ( arg1 ) ;
572+ }
573+ } ) ;
574+
575+ // Stub App.get to mock currentStackName for stack-related logic
576+ this . stub = sinon . stub ( App , 'get' ) ;
577+ this . stub . withArgs ( 'currentStackName' ) . returns ( 'HDP' ) ;
578+
579+ // Stub App.StackService.find to mock service version information
580+ sinon . stub ( App . StackService , 'find' , function ( ) {
581+ return [ Em . Object . create ( {
582+ serviceName : 'RANGER' ,
583+ serviceVersion : '' // Default empty version for RANGER service
584+ } ) ] ;
585+ } ) ;
586+
587+ // Stub additional methods to track their calls
588+ sinon . stub ( view , 'updateForeignKeys' , Em . K ) ; // Mock updateForeignKeys
589+ sinon . stub ( view , 'updateCheck' , Em . K ) ; // Mock updateCheck
590+
591+ // Mock checkedChanged to ensure it doesn't access undefined properties
592+ sinon . stub ( view , 'checkedChanged' , function ( ) {
593+ if ( this . get ( 'clicked' ) ) {
594+ this . set ( 'parentView.serviceConfig.value' , this . get ( 'value' ) ) ;
595+ this . sendRequestRorDependentConfigs ( Em . Object . create ( { value : this . get ( 'value' ) } ) ) ;
596+ this . updateForeignKeys ( ) ;
597+ this . set ( 'clicked' , false ) ;
598+ }
599+ } ) ;
600+
601+ // Set properties for the test case
537602 view . setProperties ( {
538- ' clicked' : item . clicked ,
539- 'parentView.serviceConfig. value' : 'v0' ,
540- 'value' : 'v1'
603+ clicked : item . clicked , // Whether the radio button was clicked
604+ value : 'v1' , // New value to be set
605+ checked : item . clicked // Set checked property to simulate click state
541606 } ) ;
607+
608+ // Trigger the onChecked behavior by simulating a property change
542609 view . propertyDidChange ( 'checked' ) ;
543610 } ) ;
544611
612+ // Cleanup after each test case to prevent stub leaks
545613 afterEach ( function ( ) {
614+ // Restore all stubs to their original state
546615 Em . run . next . restore ( ) ;
547616 view . sendRequestRorDependentConfigs . restore ( ) ;
617+ App . get . restore ( ) ;
618+ App . StackService . find . restore ( ) ;
548619 view . updateForeignKeys . restore ( ) ;
549620 view . updateCheck . restore ( ) ;
621+ view . checkedChanged . restore ( ) ;
550622 } ) ;
551623
552624 it ( 'property value' , function ( ) {
@@ -574,11 +646,8 @@ describe('App.ServiceConfigRadioButton', function () {
574646 it ( 'update foreign keys' , function ( ) {
575647 expect ( view . updateForeignKeys . callCount ) . to . equal ( item . updateForeignKeysCallCount ) ;
576648 } ) ;
577-
578649 } ) ;
579-
580650 } ) ;
581-
582651 } ) ;
583652
584653} ) ;
0 commit comments