mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Unit test task filters
This commit is contained in:
@@ -0,0 +1,96 @@
|
|||||||
|
/*!
|
||||||
|
* @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 { ActivitiFilters } from './activiti-filters.component';
|
||||||
|
import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
import { FilterModel } from '../models/filter.model';
|
||||||
|
|
||||||
|
describe('ActivitiFilters', () => {
|
||||||
|
|
||||||
|
let filterList: ActivitiFilters;
|
||||||
|
|
||||||
|
let fakeGlobalFilter = [];
|
||||||
|
fakeGlobalFilter.push(new FilterModel('FakeInvolvedTasks', false, 'glyphicon-align-left', '', 'open', 'fake-involved'));
|
||||||
|
fakeGlobalFilter.push(new FilterModel('FakeMyTasks', false, 'glyphicon-align-left', '', 'open', 'fake-assignee'));
|
||||||
|
|
||||||
|
let fakeGlobalFilterPromise = new Promise(function (resolve, reject) {
|
||||||
|
resolve(fakeGlobalFilter);
|
||||||
|
});
|
||||||
|
|
||||||
|
let fakeErrorFilterList = {
|
||||||
|
error: 'wrong request'
|
||||||
|
};
|
||||||
|
|
||||||
|
let fakeErrorFilterPromise = new Promise(function (resolve, reject) {
|
||||||
|
reject(fakeErrorFilterList);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
let activitiService = new ActivitiTaskListService(null);
|
||||||
|
filterList = new ActivitiFilters(null, null, activitiService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the filter task list', (done) => {
|
||||||
|
spyOn(filterList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise));
|
||||||
|
|
||||||
|
filterList.onSuccess.subscribe( (res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(res).toEqual('Filter task list loaded');
|
||||||
|
expect(filterList.filters).toBeDefined();
|
||||||
|
expect(filterList.filters.length).toEqual(2);
|
||||||
|
expect(filterList.filters[0].name).toEqual('FakeInvolvedTasks');
|
||||||
|
expect(filterList.filters[1].name).toEqual('FakeMyTasks');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
filterList.ngOnInit();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit an error with a bad response', (done) => {
|
||||||
|
spyOn(filterList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeErrorFilterPromise));
|
||||||
|
|
||||||
|
filterList.onError.subscribe( (err) => {
|
||||||
|
expect(err).toBeDefined();
|
||||||
|
expect(err).toEqual('Error to load a task filter list');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
filterList.ngOnInit();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit an event when a filter is selected', (done) => {
|
||||||
|
let currentFilter = new FilterModel('FakeInvolvedTasks', false, 'glyphicon-align-left', '', 'open', 'fake-involved');
|
||||||
|
|
||||||
|
filterList.filterClick.subscribe((filter: FilterModel) => {
|
||||||
|
expect(filter).toBeDefined();
|
||||||
|
expect(filter).toEqual(currentFilter);
|
||||||
|
expect(filterList.currentFilter).toEqual(currentFilter);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
filterList.selectFilter(currentFilter);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@@ -38,6 +38,12 @@ export class ActivitiFilters implements OnInit {
|
|||||||
@Output()
|
@Output()
|
||||||
filterClick: EventEmitter<FilterModel> = new EventEmitter<FilterModel>();
|
filterClick: EventEmitter<FilterModel> = new EventEmitter<FilterModel>();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
onSuccess: EventEmitter<string> = new EventEmitter<string>();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
onError: EventEmitter<string> = new EventEmitter<string>();
|
||||||
|
|
||||||
private filterObserver: Observer<FilterModel>;
|
private filterObserver: Observer<FilterModel>;
|
||||||
filter$: Observable<FilterModel>;
|
filter$: Observable<FilterModel>;
|
||||||
|
|
||||||
@@ -77,9 +83,11 @@ export class ActivitiFilters implements OnInit {
|
|||||||
res.forEach((filter) => {
|
res.forEach((filter) => {
|
||||||
this.filterObserver.next(filter);
|
this.filterObserver.next(filter);
|
||||||
});
|
});
|
||||||
|
this.onSuccess.emit('Filter task list loaded');
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
this.onError.emit('Error to load a task filter list');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -89,6 +97,7 @@ export class ActivitiFilters implements OnInit {
|
|||||||
* @param filter
|
* @param filter
|
||||||
*/
|
*/
|
||||||
public selectFilter(filter: FilterModel) {
|
public selectFilter(filter: FilterModel) {
|
||||||
|
this.currentFilter = filter;
|
||||||
this.filterClick.emit(filter);
|
this.filterClick.emit(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user