mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
Add unit test
This commit is contained in:
-36
@@ -1,36 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class AlfrescoSettingsServiceMock {
|
||||
|
||||
static DEFAULT_HOST_ADDRESS: string = 'fakehost';
|
||||
|
||||
private providers: string[] = ['ECM', 'BPM'];
|
||||
|
||||
private _host: string = AlfrescoSettingsServiceMock.DEFAULT_HOST_ADDRESS;
|
||||
|
||||
public get host(): string {
|
||||
return this._host;
|
||||
}
|
||||
|
||||
getProviders(): string [] {
|
||||
return this.providers;
|
||||
}
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
it,
|
||||
describe,
|
||||
expect,
|
||||
beforeEach
|
||||
} from '@angular/core/testing';
|
||||
|
||||
import { ActivitiTaskList } from './activiti-tasklist.component';
|
||||
import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
|
||||
import { FilterModel } from '../models/filter.model';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
|
||||
|
||||
describe('ActivitiTaskList', () => {
|
||||
|
||||
let taskList: ActivitiTaskList;
|
||||
|
||||
let fakeGlobalFilter = {
|
||||
size: 2, total: 2, start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 1, name: 'FakeInvolvedTasks', recent: false, icon: 'glyphicon-align-left',
|
||||
filter: {sort: 'created-desc', name: '', state: 'open', assignment: 'fake-involved'}
|
||||
},
|
||||
{
|
||||
id: 2, name: 'FakeMyTasks', recent: false, icon: 'glyphicon-align-left',
|
||||
filter: {sort: 'created-desc', name: '', state: 'open', assignment: 'fake-assignee'}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let fakeGlobalTask = {
|
||||
size: 1, total: 12, start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 14, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name', description: null, category: null,
|
||||
assignee: {
|
||||
id: 1, firstName: null, lastName: 'Administrator', email: 'admin'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 2, name: '', description: null, category: null,
|
||||
assignee: {
|
||||
id: 1, firstName: null, lastName: 'Administrator', email: 'admin'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let fakeErrorTaskList = {
|
||||
error: 'wrong request'
|
||||
};
|
||||
|
||||
let fakeGlobalFilterPromise = new Promise(function (resolve, reject) {
|
||||
resolve(fakeGlobalFilter);
|
||||
});
|
||||
|
||||
let fakeGlobalTaskPromise = new Promise(function (resolve, reject) {
|
||||
resolve(fakeGlobalTask);
|
||||
});
|
||||
|
||||
let fakeErrorTaskPromise = new Promise(function (resolve, reject) {
|
||||
reject(fakeErrorTaskList);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
let activitiSerevice = new ActivitiTaskListService(null);
|
||||
taskList = new ActivitiTaskList(null, null, activitiSerevice);
|
||||
});
|
||||
|
||||
it('should return the default filters', (done) => {
|
||||
spyOn(taskList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise));
|
||||
taskList.ngOnInit();
|
||||
|
||||
taskList.filtersList.subscribe((res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.size).toEqual(2);
|
||||
expect(res.total).toEqual(2);
|
||||
expect(res.data.length).toEqual(2);
|
||||
expect(res.data[0].name).toEqual('FakeInvolvedTasks');
|
||||
expect(res.data[1].name).toEqual('FakeMyTasks');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should subscribe to Filter when a filter is selected', (done) => {
|
||||
let filterModel: FilterModel = new FilterModel('name', false, 'icon', 'open', 'fake-assignee');
|
||||
taskList.filter$.subscribe((filter: FilterModel) => {
|
||||
expect(filter).toBe(filterModel);
|
||||
done();
|
||||
});
|
||||
taskList.selectFilter(filterModel);
|
||||
});
|
||||
|
||||
it('should return the tasks when a filter is selected', (done) => {
|
||||
spyOn(taskList.activiti, 'getTasks').and.returnValue(Observable.fromPromise(fakeGlobalTaskPromise));
|
||||
spyOn(taskList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise));
|
||||
taskList.ngOnInit();
|
||||
|
||||
let filterModel: FilterModel = new FilterModel('name', false, 'icon', 'open', 'fake-assignee');
|
||||
taskList.selectFilter(filterModel);
|
||||
|
||||
taskList.activiti.getTasks(filterModel).subscribe(
|
||||
(res) => {
|
||||
expect(res).toBeDefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an exception when the response is wrong', (done) => {
|
||||
spyOn(taskList.activiti, 'getTasks').and.returnValue(Observable.fromPromise(fakeErrorTaskPromise));
|
||||
spyOn(taskList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise));
|
||||
taskList.ngOnInit();
|
||||
|
||||
let filterModel: FilterModel = new FilterModel('name', false, 'icon', 'open', 'fake-assignee');
|
||||
taskList.selectFilter(filterModel);
|
||||
|
||||
taskList.activiti.getTasks(filterModel).subscribe(
|
||||
(res) => {
|
||||
expect(res).toBeUndefined();
|
||||
},
|
||||
(err: any) => {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.error).toEqual('wrong request');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should optimize the task name when are empty or exceed 50 characters', (done) => {
|
||||
spyOn(taskList.activiti, 'getTasks').and.returnValue(Observable.fromPromise(fakeGlobalTaskPromise));
|
||||
spyOn(taskList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise));
|
||||
taskList.ngOnInit();
|
||||
|
||||
let filterModel: FilterModel = new FilterModel('name', false, 'icon', 'open', 'fake-assignee');
|
||||
taskList.selectFilter(filterModel);
|
||||
|
||||
taskList.activiti.getTasks(filterModel).subscribe(
|
||||
(res) => {
|
||||
expect(res.data[0].name).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||
expect(res.data[1].name).toEqual('Nameless task');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
+13
-8
@@ -53,20 +53,25 @@ export class ActivitiTaskList implements OnInit {
|
||||
*/
|
||||
constructor(private auth: AlfrescoAuthenticationService,
|
||||
private translate: AlfrescoTranslationService,
|
||||
private activiti: ActivitiTaskListService) {
|
||||
public activiti: ActivitiTaskListService) {
|
||||
this.filter$ = new Observable<FilterModel>(observer => this.filterObserver = observer).share();
|
||||
|
||||
translate.addTranslationFolder('node_modules/ng2-alfresco-activiti-tasklist');
|
||||
if (translate) {
|
||||
translate.addTranslationFolder('node_modules/ng2-alfresco-activiti-tasklist');
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.filtersList = this.activiti.getTaskListFilters().map(res => (res.data));
|
||||
this.filtersList = this.activiti.getTaskListFilters();
|
||||
|
||||
this.filter$.subscribe( (filter: FilterModel) => {
|
||||
this.activiti.getTasks(filter).subscribe((res) => {
|
||||
let tasks = res.data;
|
||||
this.loadTasks(tasks);
|
||||
});
|
||||
this.filter$.subscribe((filter: FilterModel) => {
|
||||
this.activiti.getTasks(filter).subscribe(
|
||||
(res) => {
|
||||
let tasks = res.data;
|
||||
this.loadTasks(tasks);
|
||||
}, (err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-5
@@ -18,7 +18,6 @@
|
||||
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { ActivitiTaskListService } from './activiti-tasklist.service';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsServiceMock } from '../assets/AlfrescoSettingsService.service.mock';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
declare let AlfrescoApi: any;
|
||||
@@ -40,8 +39,8 @@ describe('AlfrescoUploadService', () => {
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
HTTP_PROVIDERS,
|
||||
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock },
|
||||
{ provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService },
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
ActivitiTaskListService
|
||||
];
|
||||
});
|
||||
@@ -157,8 +156,6 @@ describe('AlfrescoUploadService', () => {
|
||||
expect(err.error).toEqual('wrong request');
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
+8
-8
@@ -30,8 +30,10 @@ export class ActivitiTaskListService {
|
||||
* Retrive all the Tasks filters
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
getTaskListFilters() {
|
||||
return this.callApiTaskFilters();
|
||||
getTaskListFilters(): Observable<any> {
|
||||
return Observable.fromPromise(this.callApiTaskFilters())
|
||||
.map((res: Response) => res.json())
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +51,7 @@ export class ActivitiTaskListService {
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
private callApiTasksFiltered(data: Object): Observable<any> {
|
||||
private callApiTasksFiltered(data: Object) {
|
||||
let url = 'http://localhost:9999/activiti-app/app/rest/filter/tasks';
|
||||
let headers = new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
@@ -58,10 +60,10 @@ export class ActivitiTaskListService {
|
||||
let options = new RequestOptions({headers: headers});
|
||||
|
||||
return this.http
|
||||
.post(url, data, options);
|
||||
.post(url, data, options).toPromise();
|
||||
}
|
||||
|
||||
private callApiTaskFilters(): Observable<any> {
|
||||
private callApiTaskFilters() {
|
||||
let url = 'http://localhost:9999/activiti-app/app/rest/filters/tasks';
|
||||
let headers = new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
@@ -70,9 +72,7 @@ export class ActivitiTaskListService {
|
||||
let options = new RequestOptions({headers: headers});
|
||||
|
||||
return this.http
|
||||
.get(url, options)
|
||||
.map((res: Response) => res.json())
|
||||
.catch(this.handleError);
|
||||
.get(url, options).toPromise();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user