Added start task test

This commit is contained in:
Vito Albano 2016-11-02 17:18:15 +00:00
parent b57a79c042
commit 207d2206eb
4 changed files with 143 additions and 11 deletions

View File

@ -32,7 +32,7 @@ import {
ActivitiComments, ActivitiComments,
ActivitiPeople, ActivitiPeople,
ActivitiTaskHeader, ActivitiTaskHeader,
ActivitiStartProcessButton, ActivitiStartTaskButton,
ActivitiPeopleSearch ActivitiPeopleSearch
} from './src/components/index'; } from './src/components/index';
@ -50,7 +50,7 @@ export const ACTIVITI_TASKLIST_DIRECTIVES: any[] = [
ActivitiComments, ActivitiComments,
ActivitiPeople, ActivitiPeople,
ActivitiTaskHeader, ActivitiTaskHeader,
ActivitiStartProcessButton, ActivitiStartTaskButton,
ActivitiPeopleSearch ActivitiPeopleSearch
]; ];

View File

@ -1,19 +1,27 @@
<button type="button" (click)="showDialog()" class="mdl-button">{{'START_TASK.BUTTON'|translate}}</button> <button type="button" (click)="showDialog()" class="mdl-button" id="start-task-button">
{{'START_TASK.BUTTON'|translate}}
</button>
<dialog class="mdl-dialog" #dialog> <dialog class="mdl-dialog" id="start-task-dialog" #dialog>
<h4 class="mdl-dialog__title">{{'START_TASK.DIALOG.TITLE'|translate}}</h4> <h4 class="mdl-dialog__title" id="start-task-dialog-title">{{'START_TASK.DIALOG.TITLE'|translate}}</h4>
<div class="mdl-dialog__content"> <div class="mdl-dialog__content">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" [(ngModel)]="name" id="taskName" /> <input class="mdl-textfield__input" type="text" [(ngModel)]="name" id="taskName"/>
<label class="mdl-textfield__label" for="taskName">{{'START_TASK.DIALOG.LABEL.NAME'|translate}}</label> <label class="mdl-textfield__label" for="taskName">{{'START_TASK.DIALOG.LABEL.NAME'|translate}}</label>
</div> </div>
<div class="mdl-textfield mdl-js-textfield"> <div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" [(ngModel)]="description" rows="3" id="taskDescription"></textarea> <textarea class="mdl-textfield__input" type="text" [(ngModel)]="description" rows="3"
<label class="mdl-textfield__label" for="taskDescription">{{'START_TASK.DIALOG.LABEL.DESCRIPTION'|translate}}</label> id="taskDescription"></textarea>
<label class="mdl-textfield__label" id="task-description-label"
for="taskDescription">{{'START_TASK.DIALOG.LABEL.DESCRIPTION'|translate}}</label>
</div> </div>
</div> </div>
<div class="mdl-dialog__actions"> <div class="mdl-dialog__actions">
<button type="button" (click)="start()" class="mdl-button">{{'START_TASK.DIALOG.ACTION.START'|translate}}</button> <button type="button" id="button-start" (click)="start()" class="mdl-button">
<button type="button" (click)="cancel()" class="mdl-button close">{{'START_TASK.DIALOG.ACTION.CANCEL'|translate}}</button> {{'START_TASK.DIALOG.ACTION.START'|translate}}
</button>
<button type="button" id="button-cancel" (click)="cancel()" class="mdl-button close">
{{'START_TASK.DIALOG.ACTION.CANCEL'|translate}}
</button>
</div> </div>
</dialog> </dialog>

View File

@ -0,0 +1,124 @@
/*!
* @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 {
CoreModule,
AlfrescoTranslationService
} from 'ng2-alfresco-core';
import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
import { ActivitiStartTaskButton } from './activiti-start-task.component';
import { TranslationMock } from '../assets/translation.service.mock';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
declare let jasmine: any;
describe('Activiti Start Task Component', () => {
let activitiStartTaskButton: ActivitiStartTaskButton;
let fixture: ComponentFixture<ActivitiStartTaskButton>;
let element: HTMLElement;
let startTaskButton: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [CoreModule],
declarations: [ActivitiStartTaskButton],
providers: [
{provide: AlfrescoTranslationService, useClass: TranslationMock},
ActivitiTaskListService]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(ActivitiStartTaskButton);
activitiStartTaskButton = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
startTaskButton = <HTMLElement> element.querySelector('#start-task-button');
});
}));
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should show start task button', () => {
expect(element.querySelector('#start-task-button')).toBeDefined();
expect(element.querySelector('#start-task-button')).not.toBeNull();
expect(element.querySelector('#start-task-button').textContent).toContain('START_TASK.BUTTON');
});
it('should show start dialog on press button', () => {
startTaskButton.click();
expect(element.querySelector('#start-task-dialog')).not.toBeNull();
expect(element.querySelector('#start-task-dialog').getAttribute('open')).not.toBeNull();
expect(element.querySelector('#start-task-dialog-title')).not.toBeNull();
expect(element.querySelector('#start-task-dialog-title').textContent).toContain('START_TASK.DIALOG.TITLE');
});
it('should close start dialog on cancel button', () => {
startTaskButton.click();
expect(element.querySelector('#start-task-dialog')).not.toBeNull();
expect(element.querySelector('#start-task-dialog').getAttribute('open')).not.toBeNull();
let cancelButton = <HTMLElement> element.querySelector('#button-cancel');
cancelButton.click();
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
});
it('should create new task when start is clicked', () => {
activitiStartTaskButton.onSuccess.subscribe(() => {
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
startTaskButton.click();
activitiStartTaskButton.name = 'fake-name';
createTaskButton.click();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200
});
});
it('alert message is showed on start error', () => {
spyOn(window, 'alert');
activitiStartTaskButton.onSuccess.subscribe(() => {
expect(window.alert).toHaveBeenCalledWith('An error occurred while trying to add the task');
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
startTaskButton.click();
activitiStartTaskButton.name = 'fake-name';
createTaskButton.click();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 403
});
});
it('should send on success event when the task is started', () => {
activitiStartTaskButton.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
startTaskButton.click();
activitiStartTaskButton.name = 'fake-name';
createTaskButton.click();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'json',
responseText: {}
});
});
});

View File

@ -29,7 +29,7 @@ declare let dialogPolyfill: any;
templateUrl: './activiti-start-task.component.html', templateUrl: './activiti-start-task.component.html',
styleUrls: ['./activiti-start-task.component.css'] styleUrls: ['./activiti-start-task.component.css']
}) })
export class ActivitiStartProcessButton { export class ActivitiStartTaskButton {
@Input() @Input()
appId: string; appId: string;