Files
alfresco-ng2-components/ng2-components/ng2-activiti-processlist/src/components/adf-create-process-attachment.component.spec.ts
Maurizio Vitale 3b3adbb8ba [ADF-971] Create task/process attachment should show the new button (#2069)
* Remove the drag and drop
Change the design button
Fix the Event with the name inside the Readme

* Fix unit test

* Rollback id button
2017-08-01 10:20:15 +01:00

139 lines
4.6 KiB
TypeScript

/*!
* @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 { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivitiContentService } from 'ng2-activiti-form';
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
import { ActivitiCreateProcessAttachmentComponent } from './adf-create-process-attachment.component';
declare let jasmine: any;
describe('Activiti Process Create Attachment', () => {
let componentHandler: any;
let service: ActivitiContentService;
let component: ActivitiCreateProcessAttachmentComponent;
let fixture: ComponentFixture<ActivitiCreateProcessAttachmentComponent>;
let element: HTMLElement;
let file = new File([new Blob()], 'Test');
let fileObj = { entry: null, file: file, relativeFolder: '/' };
let customEvent = { detail: { files: [fileObj] } };
let fakeUploadResponse = {
id: 9999,
name: 'BANANA.jpeg',
created: '2017-06-12T12:52:11.109Z',
createdBy: { id: 2, firstName: 'fake-user', lastName: 'fake-user', email: 'fake-user' },
relatedContent: false,
contentAvailable: true,
link: false,
mimeType: 'image/jpeg',
simpleType: 'image',
previewStatus: 'queued',
thumbnailStatus: 'queued'
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule.forRoot()
],
declarations: [
ActivitiCreateProcessAttachmentComponent
],
providers: [
{ provide: AlfrescoTranslationService },
ActivitiContentService
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivitiCreateProcessAttachmentComponent);
component = fixture.componentInstance;
service = fixture.debugElement.injector.get(ActivitiContentService);
element = fixture.nativeElement;
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered',
'upgradeElement'
]);
window['componentHandler'] = componentHandler;
component.processInstanceId = '9999';
fixture.detectChanges();
});
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should update the processInstanceId when it is changed', () => {
component.processInstanceId = null;
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
expect(component.processInstanceId).toBe('123');
});
it('should emit content created event when the file is uploaded', async(() => {
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res.id).toBe(9999);
});
component.onFileUpload(customEvent);
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeUploadResponse)
});
}));
it('should allow user to upload files via button', async(() => {
let buttonUpload: HTMLElement = <HTMLElement> element.querySelector('#add_new_process_content_button');
expect(buttonUpload).toBeDefined();
expect(buttonUpload).not.toBeNull();
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res.id).toBe(9999);
});
let dropEvent = new CustomEvent('upload-files', customEvent);
buttonUpload.dispatchEvent(dropEvent);
fixture.detectChanges();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeUploadResponse)
});
}));
});