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:
Vito
2020-03-03 18:45:41 +00:00
committed by GitHub
parent 359022de65
commit 45f023c93a
4 changed files with 759 additions and 384 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,9 @@ import {
BpmUserService,
CommentProcessService, LogService, AuthenticationService,
UserProcessModel,
PeopleProcessService
PeopleProcessService,
TranslationMock,
TranslationService
} from '@alfresco/adf-core';
import { TaskDetailsModel } from '../models/task-details.model';
import {
@@ -42,7 +44,9 @@ import {
} from '../../mock';
import { TaskListService } from './../services/tasklist.service';
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({
id: 'fake-id',
@@ -68,8 +72,12 @@ describe('TaskDetailsComponent', () => {
setupTestBed({
imports: [
ProcessTestingModule
NoopAnimationsModule,
TaskListModule
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
TranslateStore],
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', () => {
let change;

View File

@@ -68,8 +68,6 @@ describe('TaskFiltersComponent', () => {
error: 'wrong request'
};
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
let component: TaskFiltersComponent;
let fixture: ComponentFixture<TaskFiltersComponent>;
@@ -92,6 +90,7 @@ describe('TaskFiltersComponent', () => {
});
it('should emit an error with a bad response', (done) => {
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise));
const appId = '1';