mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
parent
7bb1bfe220
commit
c196ccefc9
@ -0,0 +1,48 @@
|
||||
/*!
|
||||
* @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 { UserProcessInstanceFilterRepresentationModel } from '../models/filter.model';
|
||||
|
||||
export var fakeFilters = {
|
||||
size: 0, total: 0, start: 0,
|
||||
data: [new UserProcessInstanceFilterRepresentationModel({
|
||||
'name': 'Running',
|
||||
'appId': '22',
|
||||
'recent': true,
|
||||
'icon': 'glyphicon-random',
|
||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'running'}
|
||||
})]
|
||||
};
|
||||
|
||||
export var fakeEmptyFilters = {
|
||||
size: 0, total: 0, start: 0,
|
||||
data: [ ]
|
||||
};
|
||||
|
||||
export var fakeApi = {
|
||||
activiti: {
|
||||
userFiltersApi: {
|
||||
getUserProcessInstanceFilters: (filterOpts) => Promise.resolve({}),
|
||||
createUserProcessInstanceFilter: (filter: UserProcessInstanceFilterRepresentationModel) => Promise.resolve(filter)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export var fakeError = {
|
||||
message: null,
|
||||
messageKey: 'GENERAL.ERROR.FORBIDDEN'
|
||||
};
|
@ -21,29 +21,14 @@ import {
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService
|
||||
} from 'ng2-alfresco-core';
|
||||
import { UserProcessInstanceFilterRepresentationModel } from '../models/filter.model';
|
||||
import { fakeApi, fakeEmptyFilters, fakeFilters, fakeError } from '../assets/activiti-process.service.mock';
|
||||
import { ActivitiProcessService } from './activiti-process.service';
|
||||
|
||||
describe('ActivitiProcessService', () => {
|
||||
|
||||
let service: ActivitiProcessService;
|
||||
let authenticationService: AlfrescoAuthenticationService;
|
||||
let injector: ReflectiveInjector;
|
||||
|
||||
let fakeEmptyFilters = {
|
||||
size: 0, total: 0, start: 0,
|
||||
data: [ ]
|
||||
};
|
||||
|
||||
let fakeApi = {
|
||||
activiti: {
|
||||
userFiltersApi: {
|
||||
getUserProcessInstanceFilters: (filterOpts) => Promise.resolve({}),
|
||||
createUserProcessInstanceFilter: (filter: UserProcessInstanceFilterRepresentationModel) => Promise.resolve(filter)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
injector = ReflectiveInjector.resolveAndCreate([
|
||||
ActivitiProcessService,
|
||||
@ -52,7 +37,8 @@ describe('ActivitiProcessService', () => {
|
||||
AlfrescoSettingsService
|
||||
]);
|
||||
service = injector.get(ActivitiProcessService);
|
||||
authenticationService = injector.get(AlfrescoAuthenticationService);
|
||||
let authenticationService: AlfrescoAuthenticationService = injector.get(AlfrescoAuthenticationService);
|
||||
spyOn(authenticationService, 'getAlfrescoApi').and.returnValue(fakeApi);
|
||||
});
|
||||
|
||||
xit('should get process instances', (done) => {
|
||||
@ -61,33 +47,71 @@ describe('ActivitiProcessService', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return the default filters when none are returned by the API', (done) => {
|
||||
spyOn(fakeApi.activiti.userFiltersApi, 'getUserProcessInstanceFilters').
|
||||
and.returnValue(Promise.resolve(fakeEmptyFilters));
|
||||
spyOn(fakeApi.activiti.userFiltersApi, 'createUserProcessInstanceFilter').
|
||||
and.returnValue(Promise.resolve({}));
|
||||
spyOn(authenticationService, 'getAlfrescoApi').and.returnValue(fakeApi);
|
||||
describe('filters', () => {
|
||||
|
||||
service.getProcessFilters(null).subscribe(
|
||||
(res) => {
|
||||
expect(fakeApi.activiti.userFiltersApi.createUserProcessInstanceFilter).toHaveBeenCalledTimes(3);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
let userFiltersApi = fakeApi.activiti.userFiltersApi;
|
||||
let getFilters: any, createFilter: any;
|
||||
|
||||
it('should create the default filters when none are returned by the API', (done) => {
|
||||
spyOn(fakeApi.activiti.userFiltersApi, 'getUserProcessInstanceFilters').
|
||||
and.returnValue(Promise.resolve(fakeEmptyFilters));
|
||||
spyOn(fakeApi.activiti.userFiltersApi, 'createUserProcessInstanceFilter').
|
||||
and.returnValue(Promise.resolve({}));
|
||||
spyOn(authenticationService, 'getAlfrescoApi').and.returnValue(fakeApi);
|
||||
beforeEach(() => {
|
||||
getFilters = spyOn(userFiltersApi, 'getUserProcessInstanceFilters');
|
||||
createFilter = spyOn(userFiltersApi, 'createUserProcessInstanceFilter');
|
||||
});
|
||||
|
||||
service.getProcessFilters(null).subscribe(
|
||||
(res) => {
|
||||
expect(res.length).toBe(3);
|
||||
done();
|
||||
}
|
||||
);
|
||||
it('should call the API without an appId defined by default', () => {
|
||||
getFilters = getFilters.and.returnValue(Promise.resolve(fakeFilters));
|
||||
service.getProcessFilters(null);
|
||||
expect(getFilters).toHaveBeenCalledWith({});
|
||||
});
|
||||
|
||||
it('should call the API with the correct appId when specified', () => {
|
||||
getFilters = getFilters.and.returnValue(Promise.resolve(fakeFilters));
|
||||
service.getProcessFilters('226');
|
||||
expect(getFilters).toHaveBeenCalledWith({appId: '226'});
|
||||
});
|
||||
|
||||
it('should return the non-empty filter list that is returned by the API', (done) => {
|
||||
getFilters = getFilters.and.returnValue(Promise.resolve(fakeFilters));
|
||||
service.getProcessFilters(null).subscribe(
|
||||
(res) => {
|
||||
expect(res.length).toBe(1);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the default filters when none are returned by the API', (done) => {
|
||||
getFilters = getFilters.and.returnValue(Promise.resolve(fakeEmptyFilters));
|
||||
|
||||
service.getProcessFilters(null).subscribe(
|
||||
(res) => {
|
||||
expect(res.length).toBe(3);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should create the default filters when none are returned by the API', (done) => {
|
||||
getFilters = getFilters.and.returnValue(Promise.resolve(fakeEmptyFilters));
|
||||
createFilter = createFilter.and.returnValue(Promise.resolve({}));
|
||||
|
||||
service.getProcessFilters(null).subscribe(
|
||||
(res) => {
|
||||
expect(createFilter).toHaveBeenCalledTimes(3);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should pass on any error that is returned by the API', (done) => {
|
||||
getFilters = getFilters.and.returnValue(Promise.reject(fakeError));
|
||||
|
||||
service.getProcessFilters(null).subscribe(
|
||||
() => {},
|
||||
(res) => {
|
||||
expect(res).toBe(fakeError);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -102,7 +102,7 @@ export class ActivitiProcessService {
|
||||
* @param appId
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel}
|
||||
*/
|
||||
getRunningFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
private getRunningFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
return new UserProcessInstanceFilterRepresentationModel({
|
||||
'name': 'Running',
|
||||
'appId': appId,
|
||||
@ -117,7 +117,7 @@ export class ActivitiProcessService {
|
||||
* @param appId
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel}
|
||||
*/
|
||||
getCompletedFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
private getCompletedFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
return new UserProcessInstanceFilterRepresentationModel({
|
||||
'name': 'Completed',
|
||||
'appId': appId,
|
||||
@ -132,7 +132,7 @@ export class ActivitiProcessService {
|
||||
* @param appId
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel}
|
||||
*/
|
||||
getAllFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
private getAllFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
return new UserProcessInstanceFilterRepresentationModel({
|
||||
'name': 'All',
|
||||
'appId': appId,
|
||||
@ -256,7 +256,6 @@ export class ActivitiProcessService {
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
console.error(error);
|
||||
return Observable.throw(error || 'Server error');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user