Remove start process dialog

Refs #1253
This commit is contained in:
Will Abson 2016-12-14 09:55:34 +00:00
parent 5ed7add492
commit 2083050a10
5 changed files with 1 additions and 277 deletions

View File

@ -29,7 +29,6 @@ import { ActivitiProcessInstanceVariables } from './src/components/activiti-proc
import { ActivitiComments } from './src/components/activiti-comments.component';
import { ActivitiProcessInstanceDetails } from './src/components/activiti-process-instance-details.component';
import { ActivitiStartProcessInstance } from './src/components/activiti-start-process.component';
import { ActivitiStartProcessInstanceDialog } from './src/components/activiti-start-process-dialog.component';
import { ActivitiProcessService } from './src/services/activiti-process.service';
// components
@ -37,7 +36,6 @@ export * from './src/components/activiti-processlist.component';
export * from './src/components/activiti-filters.component';
export * from './src/components/activiti-process-instance-details.component';
export * from './src/components/activiti-start-process.component';
export * from './src/components/activiti-start-process-dialog.component';
// models
export * from './src/models/index';
@ -53,8 +51,7 @@ export const ACTIVITI_PROCESSLIST_DIRECTIVES: [any] = [
ActivitiProcessInstanceTasks,
ActivitiProcessInstanceVariables,
ActivitiComments,
ActivitiStartProcessInstance,
ActivitiStartProcessInstanceDialog
ActivitiStartProcessInstance
];
export const ACTIVITI_PROCESSLIST_PROVIDERS: [any] = [

View File

@ -1,12 +0,0 @@
:host {
width: 100%;
}
.mdl-dialog {
width: 400px;
width: -moz-fit-content;
width: -webkit-fit-content;
width: -ms-fit-content;
width: -o-fit-content;
width: fit-content;
}

View File

@ -1,12 +0,0 @@
<button type="button" (click)="showDialog()" class="mdl-button" data-automation-id="btn-show" *ngIf="showButton">{{'START_PROCESS.BUTTON'|translate}}</button>
<dialog class="mdl-dialog" #dialog>
<h4 class="mdl-dialog__title">{{'START_PROCESS.DIALOG.TITLE'|translate}}</h4>
<div class="mdl-dialog__content">
<activiti-start-process [appId]="appId" [showStartButton]="false" (start)="onStartProcessInstance($event)"></activiti-start-process>
</div>
<div class="mdl-dialog__actions">
<button type="button" [disabled]="!validateForm()" (click)="startProcess()" class="mdl-button" data-automation-id="btn-start">{{'START_PROCESS.DIALOG.ACTION.START'|translate}}</button>
<button type="button" (click)="closeDialog()" class="mdl-button close" data-automation-id="btn-close">{{'START_PROCESS.DIALOG.ACTION.CANCEL'|translate}}</button>
</div>
</dialog>

View File

@ -1,171 +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 { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
import { ActivitiFormModule, FormService } from 'ng2-activiti-form';
import { TranslationMock } from './../assets/translation.service.mock';
import { newProcess, fakeProcessDefs, taskFormMock } from './../assets/activiti-start-process.component.mock';
import { ActivitiStartProcessInstance } from './activiti-start-process.component';
import { ActivitiStartProcessInstanceDialog } from './activiti-start-process-dialog.component';
import { ActivitiProcessService } from '../services/activiti-process.service';
describe('ActivitiStartProcessInstanceDialog', () => {
let componentHandler: any;
let component: ActivitiStartProcessInstanceDialog;
let fixture: ComponentFixture<ActivitiStartProcessInstanceDialog>;
let processService: ActivitiProcessService;
let formService: FormService;
let getDefinitionsSpy: jasmine.Spy;
let getStartFormDefinitionSpy: jasmine.Spy;
let startProcessSpy: jasmine.Spy;
let debugElement: DebugElement;
const showBtnSelector = '[data-automation-id="btn-show"]';
const startBtnSelector = '[data-automation-id="btn-start"]';
const closeBtnSelector = '[data-automation-id="btn-close"]';
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ CoreModule, ActivitiFormModule ],
declarations: [
ActivitiStartProcessInstance,
ActivitiStartProcessInstanceDialog
],
providers: [
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
ActivitiProcessService
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivitiStartProcessInstanceDialog);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
processService = fixture.debugElement.injector.get(ActivitiProcessService);
formService = fixture.debugElement.injector.get(FormService);
getDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(Observable.of(fakeProcessDefs));
startProcessSpy = spyOn(processService, 'startProcess').and.returnValue(Observable.of(newProcess));
getStartFormDefinitionSpy = spyOn(formService, 'getStartFormDefinition').and.returnValue(Observable.of(taskFormMock));
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered',
'upgradeElement'
]);
window['componentHandler'] = componentHandler;
});
describe('render dialog', () => {
let buttonEl: DebugElement;
it('should render a Start Process button by default', () => {
fixture.detectChanges();
buttonEl = debugElement.query(By.css(showBtnSelector));
expect(buttonEl).not.toBeNull();
});
it('should not render the Start Process button when configured not to', () => {
component.showButton = false;
fixture.detectChanges();
buttonEl = debugElement.query(By.css(showBtnSelector));
expect(buttonEl).toBeNull();
});
});
describe('open dialog', () => {
it('should open dialog when button clicked', () => {
fixture.detectChanges();
let showModalSpy = spyOn(component.dialog.nativeElement, 'showModal');
let showButton: DebugElement = debugElement.query(By.css(showBtnSelector));
showButton.triggerEventHandler('click', null);
expect(showModalSpy).toHaveBeenCalled();
});
});
describe('start process', () => {
it('should output start event when process started from inside inner component', () => {
let emitSpy = spyOn(component.start, 'emit');
component.startProcessComponent.start.emit(newProcess);
expect(emitSpy).toHaveBeenCalledWith(newProcess);
});
it('should call inner component to start process when dialog Start button clicked', () => {
let startSpy = spyOn(component.startProcessComponent, 'startProcess').and.returnValue(null);
let closeButton: DebugElement = debugElement.query(By.css(startBtnSelector));
closeButton.triggerEventHandler('click', null);
expect(startSpy).toHaveBeenCalled();
});
});
describe('close dialog', () => {
let dialogPolyfill: any;
let setupDialog = () => {
component.showDialog();
fixture.detectChanges();
};
let clickCancelButton = () => {
let closeButton: DebugElement = debugElement.query(By.css(closeBtnSelector));
closeButton.triggerEventHandler('click', null);
};
beforeEach(() => {
dialogPolyfill = { registerDialog: (widget) => widget.showModal = () => {} };
dialogPolyfill.registerDialog = spyOn(dialogPolyfill, 'registerDialog').and.callThrough();
window['dialogPolyfill'] = dialogPolyfill;
});
it('should close dialog when close button clicked', async(() => {
let closeSpy = spyOn(component.dialog.nativeElement, 'close');
setupDialog();
clickCancelButton();
expect(closeSpy).toHaveBeenCalled();
}));
it('should reset embedded component when dialog cancelled', async(() => {
let resetSpy = spyOn(component.startProcessComponent, 'reset');
setupDialog();
clickCancelButton();
expect(resetSpy).toHaveBeenCalled();
}));
it('should register dialog via polyfill', () => {
fixture.detectChanges();
component.dialog.nativeElement.showModal = null;
component.showDialog();
expect(dialogPolyfill.registerDialog).toHaveBeenCalledWith(component.dialog.nativeElement);
});
});
});

View File

@ -1,78 +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 { Component, EventEmitter, Input, Output, ViewChild, DebugElement } from '@angular/core';
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { ActivitiStartProcessInstance } from './activiti-start-process.component';
import { ProcessInstance } from './../models/process-instance.model';
declare let componentHandler: any;
declare let dialogPolyfill: any;
@Component({
selector: 'activiti-start-process-dialog',
moduleId: module.id,
templateUrl: './activiti-start-process-dialog.component.html',
styleUrls: ['./activiti-start-process-dialog.component.css']
})
export class ActivitiStartProcessInstanceDialog {
@Input()
appId: string;
@Input()
showButton: boolean = true;
@Output()
start: EventEmitter<ProcessInstance> = new EventEmitter<ProcessInstance>();
@ViewChild('dialog')
dialog: DebugElement;
@ViewChild(ActivitiStartProcessInstance)
startProcessComponent: ActivitiStartProcessInstance;
constructor(private translate: AlfrescoTranslationService) {
if (translate) {
translate.addTranslationFolder('node_modules/ng2-activiti-processlist/src');
}
}
public showDialog() {
if (!this.dialog.nativeElement.showModal) {
dialogPolyfill.registerDialog(this.dialog.nativeElement);
}
this.dialog.nativeElement.showModal();
}
validateForm() {
return this.startProcessComponent.validateForm();
}
public startProcess() {
this.startProcessComponent.startProcess();
}
public closeDialog() {
this.startProcessComponent.reset();
this.dialog.nativeElement.close();
}
onStartProcessInstance(processInstance: ProcessInstance) {
this.start.emit(processInstance);
}
}