mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-1945 - Added extra form unit test (#5524)
* AAE-1945 - start adding test form rendering for task-details * Added last unit test for AAE-1945 * AAE-1945 - removed wrong fdescribe * AAE-1945 - fixed whitespace * AAE-1945 - fixed wrong promise errored * AAE-1945 - fixed failing unit test
This commit is contained in:
@@ -21,8 +21,11 @@ import { FormFieldModel, FormFieldTypes, FormModel } from './../widgets/core/ind
|
|||||||
import { TextWidgetComponent, CheckboxWidgetComponent } from '../widgets/index';
|
import { TextWidgetComponent, CheckboxWidgetComponent } from '../widgets/index';
|
||||||
import { FormFieldComponent } from './form-field.component';
|
import { FormFieldComponent } from './form-field.component';
|
||||||
import { setupTestBed } from '../../../testing/setup-test-bed';
|
import { setupTestBed } from '../../../testing/setup-test-bed';
|
||||||
import { CoreModule } from '../../../core.module';
|
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { FormBaseModule } from '../../form-base.module';
|
||||||
|
import { TranslationService } from '../../../services/translation.service';
|
||||||
|
import { TranslationMock } from '../../../mock/translation.service.mock';
|
||||||
|
import { TranslateStore } from '@ngx-translate/core';
|
||||||
|
|
||||||
describe('FormFieldComponent', () => {
|
describe('FormFieldComponent', () => {
|
||||||
|
|
||||||
@@ -35,7 +38,11 @@ describe('FormFieldComponent', () => {
|
|||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
NoopAnimationsModule,
|
NoopAnimationsModule,
|
||||||
CoreModule.forRoot()
|
FormBaseModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: TranslationService, useClass: TranslationMock },
|
||||||
|
TranslateStore
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -144,4 +151,57 @@ describe('FormFieldComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.nativeElement.querySelector('#field-FAKE-TXT-WIDGET-container').hidden).toBeTruthy();
|
expect(fixture.nativeElement.querySelector('#field-FAKE-TXT-WIDGET-container').hidden).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('[C213878] - Should fields be correctly rendered when filled with process variables', async () => {
|
||||||
|
const field = new FormFieldModel(form, {
|
||||||
|
fieldType: 'HyperlinkRepresentation',
|
||||||
|
id: 'label2',
|
||||||
|
name: 'Label2',
|
||||||
|
type: 'hyperlink',
|
||||||
|
value: null,
|
||||||
|
required: false,
|
||||||
|
readOnly: false,
|
||||||
|
overrideId: false,
|
||||||
|
colspan: 1,
|
||||||
|
placeholder: null,
|
||||||
|
minLength: 0,
|
||||||
|
maxLength: 0,
|
||||||
|
minValue: null,
|
||||||
|
maxValue: null,
|
||||||
|
regexPattern: null,
|
||||||
|
optionType: null,
|
||||||
|
hasEmptyValue: null,
|
||||||
|
options: null,
|
||||||
|
restUrl: null,
|
||||||
|
restResponsePath: null,
|
||||||
|
restIdProperty: null,
|
||||||
|
restLabelProperty: null,
|
||||||
|
tab: null,
|
||||||
|
className: null,
|
||||||
|
params: {
|
||||||
|
existingColspan: 1,
|
||||||
|
maxColspan: 2
|
||||||
|
},
|
||||||
|
dateDisplayFormat: null,
|
||||||
|
layout: {
|
||||||
|
row: -1,
|
||||||
|
column: -1,
|
||||||
|
colspan: 1
|
||||||
|
},
|
||||||
|
sizeX: 1,
|
||||||
|
sizeY: 1,
|
||||||
|
row: -1,
|
||||||
|
col: -1,
|
||||||
|
visibilityCondition: null,
|
||||||
|
hyperlinkUrl: 'testtest',
|
||||||
|
displayText: null
|
||||||
|
});
|
||||||
|
|
||||||
|
component.field = field;
|
||||||
|
fixture.detectChanges();
|
||||||
|
const hyperlink: HTMLLinkElement = fixture.nativeElement.querySelector('#field-label2-container hyperlink-widget a');
|
||||||
|
expect(hyperlink).not.toBeNull();
|
||||||
|
expect(hyperlink.href).toBe('http://testtest/');
|
||||||
|
expect(hyperlink.textContent).toBe('testtest');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,9 @@ import {
|
|||||||
BpmUserService,
|
BpmUserService,
|
||||||
CommentProcessService, LogService, AuthenticationService,
|
CommentProcessService, LogService, AuthenticationService,
|
||||||
UserProcessModel,
|
UserProcessModel,
|
||||||
PeopleProcessService
|
PeopleProcessService,
|
||||||
|
TranslationMock,
|
||||||
|
TranslationService
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { TaskDetailsModel } from '../models/task-details.model';
|
import { TaskDetailsModel } from '../models/task-details.model';
|
||||||
import {
|
import {
|
||||||
@@ -42,7 +44,9 @@ import {
|
|||||||
} from '../../mock';
|
} from '../../mock';
|
||||||
import { TaskListService } from './../services/tasklist.service';
|
import { TaskListService } from './../services/tasklist.service';
|
||||||
import { TaskDetailsComponent } from './task-details.component';
|
import { TaskDetailsComponent } from './task-details.component';
|
||||||
import { ProcessTestingModule } from '../../testing/process.testing.module';
|
import { TaskListModule } from '../task-list.module';
|
||||||
|
import { TranslateStore } from '@ngx-translate/core';
|
||||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
|
||||||
const fakeUser: UserProcessModel = new UserProcessModel({
|
const fakeUser: UserProcessModel = new UserProcessModel({
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
@@ -68,8 +72,12 @@ describe('TaskDetailsComponent', () => {
|
|||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
ProcessTestingModule
|
NoopAnimationsModule,
|
||||||
|
TaskListModule
|
||||||
],
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: TranslationService, useClass: TranslationMock },
|
||||||
|
TranslateStore],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -221,6 +229,86 @@ describe('TaskDetailsComponent', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('and form with visiblity', () => {
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
component.taskId = '123';
|
||||||
|
spyOn(formService, 'completeTaskForm').and.returnValue(of({}));
|
||||||
|
taskDetailsMock.formKey = '4';
|
||||||
|
getTaskDetailsSpy.and.returnValue(of(taskDetailsMock));
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('[C312410] - Should be possible to complete a task that has an invisible field on a form with a value', async (done) => {
|
||||||
|
component.formCompleted.subscribe((form: FormModel) => {
|
||||||
|
expect(form.id).toBe(taskFormMock.id);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
component.taskDetails.initiatorCanCompleteTask = true;
|
||||||
|
component.showNextTask = false;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
const inputTextOne: HTMLInputElement = fixture.nativeElement.querySelector('#text1');
|
||||||
|
expect(inputTextOne).toBeDefined();
|
||||||
|
expect(inputTextOne).not.toBeNull();
|
||||||
|
const inputTextTwo: HTMLInputElement = fixture.nativeElement.querySelector('#text2');
|
||||||
|
expect(inputTextTwo).toBeDefined();
|
||||||
|
expect(inputTextTwo).not.toBeNull();
|
||||||
|
let inputTextThree: HTMLInputElement = fixture.nativeElement.querySelector('#text3');
|
||||||
|
expect(inputTextThree).toBeDefined();
|
||||||
|
expect(inputTextThree).not.toBeNull();
|
||||||
|
|
||||||
|
inputTextOne.value = 'a';
|
||||||
|
inputTextOne.dispatchEvent(new Event('input'));
|
||||||
|
inputTextTwo.value = 'a';
|
||||||
|
inputTextTwo.dispatchEvent(new Event('input'));
|
||||||
|
inputTextThree.value = 'a';
|
||||||
|
inputTextThree.dispatchEvent(new Event('input'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
inputTextThree = fixture.nativeElement.querySelector('#text3');
|
||||||
|
expect(inputTextThree).toBeDefined();
|
||||||
|
expect(inputTextThree).not.toBeNull();
|
||||||
|
|
||||||
|
inputTextOne.value = 'b';
|
||||||
|
inputTextOne.dispatchEvent(new Event('input'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
const inputThreeContainer = fixture.nativeElement.querySelector('#field-text3-container');
|
||||||
|
expect(inputThreeContainer.hidden).toBe(true);
|
||||||
|
const completeOutcomeButton: HTMLButtonElement = fixture.nativeElement.querySelector('#adf-form-complete');
|
||||||
|
expect(completeOutcomeButton.hidden).toBe(false);
|
||||||
|
completeOutcomeButton.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('[C277278] - Should show if the form is valid via the validation icon', async () => {
|
||||||
|
const numberInput: HTMLInputElement = fixture.nativeElement.querySelector('#numberField');
|
||||||
|
let validationForm = fixture.nativeElement.querySelector('#adf-valid-form-icon');
|
||||||
|
|
||||||
|
expect(numberInput).toBeDefined();
|
||||||
|
expect(numberInput).not.toBeNull();
|
||||||
|
expect(validationForm.textContent).toBe('check_circle');
|
||||||
|
|
||||||
|
numberInput.value = 'a';
|
||||||
|
numberInput.dispatchEvent(new Event('input'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
const invalidForm = fixture.nativeElement.querySelector('#adf-invalid-form-icon');
|
||||||
|
expect(invalidForm).not.toBeNull();
|
||||||
|
expect(invalidForm.textContent).toBe('error');
|
||||||
|
|
||||||
|
numberInput.value = '4';
|
||||||
|
numberInput.dispatchEvent(new Event('input'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
validationForm = fixture.nativeElement.querySelector('#adf-valid-form-icon');
|
||||||
|
expect(validationForm.textContent).toBe('check_circle');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('change detection', () => {
|
describe('change detection', () => {
|
||||||
|
|
||||||
let change;
|
let change;
|
||||||
|
@@ -68,8 +68,6 @@ describe('TaskFiltersComponent', () => {
|
|||||||
error: 'wrong request'
|
error: 'wrong request'
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
|
|
||||||
|
|
||||||
let component: TaskFiltersComponent;
|
let component: TaskFiltersComponent;
|
||||||
let fixture: ComponentFixture<TaskFiltersComponent>;
|
let fixture: ComponentFixture<TaskFiltersComponent>;
|
||||||
|
|
||||||
@@ -92,6 +90,7 @@ describe('TaskFiltersComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should emit an error with a bad response', (done) => {
|
it('should emit an error with a bad response', (done) => {
|
||||||
|
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
|
||||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise));
|
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise));
|
||||||
|
|
||||||
const appId = '1';
|
const appId = '1';
|
||||||
|
Reference in New Issue
Block a user