Merge pull request #2217 from 4Science/DURACOM-138

Parameter box, shown or not
This commit is contained in:
Tim Donohue
2023-05-12 11:03:32 -05:00
committed by GitHub
2 changed files with 38 additions and 22 deletions

View File

@@ -1,11 +1,11 @@
<div class="form-group" *ngIf="script"> <div class="form-group" *ngIf="script?.parameters?.length" data-testID="parameters-select-container">
<label>{{'process.new.select-parameters' | translate}}</label> <label>{{'process.new.select-parameters' | translate}}</label>
<ds-parameter-select <ds-parameter-select
*ngFor="let value of parameterValues; let i = index; let last = last" *ngFor="let value of parameterValues; let i = index; let last = last"
[parameters]="script.parameters" [parameters]="script.parameters"
[parameterValue]="value" [parameterValue]="value"
[removable]="!last" [removable]="!last"
[index]="i" [index]="i"
(removeParameter)="removeParameter(i)" (removeParameter)="removeParameter(i)"
(changeParameter)="updateParameter($event, i)"></ds-parameter-select> (changeParameter)="updateParameter($event, i)"></ds-parameter-select>
</div> </div>

View File

@@ -14,14 +14,14 @@ import { TranslateLoaderMock } from '../../../shared/mocks/translate-loader.mock
describe('ProcessParametersComponent', () => { describe('ProcessParametersComponent', () => {
let component: ProcessParametersComponent; let component: ProcessParametersComponent;
let fixture: ComponentFixture<ProcessParametersComponent>; let fixture: ComponentFixture<ProcessParametersComponent>;
let parameterValues; let mockParameterValues: ProcessParameter[];
let script; let mockScript: Script;
function init() { function initParametersAndScriptMockValues() {
const param1 = new ScriptParameter(); const param1 = new ScriptParameter();
const param2 = new ScriptParameter(); const param2 = new ScriptParameter();
script = Object.assign(new Script(), { parameters: [param1, param2] }); mockScript = Object.assign(new Script(), { parameters: [param1, param2] });
parameterValues = [ mockParameterValues = [
Object.assign(new ProcessParameter(), { name: '-a', value: 'bla' }), Object.assign(new ProcessParameter(), { name: '-a', value: 'bla' }),
Object.assign(new ProcessParameter(), { name: '-b', value: '123' }), Object.assign(new ProcessParameter(), { name: '-b', value: '123' }),
Object.assign(new ProcessParameter(), { name: '-c', value: 'value' }), Object.assign(new ProcessParameter(), { name: '-c', value: 'value' }),
@@ -29,7 +29,6 @@ describe('ProcessParametersComponent', () => {
} }
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
init();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
FormsModule, FormsModule,
@@ -48,17 +47,34 @@ describe('ProcessParametersComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(ProcessParametersComponent); fixture = TestBed.createComponent(ProcessParametersComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
component.script = script;
component.parameterValues = parameterValues;
fixture.detectChanges();
}); });
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
it('should render a ParameterSelectComponent for each parameter value of the component', () => { describe('when parameter values and script are initialized', () => {
const selectComponents = fixture.debugElement.queryAll(By.directive(ParameterSelectComponent));
expect(selectComponents.length).toBe(parameterValues.length); beforeEach(() => {
initParametersAndScriptMockValues();
component.parameterValues = mockParameterValues;
component.script = mockScript;
fixture.detectChanges();
});
it(`should render a ${ParameterSelectComponent.name} for each parameter value`, () => {
const selectComponents = fixture.debugElement.queryAll(By.directive(ParameterSelectComponent));
expect(selectComponents.length).toBe(mockParameterValues.length);
});
it('should not render a selector box if the parameter array is empty',() => {
fixture.componentInstance.script.parameters = [];
fixture.detectChanges();
const formGroupComponent = fixture.debugElement.query(By.css('[data-testID=parameters-select-container]'));
expect(formGroupComponent).toBeFalsy();
});
}); });
}); });