[AAE-2107] Move e2e to Unit test (#5535)

* [AAE-2107] Move e2e to Unit test

* * fixed namings

* * more unit test added

* * minor changes
This commit is contained in:
Eugenio Romano
2020-03-05 16:47:59 +00:00
committed by GitHub
parent 0217f0c788
commit a70883378a
19 changed files with 809 additions and 772 deletions

View File

@@ -15,12 +15,19 @@
* limitations under the License.
*/
import { Component, SimpleChange, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppConfigService, setupTestBed, CoreModule, DataTableModule, DataRowEvent, ObjectDataRow } from '@alfresco/adf-core';
import {
AppConfigService,
CoreModule,
DataRowEvent,
DataTableModule,
ObjectDataRow,
setupTestBed
} from '@alfresco/adf-core';
import { ProcessListCloudService } from '../services/process-list-cloud.service';
import { ProcessListCloudComponent } from './process-list-cloud.component';
import { fakeProcessCloudList, fakeCustomSchema } from '../mock/process-list-service.mock';
import { fakeCustomSchema, fakeProcessCloudList, processListSchemaMock } from '../mock/process-list-service.mock';
import { of } from 'rxjs';
import { ProcessListCloudTestingModule } from '../testing/process-list.testing.module';
import { ProcessListCloudModule } from '../process-list-cloud.module';
@@ -65,7 +72,8 @@ describe('ProcessListCloudComponent', () => {
setupTestBed({
imports: [
ProcessListCloudTestingModule, ProcessListCloudModule
ProcessListCloudTestingModule,
ProcessListCloudModule
],
providers: [ProcessListCloudService]
});
@@ -97,14 +105,57 @@ describe('ProcessListCloudComponent', () => {
});
});
afterEach(() => {
fixture.destroy();
afterEach(() => fixture.destroy());
it('should use the default schemaColumn', () => {
appConfig.config = Object.assign(appConfig.config, { 'adf-cloud-process-list': processListSchemaMock });
component.ngAfterContentInit();
fixture.detectChanges();
expect(component.columns).toBeDefined();
expect(component.columns.length).toEqual(10);
});
it('should use the default schemaColumn as default', () => {
component.ngAfterContentInit();
expect(component.columns).toBeDefined();
expect(component.columns.length).toEqual(2);
it('should display empty content when process list is empty', () => {
const emptyList = {list: {entries: []}};
spyOn(processListCloudService, 'getProcessByRequest').and.returnValue(of(emptyList));
fixture.detectChanges();
expect(component.isLoading).toBe(true);
let loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent.nativeElement).toBeDefined();
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
component.ngOnChanges({ appName });
fixture.detectChanges();
loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent).toBeFalsy();
const emptyContent = fixture.debugElement.query(By.css('.adf-empty-content'));
expect(emptyContent.nativeElement).toBeDefined();
});
it('should load spinner and show the content', () => {
spyOn(processListCloudService, 'getProcessByRequest').and.returnValue(of(fakeProcessCloudList));
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
fixture.detectChanges();
expect(component.isLoading).toBe(true);
let loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent.nativeElement).toBeDefined();
component.ngOnChanges({ appName });
fixture.detectChanges();
expect(component.isLoading).toBe(false);
loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent).toBeFalsy();
const emptyContent = fixture.debugElement.query(By.css('.adf-empty-content'));
expect(emptyContent).toBeFalsy();
expect(component.rows.length).toEqual(3);
});
it('should use the custom schemaColumn from app.config.json', () => {

View File

@@ -97,3 +97,71 @@ export let fakeCustomSchema =
'sortable': true
})
];
export const processListSchemaMock = {
'presets': {
'default': [
{
'key': 'entry.id',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.ID',
'sortable': true
},
{
'key': 'entry.name',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.NAME',
'sortable': true
},
{
'key': 'entry.status',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.STATUS',
'sortable': true
},
{
'key': 'entry.startDate',
'type': 'date',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.START_DATE',
'sortable': true,
'format': 'timeAgo'
},
{
'key': 'entry.appName',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.APP_NAME',
'sortable': true
},
{
'key': 'entry.businessKey',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.BUSINESS_KEY',
'sortable': true
},
{
'key': 'entry.initiator',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.INITIATOR',
'sortable': true
},
{
'key': 'entry.lastModified',
'type': 'date',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.LAST_MODIFIED',
'sortable': true
},
{
'key': 'entry.processDefinitionId',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.PROCESS_DEF_ID',
'sortable': true
},
{
'key': 'entry.processDefinitionKey',
'type': 'text',
'title': 'ADF_CLOUD_PROCESS_LIST.PROPERTIES.PROCESS_DEF_KEY',
'sortable': true
}
]
}
};

View File

@@ -166,10 +166,11 @@ describe('StartTaskCloudComponent', () => {
});
});
it('should select logged in user as assignee by default', () => {
it('should show logged in user as assignee by default', () => {
fixture.detectChanges();
const assignee = fixture.nativeElement.querySelector('[data-automation-id="adf-people-cloud-search-input"]');
const assignee = fixture.nativeElement.querySelector('[data-automation-id="adf-people-cloud-chip-currentUser"]');
expect(assignee).toBeDefined();
expect(assignee.innerText).toContain('Test User');
});
it('should show start task button', () => {

View File

@@ -58,11 +58,11 @@ describe('EditTaskFilterCloudComponent', () => {
service = TestBed.get(TaskFilterCloudService);
appsService = TestBed.get(AppsProcessCloudService);
dialog = TestBed.get(MatDialog);
spyOn(dialog, 'open').and.returnValue({ afterClosed() { return of({
spyOn(dialog, 'open').and.returnValue({ afterClosed: of({
action: TaskFilterDialogCloudComponent.ACTION_SAVE,
icon: 'icon',
name: 'fake-name'
}); }});
}) });
getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeFilter));
getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
fixture.detectChanges();

View File

@@ -67,6 +67,21 @@ describe('TaskFiltersCloudComponent', () => {
taskFilterService = TestBed.get(TaskFilterCloudService);
});
it('should the first element active', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
const activeElement = fixture.debugElement.nativeElement.querySelector('.adf-active span');
expect(activeElement).toBeDefined();
expect(activeElement.innerText).toEqual(fakeGlobalFilter[0].name);
});
}));
it('should attach specific icon for each filter if hasIcon is true', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
const change = new SimpleChange(undefined, 'my-app-1', true);

View File

@@ -124,6 +124,48 @@ describe('TaskListCloudComponent', () => {
expect(component.columns.length).toEqual(3);
});
it('should display empty content when process list is empty', () => {
const emptyList = {list: {entries: []}};
spyOn(taskListCloudService, 'getTaskByRequest').and.returnValue(of(emptyList));
fixture.detectChanges();
expect(component.isLoading).toBe(true);
let loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent.nativeElement).toBeDefined();
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
component.ngOnChanges({ appName });
fixture.detectChanges();
loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent).toBeFalsy();
const emptyContent = fixture.debugElement.query(By.css('.adf-empty-content'));
expect(emptyContent.nativeElement).toBeDefined();
});
it('should load spinner and show the content', () => {
spyOn(taskListCloudService, 'getTaskByRequest').and.returnValue(of(fakeGlobalTask));
const appName = new SimpleChange(null, 'FAKE-APP-NAME', true);
fixture.detectChanges();
expect(component.isLoading).toBe(true);
let loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent.nativeElement).toBeDefined();
component.ngOnChanges({ appName });
fixture.detectChanges();
expect(component.isLoading).toBe(false);
loadingContent = fixture.debugElement.query(By.css('mat-progress-spinner'));
expect(loadingContent).toBeFalsy();
const emptyContent = fixture.debugElement.query(By.css('.adf-empty-content'));
expect(emptyContent).toBeFalsy();
expect(component.rows.length).toEqual(1);
});
it('should use the custom schemaColumn from app.config.json', () => {
component.presetColumn = 'fakeCustomSchema';
component.ngAfterContentInit();