mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-3095] ability to intercept, pause and resume upload process (#3416)
* prevent and resume upload process * upload fixes and confirmation dialog demo * ability to toggle the upload confirmation demo * fix tests * unit tests * docs update * remove deprecation * fix test name
This commit is contained in:
committed by
Eugenio Romano
parent
64a8c66103
commit
54e80e7863
@@ -15,22 +15,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Component, NgZone } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { TranslationService, UploadService, setupTestBed, CoreModule, FileModel } from '@alfresco/adf-core';
|
||||
import { UploadBase } from './upload-base';
|
||||
import { TranslationMock } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { UploadFilesEvent } from '../upload-files.event';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-upload-button-test',
|
||||
template: 'test componente'
|
||||
template: 'test component'
|
||||
})
|
||||
export class UploadTestComponent extends UploadBase {
|
||||
|
||||
constructor(protected uploadService: UploadService,
|
||||
protected translationService: TranslationService) {
|
||||
super(uploadService, translationService);
|
||||
protected translationService: TranslationService,
|
||||
protected ngZone: NgZone) {
|
||||
super(uploadService, translationService, ngZone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +69,66 @@ describe('UploadBase', () => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
describe('beginUpload', () => {
|
||||
|
||||
it('should raise event', done => {
|
||||
spyOn(uploadService, 'addToQueue').and.stub();
|
||||
spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
|
||||
|
||||
component.beginUpload.subscribe(() => done());
|
||||
const file = <File> { name: 'bigFile.png', size: 1000 };
|
||||
component.uploadFiles([file]);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should pause upload', fakeAsync(() => {
|
||||
spyOn(uploadService, 'addToQueue').and.stub();
|
||||
spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
|
||||
|
||||
let prevented = false;
|
||||
component.beginUpload.subscribe(event => {
|
||||
event.preventDefault();
|
||||
prevented = true;
|
||||
});
|
||||
const file = <File> { name: 'bigFile.png', size: 1000 };
|
||||
component.uploadFiles([file]);
|
||||
|
||||
tick();
|
||||
expect(prevented).toBeTruthy();
|
||||
expect(uploadService.addToQueue).not.toHaveBeenCalled();
|
||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should resume upload', fakeAsync(() => {
|
||||
const addToQueue = spyOn(uploadService, 'addToQueue').and.stub();
|
||||
const uploadFilesInTheQueue = spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
|
||||
|
||||
let prevented = false;
|
||||
let uploadEvent: UploadFilesEvent;
|
||||
component.beginUpload.subscribe(event => {
|
||||
uploadEvent = event;
|
||||
event.preventDefault();
|
||||
prevented = true;
|
||||
});
|
||||
const file = <File> { name: 'bigFile.png', size: 1000 };
|
||||
component.uploadFiles([file]);
|
||||
|
||||
tick();
|
||||
expect(prevented).toBeTruthy();
|
||||
expect(addToQueue).not.toHaveBeenCalled();
|
||||
expect(uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||
|
||||
addToQueue.calls.reset();
|
||||
uploadFilesInTheQueue.calls.reset();
|
||||
|
||||
uploadEvent.resumeUpload();
|
||||
|
||||
expect(addToQueue).toHaveBeenCalled();
|
||||
expect(uploadFilesInTheQueue).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
describe('filesize', () => {
|
||||
|
||||
const files: File[] = [
|
||||
|
Reference in New Issue
Block a user