Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should allow controlling [complete] button visibility', () => {
const formModel = new FormModel();
formComponent.form = formModel;
const outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION });
formComponent.showSaveButton = true;
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
formComponent.showSaveButton = false;
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy();
});
it('should not show [save] button with readOnly form ', () => {
const formModel = new FormModel();
formModel.readOnly = true;
component.form = formModel;
const outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION });
component.showSaveButton = true;
expect(component.isOutcomeButtonVisible(outcome, component.form.readOnly)).toBeFalsy();
});
it('should allow controlling [complete] button visibility', () => {
const formModel = new FormModel();
component.form = formModel;
const outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION });
component.showSaveButton = true;
expect(component.isOutcomeButtonVisible(outcome, component.form.readOnly)).toBeTruthy();
component.showSaveButton = false;
expect(component.isOutcomeButtonVisible(outcome, component.form.readOnly)).toBeFalsy();
});
getFormDefinitionOutcomes(form: FormModel): FormOutcomeModel[] {
return [
new FormOutcomeModel(form, { id: '$save', name: FormOutcomeModel.SAVE_ACTION, isSystem: true })
];
}
isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean {
if (outcome && outcome.isSystem && (outcome.name === FormOutcomeModel.SAVE_ACTION ||
outcome.name === FormOutcomeModel.COMPLETE_ACTION)) {
return false;
} else if (outcome && outcome.name === FormOutcomeModel.START_PROCESS_ACTION) {
return true;
}
return super.isOutcomeButtonVisible(outcome, isFormReadOnly);
}
const field = new FormFieldModel(formModel, {
type: 'text',
value: null,
required: true
});
const containerModel = new ContainerModel(field);
formModel.fields.push(containerModel);
formComponent.form = formModel;
formModel.onFormFieldChanged(field);
expect(formModel.isValid).toBeFalsy();
const saveOutcome = new FormOutcomeModel(new FormModel(), {
id: FormComponent.SAVE_OUTCOME_ID,
name: FormOutcomeModel.SAVE_ACTION
});
expect(formComponent.isOutcomeButtonEnabled(saveOutcome)).toBeFalsy();
});
parseForm(json: any, data?: FormValues, readOnly: boolean = false): FormModel {
if (json) {
const form = new FormModel(json, data, readOnly, this);
if (!json.fields) {
form.outcomes = [
new FormOutcomeModel(form, {
id: '$save',
name: FormOutcomeModel.SAVE_ACTION,
isSystem: true
})
];
}
return form;
}
return null;
}