Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-30168 Form Display Value does not show date variable #10593

Merged
83 changes: 46 additions & 37 deletions lib/core/src/lib/form/components/widgets/core/form.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ describe('FormModel', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CoreTestingModule
]
imports: [CoreTestingModule]
});
formService = new FormService();
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 },
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -301,6 +289,7 @@ describe('FormModel', () => {
event.isValid = false;
event.preventDefault();
prevented = true;
done();
});

const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
Expand All @@ -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']);
Expand All @@ -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']);
Expand All @@ -345,14 +336,15 @@ 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();

let validated = false;

formService.validateFormField.subscribe(() => {
validated = true;
done();
});

const field: any = {
Expand All @@ -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();

Expand All @@ -373,6 +365,7 @@ describe('FormModel', () => {
formService.validateFormField.subscribe((event: ValidateFormFieldEvent) => {
event.preventDefault();
prevented = true;
done();
});

const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
Expand Down Expand Up @@ -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'
}
];

Expand Down Expand Up @@ -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`, () => {
mkrbr marked this conversation as resolved.
Show resolved Hide resolved
const value = form.getProcessVariableValue(name);
expect(value).toEqual(result);
});
});

it('should not find a process variable', () => {
Expand Down Expand Up @@ -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();

});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
fkindgen marked this conversation as resolved.
Show resolved Hide resolved
case 'boolean':
return typeof value === 'string' ? JSON.parse(value) : value;
default:
Expand Down
Loading