mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Form and Date widget tests
This commit is contained in:
@@ -634,4 +634,74 @@ describe('ActivitiForm', () => {
|
||||
expect(visibilityService.refreshVisibility).toHaveBeenCalledWith(field.form);
|
||||
});
|
||||
|
||||
it('should load form for ecm node', () => {
|
||||
spyOn(formComponent, 'loadFormForEcmNode').and.stub();
|
||||
|
||||
formComponent.nodeId = '<id>';
|
||||
formComponent.ngOnInit();
|
||||
|
||||
expect(formComponent.loadFormForEcmNode).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should disable outcome buttons for readonly form', () => {
|
||||
let formModel = new FormModel();
|
||||
formModel.readOnly = true;
|
||||
formComponent.form = formModel;
|
||||
|
||||
let outcome = new FormOutcomeModel(new FormModel(), {
|
||||
id: ActivitiForm.CUSTOM_OUTCOME_ID,
|
||||
name: 'Custom'
|
||||
});
|
||||
|
||||
expect(formComponent.isOutcomeButtonEnabled(outcome)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should require outcome to eval button state', () => {
|
||||
formComponent.form = new FormModel();
|
||||
expect(formComponent.isOutcomeButtonEnabled(null)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should always enable save outcome for writeable form', () => {
|
||||
let formModel = new FormModel();
|
||||
let field = new FormFieldModel(formModel, {
|
||||
type: 'text',
|
||||
value: null,
|
||||
required: true
|
||||
});
|
||||
|
||||
formComponent.form = formModel;
|
||||
formModel.onFormFieldChanged(field);
|
||||
|
||||
expect(formModel.isValid).toBeFalsy();
|
||||
|
||||
let outcome = new FormOutcomeModel(new FormModel(), {
|
||||
id: ActivitiForm.SAVE_OUTCOME_ID,
|
||||
name: FormOutcomeModel.SAVE_ACTION
|
||||
});
|
||||
|
||||
formComponent.readOnly = true;
|
||||
expect(formComponent.isOutcomeButtonEnabled(outcome)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should disable oucome buttons for invalid form', () => {
|
||||
let formModel = new FormModel();
|
||||
let field = new FormFieldModel(formModel, {
|
||||
type: 'text',
|
||||
value: null,
|
||||
required: true
|
||||
});
|
||||
|
||||
formComponent.form = formModel;
|
||||
formModel.onFormFieldChanged(field);
|
||||
|
||||
expect(formModel.isValid).toBeFalsy();
|
||||
|
||||
let outcome = new FormOutcomeModel(new FormModel(), {
|
||||
id: ActivitiForm.CUSTOM_OUTCOME_ID,
|
||||
name: 'Custom'
|
||||
});
|
||||
|
||||
expect(formComponent.isOutcomeButtonEnabled(outcome)).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -194,7 +194,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
|
||||
ngOnInit() {
|
||||
if (this.nodeId) {
|
||||
this.loadActivitiFormForEcmNode();
|
||||
this.loadFormForEcmNode();
|
||||
} else {
|
||||
this.loadForm();
|
||||
}
|
||||
@@ -418,7 +418,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
private loadActivitiFormForEcmNode(): void {
|
||||
loadFormForEcmNode(): void {
|
||||
this.nodeService.getNodeMetadata(this.nodeId).subscribe(data => {
|
||||
this.data = data.metadata;
|
||||
this.loadFormFromActiviti(data.nodeType);
|
||||
@@ -426,7 +426,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
this.handleError);
|
||||
}
|
||||
|
||||
public loadFormFromActiviti(nodeType: string): any {
|
||||
loadFormFromActiviti(nodeType: string): any {
|
||||
this.formService.searchFrom(nodeType).subscribe(
|
||||
form => {
|
||||
if (!form) {
|
||||
|
@@ -210,7 +210,7 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
*/
|
||||
if (json.type === FormFieldTypes.DATE) {
|
||||
if (value) {
|
||||
let d = moment(value.split('T')[0]);
|
||||
let d = moment(value.split('T')[0], 'YYYY-M-D');
|
||||
if (d.isValid()) {
|
||||
value = d.format('D-M-YYYY');
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ describe('DateWidget', () => {
|
||||
let dateValue = '13-03-1982';
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: 'date',
|
||||
value: dateValue
|
||||
value: '1982-03-13'
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
|
Reference in New Issue
Block a user