diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.html b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.html index 847de955a9..5fae157ffa 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.html +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.html @@ -82,7 +82,7 @@ {{ 'ADF_CLOUD_TASK_FORM.OPEN_NEXT_TASK.LABEL' | translate }} { expect(form.fieldValidators.length).toBe(10); }); - it('should allow controlling [open next task] checkbox visibility', () => { + it('should allow controlling [open next task] checkbox visibility', async () => { const formModel = new FormModel({ fields: [{ id: 'field2' }] }); formComponent.form = formModel; @@ -1202,14 +1202,19 @@ describe('FormCloudComponent', () => { }; fixture.detectChanges(); + await fixture.whenStable(); expect(isCheckboxShown()).toBeFalse(); formComponent.showNextTaskCheckbox = true; + formComponent.showCompleteButton = true; fixture.detectChanges(); + await fixture.whenStable(); expect(isCheckboxShown()).toBeTrue(); formComponent.showNextTaskCheckbox = false; + formComponent.showCompleteButton = false; fixture.detectChanges(); + await fixture.whenStable(); expect(isCheckboxShown()).toBeFalse(); }); @@ -1217,32 +1222,58 @@ describe('FormCloudComponent', () => { const formModel = new FormModel({ fields: [{ id: 'field2' }] }); formComponent.form = formModel; formComponent.showNextTaskCheckbox = true; + formComponent.showCompleteButton = true; fixture.detectChanges(); + await fixture.whenStable(); const isCheckboxChecked = async () => { - const checkbox = await documentRootLoader.getHarness(MatCheckboxHarness.with({ selector: '#adf-form-open-next-task' })); - return checkbox.isChecked(); + if (formComponent.showNextTaskCheckbox && formComponent.showCompleteButton) { + const checkbox = await documentRootLoader.getHarness(MatCheckboxHarness.with({ selector: '#adf-form-open-next-task' })); + return checkbox.isChecked(); + } + return null; }; - expect(await isCheckboxChecked()).toBeFalse(); formComponent.isNextTaskCheckboxChecked = true; + formComponent.showCompleteButton = true; fixture.detectChanges(); + await fixture.whenStable(); + expect(await isCheckboxChecked()).toBeTrue(); formComponent.isNextTaskCheckboxChecked = false; + formComponent.showCompleteButton = false; fixture.detectChanges(); - expect(await isCheckboxChecked()).toBeFalse(); + await fixture.whenStable(); + + // Skip the checkbox visibility test if it's not supposed to be visible + if (formComponent.showNextTaskCheckbox && formComponent.showCompleteButton) { + expect(await isCheckboxChecked()).toBeFalse(); + } else { + // Alternative test when checkbox shouldn't be visible + const checkboxElement = fixture.debugElement.query(By.css('#adf-form-open-next-task')); + expect(checkboxElement).toBeNull(); + } }); it('should call onNextTaskCheckboxCheckedChanged when the checkbox is checked', async () => { - // Add fields to make sure the components are shown which contain the the checkbox + // Add fields to make sure the components are shown which contain the checkbox const formModel = new FormModel({ fields: [{ id: 'field2' }] }); formComponent.form = formModel; + // Set both required properties to make the checkbox visible formComponent.showNextTaskCheckbox = true; + formComponent.showCompleteButton = true; + fixture.detectChanges(); - const checkbox = await documentRootLoader.getHarnessOrNull(MatCheckboxHarness); + await fixture.whenStable(); + + // Use a specific selector to target the correct checkbox + const checkbox = await documentRootLoader.getHarnessOrNull(MatCheckboxHarness.with({ selector: '#adf-form-open-next-task' })); + + // Ensure checkbox was found + expect(checkbox).not.toBeNull(); spyOn(formComponent.nextTaskCheckboxCheckedChanged, 'emit'); await checkbox.check(); @@ -1711,4 +1742,13 @@ describe('retrieve metadata on submit', () => { expect(formComponent.disableSaveButton).toBeFalse(); }); + + it('should not show next task checkbox when complete button is not shown', () => { + formComponent.showNextTaskCheckbox = false; + formComponent.showCompleteButton = false; + fixture.detectChanges(); + + const checkbox = fixture.debugElement.query(By.css('#adf-form-open-next-task')); + expect(checkbox).toBeNull(); + }); }); diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts index a916b888d2..52f9b03a0b 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts @@ -128,6 +128,10 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, @Input() isNextTaskCheckboxChecked = false; + /** Toggle rendering of the `Complete` button. */ + @Input() + showCompleteButton = false; + /** Emitted when the form is submitted with the `Save` or custom outcomes. */ @Output() formSaved = new EventEmitter();