mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-30168 Form Display Value does not show date variable (#10593)
* [AAE-30168] don't add time stamp when there is already one * [AAE-30168] No need to check for undefined * [AAE-30168] added one more test case * [AAE-30168] added best practice for async code to tests
This commit is contained in:
@@ -33,9 +33,7 @@ describe('FormModel', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
formService = new FormService();
|
||||
});
|
||||
@@ -132,10 +130,7 @@ describe('FormModel', () => {
|
||||
|
||||
it('should parse tabs', () => {
|
||||
const json = {
|
||||
tabs: [
|
||||
{ id: 'tab1' },
|
||||
{ id: 'tab2' }
|
||||
]
|
||||
tabs: [{ id: 'tab1' }, { id: 'tab2' }]
|
||||
};
|
||||
|
||||
const form = new FormModel(json);
|
||||
@@ -199,10 +194,7 @@ describe('FormModel', () => {
|
||||
|
||||
it('should put fields into corresponding tabs', () => {
|
||||
const json = {
|
||||
tabs: [
|
||||
{ id: 'tab1' },
|
||||
{ id: 'tab2' }
|
||||
],
|
||||
tabs: [{ id: 'tab1' }, { id: 'tab2' }],
|
||||
fields: [
|
||||
{ id: 'field1', tab: 'tab1', type: FormFieldTypes.CONTAINER },
|
||||
{ id: 'field2', tab: 'tab2', type: FormFieldTypes.CONTAINER },
|
||||
@@ -227,9 +219,7 @@ describe('FormModel', () => {
|
||||
|
||||
it('should create standard form outcomes', () => {
|
||||
const json = {
|
||||
fields: [
|
||||
{ id: 'container1' }
|
||||
]
|
||||
fields: [{ id: 'container1' }]
|
||||
};
|
||||
|
||||
const form = new FormModel(json);
|
||||
@@ -255,12 +245,8 @@ describe('FormModel', () => {
|
||||
|
||||
it('should use custom form outcomes', () => {
|
||||
const json = {
|
||||
fields: [
|
||||
{ id: 'container1' }
|
||||
],
|
||||
outcomes: [
|
||||
{ id: 'custom-1', name: 'custom 1' }
|
||||
]
|
||||
fields: [{ id: 'container1' }],
|
||||
outcomes: [{ id: 'custom-1', name: 'custom 1' }]
|
||||
};
|
||||
|
||||
const form = new FormModel(json);
|
||||
@@ -273,26 +259,28 @@ describe('FormModel', () => {
|
||||
expect(form.outcomes[1].isSystem).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should raise validation event when validating form', () => {
|
||||
it('should raise validation event when validating form', (done) => {
|
||||
const form = new FormModel({}, null, false, formService);
|
||||
|
||||
formService.validateForm.subscribe((validateFormEvent) =>
|
||||
expect(validateFormEvent).toBeTruthy()
|
||||
);
|
||||
formService.validateForm.subscribe((validateFormEvent) => {
|
||||
expect(validateFormEvent).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
form.validateForm();
|
||||
});
|
||||
|
||||
it('should raise validation event when validating field', () => {
|
||||
it('should raise validation event when validating field', (done) => {
|
||||
const form = new FormModel({}, null, false, formService);
|
||||
const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
|
||||
|
||||
formService.validateFormField.subscribe((validateFormFieldEvent) =>
|
||||
expect(validateFormFieldEvent).toBeTruthy()
|
||||
);
|
||||
formService.validateFormField.subscribe((validateFormFieldEvent) => {
|
||||
expect(validateFormFieldEvent).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
form.validateField(field);
|
||||
});
|
||||
|
||||
it('should skip field validation when default behaviour prevented', () => {
|
||||
it('should skip field validation when default behaviour prevented', (done) => {
|
||||
const form = new FormModel({}, null, false, formService);
|
||||
|
||||
let prevented = false;
|
||||
@@ -301,6 +289,7 @@ describe('FormModel', () => {
|
||||
event.isValid = false;
|
||||
event.preventDefault();
|
||||
prevented = true;
|
||||
done();
|
||||
});
|
||||
|
||||
const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
|
||||
@@ -311,13 +300,14 @@ describe('FormModel', () => {
|
||||
expect(field.validate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should validate fields when form validation not prevented', () => {
|
||||
it('should validate fields when form validation not prevented', (done) => {
|
||||
const form = new FormModel(fakeMetadataForm, null, false, formService);
|
||||
|
||||
let validated = false;
|
||||
|
||||
formService.validateForm.subscribe(() => {
|
||||
validated = true;
|
||||
done();
|
||||
});
|
||||
|
||||
const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
|
||||
@@ -329,13 +319,14 @@ describe('FormModel', () => {
|
||||
expect(field.validate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should validate field when field validation not prevented', () => {
|
||||
it('should validate field when field validation not prevented', (done) => {
|
||||
const form = new FormModel({}, null, false, formService);
|
||||
|
||||
let validated = false;
|
||||
|
||||
formService.validateFormField.subscribe(() => {
|
||||
validated = true;
|
||||
done();
|
||||
});
|
||||
|
||||
const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
|
||||
@@ -345,7 +336,7 @@ describe('FormModel', () => {
|
||||
expect(field.validate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should validate form when field validation not prevented', () => {
|
||||
it('should validate form when field validation not prevented', (done) => {
|
||||
const form = new FormModel({}, null, false, formService);
|
||||
spyOn(form, 'validateForm').and.stub();
|
||||
|
||||
@@ -353,6 +344,7 @@ describe('FormModel', () => {
|
||||
|
||||
formService.validateFormField.subscribe(() => {
|
||||
validated = true;
|
||||
done();
|
||||
});
|
||||
|
||||
const field: any = {
|
||||
@@ -364,7 +356,7 @@ describe('FormModel', () => {
|
||||
expect(form.validateForm).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not validate form when field validation prevented', () => {
|
||||
it('should not validate form when field validation prevented', (done) => {
|
||||
const form = new FormModel({}, null, false, formService);
|
||||
spyOn(form, 'validateForm').and.stub();
|
||||
|
||||
@@ -373,6 +365,7 @@ describe('FormModel', () => {
|
||||
formService.validateFormField.subscribe((event: ValidateFormFieldEvent) => {
|
||||
event.preventDefault();
|
||||
prevented = true;
|
||||
done();
|
||||
});
|
||||
|
||||
const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
|
||||
@@ -503,6 +496,17 @@ describe('FormModel', () => {
|
||||
processInstanceId: '1be4785f-c982-11e9-bdd8-96d6903e4e44',
|
||||
taskId: '1beab9f6-c982-11e9-bdd8-96d6903e4e44',
|
||||
taskVariable: true
|
||||
},
|
||||
{
|
||||
id: 'variables.datetime',
|
||||
name: 'variables.datetime',
|
||||
value: '2025-01-23T04:30:00.000+0000',
|
||||
type: 'date'
|
||||
},
|
||||
{
|
||||
type: 'date',
|
||||
name: 'variables.dateonly',
|
||||
value: '2025-01-27'
|
||||
}
|
||||
];
|
||||
|
||||
@@ -570,9 +574,15 @@ describe('FormModel', () => {
|
||||
expect(value).toBe('29.09.2019T00:00:00.000Z');
|
||||
});
|
||||
|
||||
it('should find a process variable by name', () => {
|
||||
const value = form.getProcessVariableValue('booleanVar');
|
||||
expect(value).toEqual(true);
|
||||
[
|
||||
{ name: 'booleanVar', result: true },
|
||||
{ name: 'datetime', result: '2025-01-23T04:30:00.000+0000' },
|
||||
{ name: 'dateonly', result: '2025-01-27T00:00:00.000Z' }
|
||||
].forEach(({ name, result }) => {
|
||||
it(`should find a process variable by name ${name} and convert it`, () => {
|
||||
const value = form.getProcessVariableValue(name);
|
||||
expect(value).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not find a process variable', () => {
|
||||
@@ -614,7 +624,6 @@ describe('FormModel', () => {
|
||||
expect(form.values['pfx_property_six']).toEqual('text-value');
|
||||
expect(form.values['pfx_property_seven']).toBeNull();
|
||||
expect(form.values['pfx_property_eight']).toBeNull();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -313,7 +313,7 @@ export class FormModel implements ProcessFormModel {
|
||||
if (type && value) {
|
||||
switch (type) {
|
||||
case 'date':
|
||||
return value ? `${value}T00:00:00.000Z` : undefined;
|
||||
return value.toString().includes('T') ? value : `${value}T00:00:00.000Z`;
|
||||
case 'boolean':
|
||||
return typeof value === 'string' ? JSON.parse(value) : value;
|
||||
default:
|
||||
|
Reference in New Issue
Block a user