mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-21755 Error when form is assigned to process start event (#9509)
* AAE-21755 Error when form is assigned to process start event * fix unit * Fix unit v2 * update
This commit is contained in:
@@ -19,21 +19,26 @@
|
|||||||
|
|
||||||
import { VersionCompatibilityService } from '@alfresco/adf-content-services';
|
import { VersionCompatibilityService } from '@alfresco/adf-content-services';
|
||||||
import {
|
import {
|
||||||
AlfrescoApiService, ContentLinkModel, CoreModule,
|
AlfrescoApiService,
|
||||||
|
ContentLinkModel,
|
||||||
|
CoreModule,
|
||||||
FormFieldModel,
|
FormFieldModel,
|
||||||
FormFieldTypes,
|
FormFieldTypes,
|
||||||
FormModel,
|
FormModel,
|
||||||
FormOutcomeEvent,
|
FormOutcomeEvent,
|
||||||
FormOutcomeModel, FormRenderingService, FormService,
|
FormOutcomeModel,
|
||||||
UploadWidgetContentLinkModel, WidgetVisibilityService, provideTranslations, AuthModule
|
FormRenderingService,
|
||||||
|
FormService,
|
||||||
|
UploadWidgetContentLinkModel,
|
||||||
|
WidgetVisibilityService,
|
||||||
|
provideTranslations,
|
||||||
|
AuthModule
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { Node } from '@alfresco/js-api';
|
import { Node } from '@alfresco/js-api';
|
||||||
import { ESCAPE } from '@angular/cdk/keycodes';
|
import { ESCAPE } from '@angular/cdk/keycodes';
|
||||||
import { HarnessLoader } from '@angular/cdk/testing';
|
import { HarnessLoader } from '@angular/cdk/testing';
|
||||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||||
import {
|
import { Component, ComponentFactoryResolver, Injector, SimpleChange } from '@angular/core';
|
||||||
Component, ComponentFactoryResolver, Injector, SimpleChange
|
|
||||||
} from '@angular/core';
|
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { MatDialogHarness } from '@angular/material/dialog/testing';
|
import { MatDialogHarness } from '@angular/material/dialog/testing';
|
||||||
@@ -47,7 +52,9 @@ import {
|
|||||||
cloudFormMock,
|
cloudFormMock,
|
||||||
conditionalUploadWidgetsMock,
|
conditionalUploadWidgetsMock,
|
||||||
emptyFormRepresentationJSON,
|
emptyFormRepresentationJSON,
|
||||||
fakeCloudForm, fakeMetadataForm, multilingualForm,
|
fakeCloudForm,
|
||||||
|
fakeMetadataForm,
|
||||||
|
multilingualForm,
|
||||||
formDefinitionThreeColumnMock
|
formDefinitionThreeColumnMock
|
||||||
} from '../mocks/cloud-form.mock';
|
} from '../mocks/cloud-form.mock';
|
||||||
import { FormCloudRepresentation } from '../models/form-cloud-representation.model';
|
import { FormCloudRepresentation } from '../models/form-cloud-representation.model';
|
||||||
@@ -99,9 +106,7 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [ProcessServiceCloudTestingModule],
|
||||||
ProcessServiceCloudTestingModule
|
|
||||||
],
|
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: VersionCompatibilityService,
|
provide: VersionCompatibilityService,
|
||||||
@@ -328,16 +333,22 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should get task variables if a task form is rendered', () => {
|
it('should get task variables if a task form is rendered', () => {
|
||||||
spyOn(formCloudService, 'getTaskForm').and.callFake((currentTaskId) => new Observable((observer) => {
|
spyOn(formCloudService, 'getTaskForm').and.callFake(
|
||||||
observer.next({ formRepresentation: { taskId: currentTaskId } });
|
(currentTaskId) =>
|
||||||
observer.complete();
|
new Observable((observer) => {
|
||||||
}));
|
observer.next({ formRepresentation: { taskId: currentTaskId } });
|
||||||
|
observer.complete();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
spyOn(formCloudService, 'getTask').and.callFake((currentTaskId) => new Observable((observer) => {
|
spyOn(formCloudService, 'getTask').and.callFake(
|
||||||
observer.next({ formRepresentation: { taskId: currentTaskId } } as any);
|
(currentTaskId) =>
|
||||||
observer.complete();
|
new Observable((observer) => {
|
||||||
}));
|
observer.next({ formRepresentation: { taskId: currentTaskId } } as any);
|
||||||
|
observer.complete();
|
||||||
|
})
|
||||||
|
);
|
||||||
const taskId = '123';
|
const taskId = '123';
|
||||||
const appName = 'test-app';
|
const appName = 'test-app';
|
||||||
|
|
||||||
@@ -349,10 +360,13 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not get task variables and form if task id is not specified', () => {
|
it('should not get task variables and form if task id is not specified', () => {
|
||||||
spyOn(formCloudService, 'getTaskForm').and.callFake((currentTaskId) => new Observable((observer) => {
|
spyOn(formCloudService, 'getTaskForm').and.callFake(
|
||||||
observer.next({ taskId: currentTaskId });
|
(currentTaskId) =>
|
||||||
observer.complete();
|
new Observable((observer) => {
|
||||||
}));
|
observer.next({ taskId: currentTaskId });
|
||||||
|
observer.complete();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
|
|
||||||
@@ -447,7 +461,7 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
let saved = false;
|
let saved = false;
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.formSaved.subscribe(() => saved = true);
|
formComponent.formSaved.subscribe(() => (saved = true));
|
||||||
spyOn(formComponent, 'completeTaskForm').and.stub();
|
spyOn(formComponent, 'completeTaskForm').and.stub();
|
||||||
|
|
||||||
const result = formComponent.onOutcomeClicked(outcome);
|
const result = formComponent.onOutcomeClicked(outcome);
|
||||||
@@ -498,7 +512,7 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
let saved = false;
|
let saved = false;
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.formSaved.subscribe(() => saved = true);
|
formComponent.formSaved.subscribe(() => (saved = true));
|
||||||
|
|
||||||
const result = formComponent.onOutcomeClicked(outcome);
|
const result = formComponent.onOutcomeClicked(outcome);
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
@@ -631,10 +645,13 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should save task form and raise corresponding event', () => {
|
it('should save task form and raise corresponding event', () => {
|
||||||
spyOn(formCloudService, 'saveTaskForm').and.callFake(() => new Observable((observer) => {
|
spyOn(formCloudService, 'saveTaskForm').and.callFake(
|
||||||
observer.next();
|
() =>
|
||||||
observer.complete();
|
new Observable((observer) => {
|
||||||
}));
|
observer.next();
|
||||||
|
observer.complete();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
let saved = false;
|
let saved = false;
|
||||||
let savedForm = null;
|
let savedForm = null;
|
||||||
@@ -650,10 +667,7 @@ describe('FormCloudComponent', () => {
|
|||||||
const formModel = new FormModel({
|
const formModel = new FormModel({
|
||||||
id: '23',
|
id: '23',
|
||||||
taskId,
|
taskId,
|
||||||
fields: [
|
fields: [{ id: 'field1' }, { id: 'field2' }]
|
||||||
{ id: 'field1' },
|
|
||||||
{ id: 'field2' }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.taskId = taskId;
|
formComponent.taskId = taskId;
|
||||||
@@ -677,10 +691,7 @@ describe('FormCloudComponent', () => {
|
|||||||
const formModel = new FormModel({
|
const formModel = new FormModel({
|
||||||
id: '23',
|
id: '23',
|
||||||
taskId,
|
taskId,
|
||||||
fields: [
|
fields: [{ id: 'field1' }, { id: 'field2' }]
|
||||||
{ id: 'field1' },
|
|
||||||
{ id: 'field2' }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.taskId = taskId;
|
formComponent.taskId = taskId;
|
||||||
@@ -727,14 +738,17 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should complete form and raise corresponding event', () => {
|
it('should complete form and raise corresponding event', () => {
|
||||||
spyOn(formCloudService, 'completeTaskForm').and.callFake(() => new Observable((observer) => {
|
spyOn(formCloudService, 'completeTaskForm').and.callFake(
|
||||||
observer.next();
|
() =>
|
||||||
observer.complete();
|
new Observable((observer) => {
|
||||||
}));
|
observer.next();
|
||||||
|
observer.complete();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const outcome = 'complete';
|
const outcome = 'complete';
|
||||||
let completed = false;
|
let completed = false;
|
||||||
formComponent.formCompleted.subscribe(() => completed = true);
|
formComponent.formCompleted.subscribe(() => (completed = true));
|
||||||
|
|
||||||
const taskId = '123-223';
|
const taskId = '123-223';
|
||||||
const appVersion = 1;
|
const appVersion = 1;
|
||||||
@@ -744,10 +758,7 @@ describe('FormCloudComponent', () => {
|
|||||||
const formModel = new FormModel({
|
const formModel = new FormModel({
|
||||||
id: '23',
|
id: '23',
|
||||||
taskId,
|
taskId,
|
||||||
fields: [
|
fields: [{ id: 'field1' }, { id: 'field2' }]
|
||||||
{ id: 'field1' },
|
|
||||||
{ id: 'field2' }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
formComponent.appVersion = appVersion;
|
formComponent.appVersion = appVersion;
|
||||||
@@ -757,7 +768,15 @@ describe('FormCloudComponent', () => {
|
|||||||
formComponent.processInstanceId = processInstanceId;
|
formComponent.processInstanceId = processInstanceId;
|
||||||
formComponent.completeTaskForm(outcome);
|
formComponent.completeTaskForm(outcome);
|
||||||
|
|
||||||
expect(formCloudService.completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values, outcome, appVersion);
|
expect(formCloudService.completeTaskForm).toHaveBeenCalledWith(
|
||||||
|
appName,
|
||||||
|
formModel.taskId,
|
||||||
|
processInstanceId,
|
||||||
|
formModel.id,
|
||||||
|
formModel.values,
|
||||||
|
outcome,
|
||||||
|
appVersion
|
||||||
|
);
|
||||||
expect(completed).toBeTruthy();
|
expect(completed).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -825,9 +844,7 @@ describe('FormCloudComponent', () => {
|
|||||||
it('should parse form from json', () => {
|
it('should parse form from json', () => {
|
||||||
const form = formComponent.parseForm({
|
const form = formComponent.parseForm({
|
||||||
id: '1',
|
id: '1',
|
||||||
fields: [
|
fields: [{ id: 'field1', type: FormFieldTypes.CONTAINER }]
|
||||||
{ id: 'field1', type: FormFieldTypes.CONTAINER }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(form).toBeDefined();
|
expect(form).toBeDefined();
|
||||||
@@ -837,7 +854,6 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should prevent default outcome execution', () => {
|
it('should prevent default outcome execution', () => {
|
||||||
|
|
||||||
const outcome = new FormOutcomeModel(new FormModel(), {
|
const outcome = new FormOutcomeModel(new FormModel(), {
|
||||||
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
||||||
name: 'Custom'
|
name: 'Custom'
|
||||||
@@ -875,7 +891,6 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should check visibility only if field with form provided', () => {
|
it('should check visibility only if field with form provided', () => {
|
||||||
|
|
||||||
formComponent.checkVisibility(null);
|
formComponent.checkVisibility(null);
|
||||||
expect(visibilityService.refreshVisibility).not.toHaveBeenCalled();
|
expect(visibilityService.refreshVisibility).not.toHaveBeenCalled();
|
||||||
|
|
||||||
@@ -993,7 +1008,10 @@ describe('FormCloudComponent', () => {
|
|||||||
expect(labelField.value).toBeNull();
|
expect(labelField.value).toBeNull();
|
||||||
expect(radioField.value).toBeNull();
|
expect(radioField.value).toBeNull();
|
||||||
|
|
||||||
const formValues: any[] = [{ name: 'text1', value: 'test' }, { name: 'number1', value: 99 }];
|
const formValues: any[] = [
|
||||||
|
{ name: 'text1', value: 'test' },
|
||||||
|
{ name: 'number1', value: 99 }
|
||||||
|
];
|
||||||
|
|
||||||
const change = new SimpleChange(null, formValues, false);
|
const change = new SimpleChange(null, formValues, false);
|
||||||
formComponent.data = formValues;
|
formComponent.data = formValues;
|
||||||
@@ -1011,6 +1029,19 @@ describe('FormCloudComponent', () => {
|
|||||||
formComponent.ngOnChanges({ data: change });
|
formComponent.ngOnChanges({ data: change });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should work with empty form JSON representaiton when refreashing form', () => {
|
||||||
|
formComponent.form = new FormModel(JSON.parse(JSON.stringify(cloudFormMock)));
|
||||||
|
formComponent.formCloudRepresentationJSON = undefined;
|
||||||
|
|
||||||
|
const formValues: any[] = [
|
||||||
|
{ name: 'text1', value: 'test' },
|
||||||
|
{ name: 'number1', value: 99 }
|
||||||
|
];
|
||||||
|
const change = new SimpleChange(null, formValues, false);
|
||||||
|
|
||||||
|
expect(() => formComponent.ngOnChanges({ data: change })).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
it('should refresh radio buttons value when id is given to data', () => {
|
it('should refresh radio buttons value when id is given to data', () => {
|
||||||
formComponent.form = new FormModel(JSON.parse(JSON.stringify(cloudFormMock)));
|
formComponent.form = new FormModel(JSON.parse(JSON.stringify(cloudFormMock)));
|
||||||
formComponent.formCloudRepresentationJSON = new FormCloudRepresentation(JSON.parse(JSON.stringify(cloudFormMock)));
|
formComponent.formCloudRepresentationJSON = new FormCloudRepresentation(JSON.parse(JSON.stringify(cloudFormMock)));
|
||||||
@@ -1046,22 +1077,32 @@ describe('FormCloudComponent', () => {
|
|||||||
const errorMessage = 'Something went wrong.';
|
const errorMessage = 'Something went wrong.';
|
||||||
spyOn(formCloudService, 'completeTaskForm').and.callFake(() => throwError(errorMessage));
|
spyOn(formCloudService, 'completeTaskForm').and.callFake(() => throwError(errorMessage));
|
||||||
|
|
||||||
formCloudService.completeTaskForm('test-app', '123', '333-444', '123', {
|
formCloudService
|
||||||
pfx_property_one: 'testValue',
|
.completeTaskForm(
|
||||||
pfx_property_two: true,
|
'test-app',
|
||||||
pfx_property_three: 'opt_1',
|
'123',
|
||||||
pfx_property_four: 'option_2',
|
'333-444',
|
||||||
pfx_property_five: 'orange',
|
'123',
|
||||||
pfx_property_none: 'no_form_field'
|
{
|
||||||
}, 'Complete', 123).subscribe({
|
pfx_property_one: 'testValue',
|
||||||
next: () => done.fail('expected an error, not data'),
|
pfx_property_two: true,
|
||||||
error: error => {
|
pfx_property_three: 'opt_1',
|
||||||
expect(error).toBe(errorMessage);
|
pfx_property_four: 'option_2',
|
||||||
expect(formComponent.disableSaveButton).toBeFalse();
|
pfx_property_five: 'orange',
|
||||||
expect(formComponent.disableCompleteButton).toBeFalse();
|
pfx_property_none: 'no_form_field'
|
||||||
done();
|
},
|
||||||
}
|
'Complete',
|
||||||
});
|
123
|
||||||
|
)
|
||||||
|
.subscribe({
|
||||||
|
next: () => done.fail('expected an error, not data'),
|
||||||
|
error: (error) => {
|
||||||
|
expect(error).toBe(errorMessage);
|
||||||
|
expect(formComponent.disableSaveButton).toBeFalse();
|
||||||
|
expect(formComponent.disableCompleteButton).toBeFalse();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render header and three text field columns', () => {
|
it('should render header and three text field columns', () => {
|
||||||
@@ -1072,8 +1113,8 @@ describe('FormCloudComponent', () => {
|
|||||||
const columns = fixture.debugElement.queryAll(By.css('.adf-grid-list-single-column'));
|
const columns = fixture.debugElement.queryAll(By.css('.adf-grid-list-single-column'));
|
||||||
|
|
||||||
expect(columns.length).toEqual(3);
|
expect(columns.length).toEqual(3);
|
||||||
columns.forEach(column => expect(column.styles.width).toEqual('33.3333%'));
|
columns.forEach((column) => expect(column.styles.width).toEqual('33.3333%'));
|
||||||
columns.forEach(column => {
|
columns.forEach((column) => {
|
||||||
const input = column.query(By.css('input[matinput]'));
|
const input = column.query(By.css('input[matinput]'));
|
||||||
expect(input.attributes.type).toEqual('text');
|
expect(input.attributes.type).toEqual('text');
|
||||||
});
|
});
|
||||||
@@ -1146,7 +1187,6 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Full screen', async () => {
|
describe('Full screen', async () => {
|
||||||
|
|
||||||
let displayModeOnSpy: jasmine.Spy;
|
let displayModeOnSpy: jasmine.Spy;
|
||||||
let displayModeOffSpy: jasmine.Spy;
|
let displayModeOffSpy: jasmine.Spy;
|
||||||
|
|
||||||
@@ -1156,7 +1196,9 @@ describe('FormCloudComponent', () => {
|
|||||||
* @param form The form model to be loaded
|
* @param form The form model to be loaded
|
||||||
*/
|
*/
|
||||||
async function loadForm(form?: any): Promise<void> {
|
async function loadForm(form?: any): Promise<void> {
|
||||||
formComponent.ngOnChanges({ form: { currentValue: formComponent.parseForm(form || {}), firstChange: true, isFirstChange: () => true, previousValue: undefined } });
|
formComponent.ngOnChanges({
|
||||||
|
form: { currentValue: formComponent.parseForm(form || {}), firstChange: true, isFirstChange: () => true, previousValue: undefined }
|
||||||
|
});
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}
|
}
|
||||||
@@ -1164,7 +1206,9 @@ describe('FormCloudComponent', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
displayModeOnSpy = spyOn(formComponent.displayModeOn, 'emit').and.stub();
|
displayModeOnSpy = spyOn(formComponent.displayModeOn, 'emit').and.stub();
|
||||||
displayModeOffSpy = spyOn(formComponent.displayModeOff, 'emit').and.stub();
|
displayModeOffSpy = spyOn(formComponent.displayModeOff, 'emit').and.stub();
|
||||||
spyOn(displayModeService, 'getDefaultDisplayModeConfigurations').and.callFake(() => DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS);
|
spyOn(displayModeService, 'getDefaultDisplayModeConfigurations').and.callFake(
|
||||||
|
() => DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS
|
||||||
|
);
|
||||||
|
|
||||||
formComponent.taskId = 'any';
|
formComponent.taskId = 'any';
|
||||||
formComponent.appName = 'any';
|
formComponent.appName = 'any';
|
||||||
@@ -1286,7 +1330,8 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should display the toolbar with the nameless task title when the task name is not provided and toolbar is enabled', () => {
|
it('should display the toolbar with the nameless task title when the task name is not provided and toolbar is enabled', () => {
|
||||||
const cloudFormToolbarDisplayName: HTMLSpanElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-form__display-name');
|
const cloudFormToolbarDisplayName: HTMLSpanElement =
|
||||||
|
fixture.debugElement.nativeElement.querySelector('.adf-cloud-form__display-name');
|
||||||
expect(cloudFormToolbarDisplayName).not.toBeNull();
|
expect(cloudFormToolbarDisplayName).not.toBeNull();
|
||||||
expect(cloudFormToolbarDisplayName.textContent.trim()).toEqual('Nameless task');
|
expect(cloudFormToolbarDisplayName.textContent.trim()).toEqual('Nameless task');
|
||||||
});
|
});
|
||||||
@@ -1296,7 +1341,8 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
await loadForm({ displayMode: FormCloudDisplayMode.fullScreen, taskName });
|
await loadForm({ displayMode: FormCloudDisplayMode.fullScreen, taskName });
|
||||||
|
|
||||||
const cloudFormToolbarDisplayName: HTMLSpanElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-form__display-name');
|
const cloudFormToolbarDisplayName: HTMLSpanElement =
|
||||||
|
fixture.debugElement.nativeElement.querySelector('.adf-cloud-form__display-name');
|
||||||
expect(cloudFormToolbarDisplayName).not.toBeNull();
|
expect(cloudFormToolbarDisplayName).not.toBeNull();
|
||||||
expect(cloudFormToolbarDisplayName.textContent.trim()).toEqual(taskName);
|
expect(cloudFormToolbarDisplayName.textContent.trim()).toEqual(taskName);
|
||||||
});
|
});
|
||||||
@@ -1306,10 +1352,10 @@ describe('FormCloudComponent', () => {
|
|||||||
{
|
{
|
||||||
displayMode: FormCloudDisplayMode.fullScreen,
|
displayMode: FormCloudDisplayMode.fullScreen,
|
||||||
options: {
|
options: {
|
||||||
onCompleteTask: () => { },
|
onCompleteTask: () => {},
|
||||||
onDisplayModeOff: () => { },
|
onDisplayModeOff: () => {},
|
||||||
onDisplayModeOn: () => { },
|
onDisplayModeOn: () => {},
|
||||||
onSaveTask: () => { },
|
onSaveTask: () => {},
|
||||||
displayToolbar: false
|
displayToolbar: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1345,7 +1391,10 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
it('should close fullScreen when completing the task', () => {
|
it('should close fullScreen when completing the task', () => {
|
||||||
const formRenderingServiceOnCompleteTaskSpy = spyOn(displayModeService, 'onCompleteTask').and.callThrough();
|
const formRenderingServiceOnCompleteTaskSpy = spyOn(displayModeService, 'onCompleteTask').and.callThrough();
|
||||||
const onCompleteTaskSpy = spyOn(DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS[1].options, 'onCompleteTask').and.callThrough();
|
const onCompleteTaskSpy = spyOn(
|
||||||
|
DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS[1].options,
|
||||||
|
'onCompleteTask'
|
||||||
|
).and.callThrough();
|
||||||
const formRenderingServiceChangeDisplayModeSpy = spyOn(DisplayModeService, 'changeDisplayMode').and.callThrough();
|
const formRenderingServiceChangeDisplayModeSpy = spyOn(DisplayModeService, 'changeDisplayMode').and.callThrough();
|
||||||
|
|
||||||
displayModeOnSpy.calls.reset();
|
displayModeOnSpy.calls.reset();
|
||||||
@@ -1353,16 +1402,22 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
formComponent.completeTaskForm();
|
formComponent.completeTaskForm();
|
||||||
|
|
||||||
expect(formRenderingServiceOnCompleteTaskSpy).toHaveBeenCalledOnceWith(formComponent.id, FormCloudDisplayMode.fullScreen, DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS);
|
expect(formRenderingServiceOnCompleteTaskSpy).toHaveBeenCalledOnceWith(
|
||||||
|
formComponent.id,
|
||||||
|
FormCloudDisplayMode.fullScreen,
|
||||||
|
DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS
|
||||||
|
);
|
||||||
expect(onCompleteTaskSpy).toHaveBeenCalledOnceWith(formComponent.id);
|
expect(onCompleteTaskSpy).toHaveBeenCalledOnceWith(formComponent.id);
|
||||||
expect(formRenderingServiceChangeDisplayModeSpy).toHaveBeenCalledOnceWith({ id: formComponent.id, displayMode: FormCloudDisplayMode.inline });
|
expect(formRenderingServiceChangeDisplayModeSpy).toHaveBeenCalledOnceWith({
|
||||||
|
id: formComponent.id,
|
||||||
|
displayMode: FormCloudDisplayMode.inline
|
||||||
|
});
|
||||||
expect(displayModeOffSpy).toHaveBeenCalledOnceWith(DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS[1]);
|
expect(displayModeOffSpy).toHaveBeenCalledOnceWith(DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS[1]);
|
||||||
expect(displayModeOnSpy).toHaveBeenCalledOnceWith(DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS[0]);
|
expect(displayModeOnSpy).toHaveBeenCalledOnceWith(DisplayModeService.IMPLEMENTED_DISPLAY_MODE_CONFIGURATIONS[0]);
|
||||||
expect(formComponent.displayMode).toBe(FormCloudDisplayMode.inline);
|
expect(formComponent.displayMode).toBe(FormCloudDisplayMode.inline);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Multilingual Form', () => {
|
describe('Multilingual Form', () => {
|
||||||
@@ -1380,9 +1435,7 @@ describe('Multilingual Form', () => {
|
|||||||
CoreModule.forRoot(),
|
CoreModule.forRoot(),
|
||||||
ProcessServicesCloudModule.forRoot()
|
ProcessServicesCloudModule.forRoot()
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [provideTranslations('app', 'resources')]
|
||||||
provideTranslations('app', 'resources')
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
translateService = TestBed.inject(TranslateService);
|
translateService = TestBed.inject(TranslateService);
|
||||||
formCloudService = TestBed.inject(FormCloudService);
|
formCloudService = TestBed.inject(FormCloudService);
|
||||||
@@ -1449,13 +1502,7 @@ describe('retrieve metadata on submit', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [AuthModule.forRoot({ useHash: true }), NoopAnimationsModule, TranslateModule.forRoot(), CoreModule.forRoot(), FormCloudModule],
|
||||||
AuthModule.forRoot({ useHash: true }),
|
|
||||||
NoopAnimationsModule,
|
|
||||||
TranslateModule.forRoot(),
|
|
||||||
CoreModule.forRoot(),
|
|
||||||
FormCloudModule
|
|
||||||
],
|
|
||||||
providers: [
|
providers: [
|
||||||
provideTranslations('app', 'resources'),
|
provideTranslations('app', 'resources'),
|
||||||
{
|
{
|
||||||
@@ -1506,7 +1553,10 @@ describe('retrieve metadata on submit', () => {
|
|||||||
it('should call setNodeIdValueForViewersLinkedToUploadWidget when content is UploadWidgetContentLinkModel', async () => {
|
it('should call setNodeIdValueForViewersLinkedToUploadWidget when content is UploadWidgetContentLinkModel', async () => {
|
||||||
const uploadWidgetContentLinkModel = new UploadWidgetContentLinkModel(fakeNodeWithProperties, 'attach-file-alfresco');
|
const uploadWidgetContentLinkModel = new UploadWidgetContentLinkModel(fakeNodeWithProperties, 'attach-file-alfresco');
|
||||||
|
|
||||||
const setNodeIdValueForViewersLinkedToUploadWidget = spyOn<any>(formComponent.form, 'setNodeIdValueForViewersLinkedToUploadWidget').and.callThrough();
|
const setNodeIdValueForViewersLinkedToUploadWidget = spyOn<any>(
|
||||||
|
formComponent.form,
|
||||||
|
'setNodeIdValueForViewersLinkedToUploadWidget'
|
||||||
|
).and.callThrough();
|
||||||
const formDataRefreshed = spyOn<any>(formComponent.formDataRefreshed, 'emit').and.callThrough();
|
const formDataRefreshed = spyOn<any>(formComponent.formDataRefreshed, 'emit').and.callThrough();
|
||||||
const formContentClicked = spyOn<any>(formComponent.formContentClicked, 'emit').and.callThrough();
|
const formContentClicked = spyOn<any>(formComponent.formContentClicked, 'emit').and.callThrough();
|
||||||
|
|
||||||
@@ -1520,7 +1570,10 @@ describe('retrieve metadata on submit', () => {
|
|||||||
it('should not call setNodeIdValueForViewersLinkedToUploadWidget when content is not UploadWidgetContentLinkModel', async () => {
|
it('should not call setNodeIdValueForViewersLinkedToUploadWidget when content is not UploadWidgetContentLinkModel', async () => {
|
||||||
const contentLinkModel = new ContentLinkModel(fakeNodeWithProperties);
|
const contentLinkModel = new ContentLinkModel(fakeNodeWithProperties);
|
||||||
|
|
||||||
const setNodeIdValueForViewersLinkedToUploadWidget = spyOn<any>(formComponent.form, 'setNodeIdValueForViewersLinkedToUploadWidget').and.callThrough();
|
const setNodeIdValueForViewersLinkedToUploadWidget = spyOn<any>(
|
||||||
|
formComponent.form,
|
||||||
|
'setNodeIdValueForViewersLinkedToUploadWidget'
|
||||||
|
).and.callThrough();
|
||||||
const formDataRefreshed = spyOn<any>(formComponent.formDataRefreshed, 'emit').and.callThrough();
|
const formDataRefreshed = spyOn<any>(formComponent.formDataRefreshed, 'emit').and.callThrough();
|
||||||
const formContentClicked = spyOn<any>(formComponent.formContentClicked, 'emit').and.callThrough();
|
const formContentClicked = spyOn<any>(formComponent.formContentClicked, 'emit').and.callThrough();
|
||||||
|
|
||||||
|
@@ -201,14 +201,18 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
DisplayModeService.displayMode$
|
DisplayModeService.displayMode$
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(change => change.id === this.id),
|
filter((change) => change.id === this.id),
|
||||||
takeUntil(this.onDestroy$)
|
takeUntil(this.onDestroy$)
|
||||||
).subscribe((displayModeChange) => {
|
)
|
||||||
|
.subscribe((displayModeChange) => {
|
||||||
const oldDisplayMode = this.displayMode;
|
const oldDisplayMode = this.displayMode;
|
||||||
this.displayMode = displayModeChange.displayMode;
|
this.displayMode = displayModeChange.displayMode;
|
||||||
|
|
||||||
const oldDisplayModeConfiguration = this.displayModeService.findConfiguration(oldDisplayMode, this.displayModeConfigurations);
|
const oldDisplayModeConfiguration = this.displayModeService.findConfiguration(oldDisplayMode, this.displayModeConfigurations);
|
||||||
const newDisplayModeConfiguration = this.displayModeService.findConfiguration(displayModeChange.displayMode, this.displayModeConfigurations);
|
const newDisplayModeConfiguration = this.displayModeService.findConfiguration(
|
||||||
|
displayModeChange.displayMode,
|
||||||
|
this.displayModeConfigurations
|
||||||
|
);
|
||||||
|
|
||||||
if (oldDisplayModeConfiguration?.displayMode !== newDisplayModeConfiguration?.displayMode) {
|
if (oldDisplayModeConfiguration?.displayMode !== newDisplayModeConfiguration?.displayMode) {
|
||||||
if (oldDisplayModeConfiguration) {
|
if (oldDisplayModeConfiguration) {
|
||||||
@@ -295,7 +299,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
this.formCloudRepresentationJSON = form;
|
this.formCloudRepresentationJSON = form;
|
||||||
const parsedForm = this.parseForm(form);
|
const parsedForm = this.parseForm(form);
|
||||||
this.visibilityService.refreshVisibility(parsedForm);
|
this.visibilityService.refreshVisibility(parsedForm);
|
||||||
parsedForm.validateForm();
|
parsedForm?.validateForm();
|
||||||
this.form = parsedForm;
|
this.form = parsedForm;
|
||||||
this.form.nodeId = '-my-';
|
this.form.nodeId = '-my-';
|
||||||
this.onFormLoaded(this.form);
|
this.onFormLoaded(this.form);
|
||||||
@@ -355,7 +359,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseForm(formCloudRepresentationJSON: any): FormModel {
|
parseForm(formCloudRepresentationJSON?: any): FormModel | null {
|
||||||
if (formCloudRepresentationJSON) {
|
if (formCloudRepresentationJSON) {
|
||||||
const formValues: FormValues = {};
|
const formValues: FormValues = {};
|
||||||
(this.data || []).forEach((variable) => {
|
(this.data || []).forEach((variable) => {
|
||||||
@@ -397,9 +401,17 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected onFormLoaded(form: FormModel) {
|
protected onFormLoaded(form: FormModel) {
|
||||||
this.displayModeConfigurations = this.displayModeService.getDisplayModeConfigurations(this.displayModeConfigurations);
|
if (form) {
|
||||||
this.displayMode = this.displayModeService.switchToDisplayMode(this.id, this.form.json.displayMode, this.displayMode, this.displayModeConfigurations);
|
this.displayModeConfigurations = this.displayModeService.getDisplayModeConfigurations(this.displayModeConfigurations);
|
||||||
this.displayModeOn.emit(this.displayModeService.findConfiguration(this.displayMode, this.displayModeConfigurations));
|
this.displayMode = this.displayModeService.switchToDisplayMode(
|
||||||
|
this.id,
|
||||||
|
this.form.json.displayMode,
|
||||||
|
this.displayMode,
|
||||||
|
this.displayModeConfigurations
|
||||||
|
);
|
||||||
|
this.displayModeOn.emit(this.displayModeService.findConfiguration(this.displayMode, this.displayModeConfigurations));
|
||||||
|
}
|
||||||
|
|
||||||
this.formLoaded.emit(form);
|
this.formLoaded.emit(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +446,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
return !args.defaultPrevented;
|
return !args.defaultPrevented;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected storeFormAsMetadata() { }
|
protected storeFormAsMetadata() {}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.onDestroy$.next(true);
|
this.onDestroy$.next(true);
|
||||||
|
Reference in New Issue
Block a user