@@ -14,22 +14,21 @@ import { TranslateLoaderMock } from '../../../shared/mocks/translate-loader.mock
1414describe ( 'ProcessParametersComponent' , ( ) => {
1515 let component : ProcessParametersComponent ;
1616 let fixture : ComponentFixture < ProcessParametersComponent > ;
17- let parameterValues ;
18- let script ;
17+ let mockParameterValues : ProcessParameter [ ] ;
18+ let mockScript : Script ;
1919
20- function init ( ) {
20+ function initParametersAndScriptMockValues ( ) {
2121 const param1 = new ScriptParameter ( ) ;
2222 const param2 = new ScriptParameter ( ) ;
23- script = Object . assign ( new Script ( ) , { parameters : [ param1 , param2 ] } ) ;
24- parameterValues = [
23+ mockScript = Object . assign ( new Script ( ) , { parameters : [ param1 , param2 ] } ) ;
24+ mockParameterValues = [
2525 Object . assign ( new ProcessParameter ( ) , { name : '-a' , value : 'bla' } ) ,
2626 Object . assign ( new ProcessParameter ( ) , { name : '-b' , value : '123' } ) ,
2727 Object . assign ( new ProcessParameter ( ) , { name : '-c' , value : 'value' } ) ,
2828 ] ;
2929 }
3030
3131 beforeEach ( waitForAsync ( ( ) => {
32- init ( ) ;
3332 TestBed . configureTestingModule ( {
3433 imports : [
3534 FormsModule ,
@@ -48,17 +47,34 @@ describe('ProcessParametersComponent', () => {
4847 beforeEach ( ( ) => {
4948 fixture = TestBed . createComponent ( ProcessParametersComponent ) ;
5049 component = fixture . componentInstance ;
51- component . script = script ;
52- component . parameterValues = parameterValues ;
53- fixture . detectChanges ( ) ;
5450 } ) ;
5551
5652 it ( 'should create' , ( ) => {
5753 expect ( component ) . toBeTruthy ( ) ;
5854 } ) ;
5955
60- it ( 'should render a ParameterSelectComponent for each parameter value of the component' , ( ) => {
61- const selectComponents = fixture . debugElement . queryAll ( By . directive ( ParameterSelectComponent ) ) ;
62- expect ( selectComponents . length ) . toBe ( parameterValues . length ) ;
56+ describe ( 'when parameter values and script are initialized' , ( ) => {
57+
58+ beforeEach ( ( ) => {
59+ initParametersAndScriptMockValues ( ) ;
60+ component . parameterValues = mockParameterValues ;
61+ component . script = mockScript ;
62+
63+ fixture . detectChanges ( ) ;
64+ } ) ;
65+
66+ it ( `should render a ${ ParameterSelectComponent . name } for each parameter value` , ( ) => {
67+ const selectComponents = fixture . debugElement . queryAll ( By . directive ( ParameterSelectComponent ) ) ;
68+ expect ( selectComponents . length ) . toBe ( mockParameterValues . length ) ;
69+ } ) ;
70+
71+ it ( 'should not render a selector box if the parameter array is empty' , ( ) => {
72+ fixture . componentInstance . script . parameters = [ ] ;
73+
74+ fixture . detectChanges ( ) ;
75+
76+ const formGroupComponent = fixture . debugElement . query ( By . css ( '[data-testID=parameters-select-container]' ) ) ;
77+ expect ( formGroupComponent ) . toBeFalsy ( ) ;
78+ } ) ;
6379 } ) ;
6480} ) ;
0 commit comments