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:
Michaela
2025-01-29 13:20:41 +01:00
committed by GitHub
parent 40d9c750d6
commit 91ffd96100
2 changed files with 47 additions and 38 deletions

View File

@@ -33,9 +33,7 @@ describe('FormModel', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [CoreTestingModule]
CoreTestingModule
]
}); });
formService = new FormService(); formService = new FormService();
}); });
@@ -132,10 +130,7 @@ describe('FormModel', () => {
it('should parse tabs', () => { it('should parse tabs', () => {
const json = { const json = {
tabs: [ tabs: [{ id: 'tab1' }, { id: 'tab2' }]
{ id: 'tab1' },
{ id: 'tab2' }
]
}; };
const form = new FormModel(json); const form = new FormModel(json);
@@ -199,10 +194,7 @@ describe('FormModel', () => {
it('should put fields into corresponding tabs', () => { it('should put fields into corresponding tabs', () => {
const json = { const json = {
tabs: [ tabs: [{ id: 'tab1' }, { id: 'tab2' }],
{ id: 'tab1' },
{ id: 'tab2' }
],
fields: [ fields: [
{ id: 'field1', tab: 'tab1', type: FormFieldTypes.CONTAINER }, { id: 'field1', tab: 'tab1', type: FormFieldTypes.CONTAINER },
{ id: 'field2', tab: 'tab2', type: FormFieldTypes.CONTAINER }, { id: 'field2', tab: 'tab2', type: FormFieldTypes.CONTAINER },
@@ -227,9 +219,7 @@ describe('FormModel', () => {
it('should create standard form outcomes', () => { it('should create standard form outcomes', () => {
const json = { const json = {
fields: [ fields: [{ id: 'container1' }]
{ id: 'container1' }
]
}; };
const form = new FormModel(json); const form = new FormModel(json);
@@ -255,12 +245,8 @@ describe('FormModel', () => {
it('should use custom form outcomes', () => { it('should use custom form outcomes', () => {
const json = { const json = {
fields: [ fields: [{ id: 'container1' }],
{ id: 'container1' } outcomes: [{ id: 'custom-1', name: 'custom 1' }]
],
outcomes: [
{ id: 'custom-1', name: 'custom 1' }
]
}; };
const form = new FormModel(json); const form = new FormModel(json);
@@ -273,26 +259,28 @@ describe('FormModel', () => {
expect(form.outcomes[1].isSystem).toBeFalsy(); 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); const form = new FormModel({}, null, false, formService);
formService.validateForm.subscribe((validateFormEvent) => formService.validateForm.subscribe((validateFormEvent) => {
expect(validateFormEvent).toBeTruthy() expect(validateFormEvent).toBeTruthy();
); done();
});
form.validateForm(); 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 form = new FormModel({}, null, false, formService);
const field = jasmine.createSpyObj('FormFieldModel', ['validate']); const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
formService.validateFormField.subscribe((validateFormFieldEvent) => formService.validateFormField.subscribe((validateFormFieldEvent) => {
expect(validateFormFieldEvent).toBeTruthy() expect(validateFormFieldEvent).toBeTruthy();
); done();
});
form.validateField(field); 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); const form = new FormModel({}, null, false, formService);
let prevented = false; let prevented = false;
@@ -301,6 +289,7 @@ describe('FormModel', () => {
event.isValid = false; event.isValid = false;
event.preventDefault(); event.preventDefault();
prevented = true; prevented = true;
done();
}); });
const field = jasmine.createSpyObj('FormFieldModel', ['validate']); const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
@@ -311,13 +300,14 @@ describe('FormModel', () => {
expect(field.validate).not.toHaveBeenCalled(); 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); const form = new FormModel(fakeMetadataForm, null, false, formService);
let validated = false; let validated = false;
formService.validateForm.subscribe(() => { formService.validateForm.subscribe(() => {
validated = true; validated = true;
done();
}); });
const field = jasmine.createSpyObj('FormFieldModel', ['validate']); const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
@@ -329,13 +319,14 @@ describe('FormModel', () => {
expect(field.validate).toHaveBeenCalled(); 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); const form = new FormModel({}, null, false, formService);
let validated = false; let validated = false;
formService.validateFormField.subscribe(() => { formService.validateFormField.subscribe(() => {
validated = true; validated = true;
done();
}); });
const field = jasmine.createSpyObj('FormFieldModel', ['validate']); const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
@@ -345,7 +336,7 @@ describe('FormModel', () => {
expect(field.validate).toHaveBeenCalled(); 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); const form = new FormModel({}, null, false, formService);
spyOn(form, 'validateForm').and.stub(); spyOn(form, 'validateForm').and.stub();
@@ -353,6 +344,7 @@ describe('FormModel', () => {
formService.validateFormField.subscribe(() => { formService.validateFormField.subscribe(() => {
validated = true; validated = true;
done();
}); });
const field: any = { const field: any = {
@@ -364,7 +356,7 @@ describe('FormModel', () => {
expect(form.validateForm).toHaveBeenCalled(); 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); const form = new FormModel({}, null, false, formService);
spyOn(form, 'validateForm').and.stub(); spyOn(form, 'validateForm').and.stub();
@@ -373,6 +365,7 @@ describe('FormModel', () => {
formService.validateFormField.subscribe((event: ValidateFormFieldEvent) => { formService.validateFormField.subscribe((event: ValidateFormFieldEvent) => {
event.preventDefault(); event.preventDefault();
prevented = true; prevented = true;
done();
}); });
const field = jasmine.createSpyObj('FormFieldModel', ['validate']); const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
@@ -503,6 +496,17 @@ describe('FormModel', () => {
processInstanceId: '1be4785f-c982-11e9-bdd8-96d6903e4e44', processInstanceId: '1be4785f-c982-11e9-bdd8-96d6903e4e44',
taskId: '1beab9f6-c982-11e9-bdd8-96d6903e4e44', taskId: '1beab9f6-c982-11e9-bdd8-96d6903e4e44',
taskVariable: true 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'); expect(value).toBe('29.09.2019T00:00:00.000Z');
}); });
it('should find a process variable by name', () => { [
const value = form.getProcessVariableValue('booleanVar'); { name: 'booleanVar', result: true },
expect(value).toEqual(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', () => { 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_six']).toEqual('text-value');
expect(form.values['pfx_property_seven']).toBeNull(); expect(form.values['pfx_property_seven']).toBeNull();
expect(form.values['pfx_property_eight']).toBeNull(); expect(form.values['pfx_property_eight']).toBeNull();
}); });
}); });

View File

@@ -313,7 +313,7 @@ export class FormModel implements ProcessFormModel {
if (type && value) { if (type && value) {
switch (type) { switch (type) {
case 'date': case 'date':
return value ? `${value}T00:00:00.000Z` : undefined; return value.toString().includes('T') ? value : `${value}T00:00:00.000Z`;
case 'boolean': case 'boolean':
return typeof value === 'string' ? JSON.parse(value) : value; return typeof value === 'string' ? JSON.parse(value) : value;
default: default: