[ADF-5259] - addded unit test for custom widget (#6202)

Co-authored-by: Vito Albano <vitoalbano@vitoalbano-mbp-0120.local>
This commit is contained in:
Vito 2020-10-02 13:51:15 +01:00 committed by GitHub
parent d83bc9935c
commit e22bdc7f4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 173 additions and 1 deletions

View File

@ -30,10 +30,14 @@ import { formDisplayValueVisibility,
numberMinMaxForm,
textWidgetVisibility,
numberWidgetVisibilityForm,
radioWidgetVisibiltyForm } from './mock/form-renderer.component.mock';
radioWidgetVisibiltyForm,
customWidgetForm,
customWidgetFormWithVisibility } from './mock/form-renderer.component.mock';
import { FormService } from '../services/form.service';
import { CoreTestingModule } from '../../testing';
import { TranslateModule } from '@ngx-translate/core';
import { FormRenderingService } from '../services/form-rendering.service';
import { TextWidgetComponent } from './widgets';
function typeIntoInput(targetInput: HTMLInputElement, message: string ) {
expect(targetInput).not.toBeNull('Expected input to set to be valid and not null');
@ -75,6 +79,7 @@ describe('Form Renderer Component', () => {
let formRendererComponent: FormRendererComponent;
let fixture: ComponentFixture<FormRendererComponent>;
let formService: FormService;
let formRenderingService: FormRenderingService;
setupTestBed({
imports: [
@ -88,6 +93,7 @@ describe('Form Renderer Component', () => {
fixture = TestBed.createComponent(FormRendererComponent);
formRendererComponent = fixture.componentInstance;
formService = TestBed.inject(FormService);
formRenderingService = TestBed.inject(FormRenderingService);
});
afterEach(() => {
@ -560,4 +566,34 @@ describe('Form Renderer Component', () => {
});
});
describe('Custom Widget', () => {
it('Should be able to correctly display a custom process cloud widget', async () => {
formRenderingService.register({'bananaforevah': () => TextWidgetComponent}, true);
formRendererComponent.formDefinition = formService.parseForm(customWidgetForm.formRepresentation.formDefinition);
fixture.detectChanges();
await fixture.whenStable();
const textInputElement = fixture.nativeElement.querySelector('#Text0vdi18');
const customWidgetElement = fixture.nativeElement.querySelector('#bananaforevah0k8gui');
expectElementToBeVisible(textInputElement);
expectElementToBeVisible(customWidgetElement);
});
it('Should be able to correctly use visibility in a custom process cloud widget ', async () => {
formRenderingService.register({'bananaforevah': () => TextWidgetComponent}, true);
formRendererComponent.formDefinition = formService.parseForm(customWidgetFormWithVisibility.formRepresentation.formDefinition);
fixture.detectChanges();
await fixture.whenStable();
const textInputElement = fixture.nativeElement.querySelector('#Text0vdi18');
let customWidgetElementContainer = fixture.nativeElement.querySelector('#field-bananaforevah0k8gui-container');
expectElementToBeHidden(customWidgetElementContainer);
typeIntoInput(textInputElement, 'no');
fixture.detectChanges();
await fixture.whenStable();
customWidgetElementContainer = fixture.nativeElement.querySelector('#field-bananaforevah0k8gui-container');
expectElementToBeVisible(customWidgetElementContainer);
});
});
});

View File

@ -1334,3 +1334,139 @@ export const radioWidgetVisibiltyForm = {
}
}
};
export const customWidgetForm = {
formRepresentation: {
id: 'form-bf7fe50b-c193-41c0-b835-637bf6593e41',
name: 'formformformformbananaform',
description: 'Read it while you sing banana phone please',
version: 0,
standAlone: true,
formDefinition: {
tabs: [],
fields: [
{
id: '07672e71-2f3d-4e3a-a0c6-ccaf76a8d3a1',
name: 'Label',
type: 'container',
tab: null,
numberOfColumns: 2,
fields: {
'1': [
{
id: 'Text0vdi18',
name: 'herejustoshowstandardones',
type: 'text',
readOnly: false,
required: false,
colspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
],
'2': [
{
id: 'bananaforevah0k8gui',
name: 'bananaforevah',
type: 'bananaforevah',
required: true,
readOnly: false,
isCustomType: true,
valueType: 'json',
widgetId: '72f32b8b-505c-4f55-a08c-e2d0edd5bc9d',
colspan: 1,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
]
}
}
],
outcomes: [],
metadata: {},
variables: []
}
}
};
export const customWidgetFormWithVisibility = {
formRepresentation: {
id: 'form-bf7fe50b-c193-41c0-b835-637bf6593e41',
name: 'formformformformbananaform',
description: 'Read it while you sing banana phone please',
version: 0,
standAlone: true,
formDefinition: {
tabs: [],
fields: [
{
id: '07672e71-2f3d-4e3a-a0c6-ccaf76a8d3a1',
name: 'Label',
type: 'container',
tab: null,
numberOfColumns: 2,
fields: {
'1': [
{
id: 'Text0vdi18',
name: 'herejustoshowstandardones',
type: 'text',
readOnly: false,
required: false,
colspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
],
'2': [
{
id: 'bananaforevah0k8gui',
name: 'bananaforevah',
type: 'bananaforevah',
required: true,
readOnly: false,
isCustomType: true,
valueType: 'json',
widgetId: '72f32b8b-505c-4f55-a08c-e2d0edd5bc9d',
colspan: 1,
visibilityCondition: {
leftType: 'field',
leftValue: 'Text0vdi18',
operator: '==',
rightValue: 'no',
rightType: 'value',
nextConditionOperator: '',
nextCondition: null
},
params: {
existingColspan: 1,
maxColspan: 2
}
}
]
}
}
],
outcomes: [],
metadata: {},
variables: []
}
}
};