mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Merge pull request #862 from Alfresco/dev-eromano-UploadTestFix
fix test and coverage Angular2 Final release uploader component #749
This commit is contained in:
commit
08fccc84a3
@ -30,7 +30,6 @@ declare let jasmine: any;
|
||||
|
||||
describe('Test ng2-alfresco-tag Tag relative node list', () => {
|
||||
|
||||
|
||||
let dataTag = {
|
||||
'list': {
|
||||
'pagination': {
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
import { TagService } from '../services/tag.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
declare var AlfrescoApi: any;
|
||||
|
||||
describe('Tag service', () => {
|
||||
|
||||
|
@ -24,6 +24,7 @@ import { UploadButtonComponent } from './src/components/upload-button.component'
|
||||
import { FileUploadingDialogComponent } from './src/components/file-uploading-dialog.component';
|
||||
import { FileUploadingListComponent } from './src/components/file-uploading-list.component';
|
||||
import { UploadService } from './src/services/upload.service';
|
||||
import { TranslateModule } from 'ng2-translate';
|
||||
|
||||
/**
|
||||
* ng2-alfresco-upload, provide components to upload files to alfresco repository.
|
||||
@ -62,7 +63,8 @@ export const UPLOAD_PROVIDERS: any[] = [
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CoreModule
|
||||
CoreModule,
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
...UPLOAD_DIRECTIVES
|
||||
|
@ -33,6 +33,7 @@ module.exports = function (config) {
|
||||
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
|
||||
|
||||
'node_modules/alfresco-js-api/dist/alfresco-js-api.js',
|
||||
|
||||
{pattern: 'node_modules/ng2-translate/**/*.js', included: false, watched: false},
|
||||
{pattern: 'node_modules/ng2-translate/**/*.js.map', included: false, watched: false},
|
||||
|
||||
@ -45,10 +46,13 @@ module.exports = function (config) {
|
||||
|
||||
// ng2-components
|
||||
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
|
||||
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.map', included: false, served: true, watched: false},
|
||||
|
||||
// paths to support debugging with source maps in dev tools
|
||||
{pattern: 'src/**/*.ts', included: false, watched: false},
|
||||
{pattern: 'dist/**/*.js.map', included: false, watched: false}
|
||||
{pattern: 'dist/**/*.js.map', included: false, watched: false},
|
||||
|
||||
{pattern: 'src/i18n/*.json', included: false, watched: true, served: true}
|
||||
],
|
||||
|
||||
exclude: [
|
||||
@ -96,11 +100,10 @@ module.exports = function (config) {
|
||||
// Source files that you wanna generate coverage for.
|
||||
// Do not include tests or libraries (these files will be instrumented by Istanbul)
|
||||
preprocessors: {
|
||||
'dist/**/!(*spec|index|*mock|*model).js': 'coverage'
|
||||
'dist/**/!(*spec).js': ['coverage']
|
||||
},
|
||||
|
||||
coverageReporter: {
|
||||
includeAllSources: true,
|
||||
dir: 'coverage/',
|
||||
subdir: 'report',
|
||||
reporters: [
|
||||
|
@ -63,15 +63,14 @@
|
||||
"@angular/router": "3.0.0",
|
||||
"@angular/upgrade": "2.0.0",
|
||||
"@types/node": "^6.0.42",
|
||||
"alfresco-js-api": "^0.3.0",
|
||||
"core-js": "^2.4.1",
|
||||
"ng2-alfresco-core": "0.3.2",
|
||||
"ng2-translate": "2.5.0",
|
||||
"reflect-metadata": "^0.1.3",
|
||||
"rxjs": "5.0.0-beta.12",
|
||||
"systemjs": "0.19.27",
|
||||
"zone.js": "^0.6.23",
|
||||
|
||||
"ng2-translate": "2.5.0",
|
||||
"alfresco-js-api": "^0.3.0",
|
||||
"ng2-alfresco-core": "0.3.2"
|
||||
"zone.js": "^0.6.23"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/core-js": "^0.9.32",
|
||||
|
@ -15,153 +15,107 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
import { PLATFORM_PIPES } from '@angular/core';
|
||||
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
import {
|
||||
AlfrescoTranslationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoPipeTranslate
|
||||
} from 'ng2-alfresco-core';
|
||||
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
||||
import { FileModel } from '../models/file.model';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
|
||||
describe('FileUploadDialog', () => {
|
||||
|
||||
let componentFixture;
|
||||
let uploadService;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
HTTP_PROVIDERS,
|
||||
import { FileUploadingListComponent } from './file-uploading-list.component';
|
||||
import { DebugElement, ReflectiveInjector } from '@angular/core';
|
||||
import {
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService,
|
||||
CoreModule
|
||||
} from 'ng2-alfresco-core';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { FileModel } from '../models/file.model';
|
||||
|
||||
describe('Test ng2-alfresco-upload FileUploadDialog', () => {
|
||||
|
||||
let injector;
|
||||
let component: any;
|
||||
let fixture: ComponentFixture<FileUploadingDialogComponent>;
|
||||
let debug: DebugElement;
|
||||
let element: any;
|
||||
let file: FileModel;
|
||||
|
||||
beforeEach(async(() => {
|
||||
injector = ReflectiveInjector.resolveAndCreate([
|
||||
UploadService
|
||||
]);
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule
|
||||
],
|
||||
declarations: [FileUploadingDialogComponent, FileUploadingListComponent],
|
||||
providers: [
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
{ provide: PLATFORM_PIPES, useValue: AlfrescoPipeTranslate, multi: true },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
AlfrescoApiService,
|
||||
UploadService
|
||||
];
|
||||
});
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(
|
||||
inject(
|
||||
[TestComponentBuilder, UploadService],
|
||||
(tcb: TestComponentBuilder, service: UploadService) => {
|
||||
return tcb
|
||||
.createAsync(FileUploadingDialogComponent)
|
||||
.then(fixture => {
|
||||
componentFixture = fixture;
|
||||
uploadService = service;
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
beforeEach(() => {
|
||||
window['componentHandler'] = null;
|
||||
|
||||
it('should render completed upload 1 when an element is added to Observer', () => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
file.progress = {'percent': 50};
|
||||
file = new FileModel(fileFake);
|
||||
|
||||
uploadService.totalCompleted$ = new Observable(observer => {
|
||||
observer.next(1);
|
||||
fixture = TestBed.createComponent(FileUploadingDialogComponent);
|
||||
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
|
||||
component.filesUploadingList = [file];
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
let component = componentFixture.componentInstance;
|
||||
componentFixture.detectChanges();
|
||||
component.filesUploadingList = [file];
|
||||
|
||||
let compiled = componentFixture.debugElement.nativeElement;
|
||||
it('should render completed upload 1 when an element is added to Observer', () => {
|
||||
component._uploaderService.updateFileCounterStream(1);
|
||||
fixture.detectChanges();
|
||||
|
||||
componentFixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('#total-upload-completed').innerText).toEqual('1');
|
||||
expect(element.querySelector('#total-upload-completed').innerText).toEqual('1');
|
||||
});
|
||||
|
||||
it('should render dialog box with css class show when an element is added to Observer', () => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
file.progress = {'percent': 50};
|
||||
|
||||
let component = componentFixture.componentInstance;
|
||||
componentFixture.detectChanges();
|
||||
uploadService.addToQueue([file]);
|
||||
component._uploaderService.addToQueue([file]);
|
||||
component.filesUploadingList = [file];
|
||||
|
||||
let compiled = componentFixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
|
||||
componentFixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
expect(element.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
});
|
||||
|
||||
it('should render dialog box with css class show when the toggleShowDialog is called', () => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
|
||||
let component = componentFixture.componentInstance;
|
||||
componentFixture.detectChanges();
|
||||
component.filesUploadingList = [file];
|
||||
|
||||
let compiled = componentFixture.debugElement.nativeElement;
|
||||
|
||||
component.toggleShowDialog();
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
expect(element.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
});
|
||||
|
||||
it('should render dialog box with css class hide', () => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
let component = componentFixture.componentInstance;
|
||||
component.filesUploadingList = [file];
|
||||
component.isDialogActive = true;
|
||||
|
||||
let compiled = componentFixture.debugElement.nativeElement;
|
||||
|
||||
component.toggleShowDialog();
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog');
|
||||
expect(element.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog');
|
||||
});
|
||||
|
||||
it('should render minimize dialog as default', () => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
let component = componentFixture.componentInstance;
|
||||
component.filesUploadingList = [file];
|
||||
component.isDialogActive = true;
|
||||
|
||||
let compiled = componentFixture.debugElement.nativeElement;
|
||||
|
||||
component.toggleDialogMinimize();
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.minimize-button').getAttribute('class')).toEqual('minimize-button active');
|
||||
expect(element.querySelector('.minimize-button').getAttribute('class')).toEqual('minimize-button active');
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
|
@ -54,7 +54,7 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
|
||||
constructor(private cd: ChangeDetectorRef,
|
||||
translate: AlfrescoTranslationService,
|
||||
private _uploaderService: UploadService) {
|
||||
translate.addTranslationFolder('node_modules/ng2-alfresco-upload/dist/src');
|
||||
translate.addTranslationFolder('./src');
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
@ -15,29 +15,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
import { PLATFORM_PIPES } from '@angular/core';
|
||||
import { beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
import {
|
||||
AlfrescoTranslationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoPipeTranslate
|
||||
} from 'ng2-alfresco-core';
|
||||
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import {
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService,
|
||||
CoreModule,
|
||||
AlfrescoTranslationService
|
||||
} from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
|
||||
declare var AlfrescoApi: any;
|
||||
|
||||
describe('AlfrescoUploadButton', () => {
|
||||
|
||||
let uploadButtonFixture;
|
||||
describe('Test ng2-alfresco-upload UploadButton', () => {
|
||||
|
||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
let fakeEvent = {
|
||||
@ -72,68 +63,73 @@ describe('AlfrescoUploadButton', () => {
|
||||
reject(fakeRejectRest);
|
||||
});
|
||||
|
||||
beforeEach( () => {
|
||||
window['componentHandler'] = null;
|
||||
});
|
||||
let component: any;
|
||||
let fixture: ComponentFixture<UploadButtonComponent>;
|
||||
let debug: DebugElement;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
HTTP_PROVIDERS,
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule
|
||||
],
|
||||
declarations: [UploadButtonComponent],
|
||||
providers: [
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
{ provide: PLATFORM_PIPES, useValue: AlfrescoPipeTranslate, multi: true },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
UploadService
|
||||
];
|
||||
});
|
||||
|
||||
beforeEach( inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(UploadButtonComponent)
|
||||
.then(fixture => uploadButtonFixture = fixture);
|
||||
UploadService,
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
window['componentHandler'] = null;
|
||||
|
||||
fixture = TestBed.createComponent(UploadButtonComponent);
|
||||
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should render upload-single-file button as default', () => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.multipleFiles = false;
|
||||
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||
uploadButtonFixture.detectChanges();
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('#upload-single-file')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should render upload-multiple-file button if multipleFiles is true', () => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.multipleFiles = true;
|
||||
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||
uploadButtonFixture.detectChanges();
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('#upload-multiple-files')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should render an uploadFolder button if uploadFolder is true', () => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.uploadFolder = true;
|
||||
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||
uploadButtonFixture.detectChanges();
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should call uploadFile with the default folder', () => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
||||
component.onSuccess = null;
|
||||
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
uploadButtonFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
|
||||
});
|
||||
|
||||
it('should create a folder and emit an File uploaded event', (done) => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.currentFolderPath = '/fake-root-path';
|
||||
uploadButtonFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(component._uploaderService, 'callApiCreateFolder').and.returnValue(fakeResolvePromise);
|
||||
|
||||
@ -152,9 +148,6 @@ describe('AlfrescoUploadButton', () => {
|
||||
});
|
||||
|
||||
it('should emit an onError event when the folder already exist', (done) => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
uploadButtonFixture.detectChanges();
|
||||
|
||||
spyOn(component._uploaderService, 'callApiCreateFolder').and.returnValue(fakeRejectPromise);
|
||||
component.onError.subscribe(e => {
|
||||
expect(e.value).toEqual('FILE_UPLOAD.MESSAGES.FOLDER_ALREADY_EXIST');
|
||||
@ -164,4 +157,4 @@ describe('AlfrescoUploadButton', () => {
|
||||
component.onDirectoryAdded(fakeEvent);
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
|
@ -89,7 +89,7 @@ export class UploadButtonComponent {
|
||||
|
||||
constructor(public el: ElementRef, private _uploaderService: UploadService, translate: AlfrescoTranslationService) {
|
||||
this.translate = translate;
|
||||
this.translate.addTranslationFolder('node_modules/ng2-alfresco-upload/dist/src');
|
||||
translate.addTranslationFolder('node_modules/ng2-alfresco-upload/dist/src');
|
||||
}
|
||||
|
||||
ngOnChanges(changes) {
|
||||
|
@ -15,47 +15,53 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
import { PLATFORM_PIPES } from '@angular/core';
|
||||
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { UploadDragAreaComponent } from './upload-drag-area.component';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoPipeTranslate } from 'ng2-alfresco-core';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import {
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoTranslationService,
|
||||
CoreModule
|
||||
} from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
|
||||
declare var AlfrescoApi: any;
|
||||
describe('Test ng2-alfresco-upload UploadDragArea', () => {
|
||||
|
||||
describe('AlfrescoUploadDragArea', () => {
|
||||
let component: any;
|
||||
let fixture: ComponentFixture<UploadDragAreaComponent>;
|
||||
let debug: DebugElement;
|
||||
let element: HTMLElement;
|
||||
|
||||
let componentFixture;
|
||||
|
||||
beforeEach( () => {
|
||||
|
||||
});
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
HTTP_PROVIDERS,
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule
|
||||
],
|
||||
declarations: [UploadDragAreaComponent],
|
||||
providers: [
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
{ provide: PLATFORM_PIPES, useValue: AlfrescoPipeTranslate, multi: true },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
UploadService
|
||||
];
|
||||
});
|
||||
|
||||
beforeEach( inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(UploadDragAreaComponent)
|
||||
.then(fixture => componentFixture = fixture);
|
||||
UploadService,
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UploadDragAreaComponent);
|
||||
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should show an folder non supported error in console when the file type is empty', () => {
|
||||
let component = componentFixture.componentInstance;
|
||||
component.showUdoNotificationBar = false;
|
||||
spyOn(console, 'error');
|
||||
|
||||
@ -66,7 +72,6 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
});
|
||||
|
||||
it('should show an folder non supported error in the notification bar when the file type is empty', () => {
|
||||
let component = componentFixture.componentInstance;
|
||||
component._showErrorNotificationBar = jasmine.createSpy('_showErrorNotificationBar');
|
||||
component.showUdoNotificationBar = true;
|
||||
|
||||
@ -77,14 +82,13 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
});
|
||||
|
||||
it('should upload the list of files dropped', () => {
|
||||
let component = componentFixture.componentInstance;
|
||||
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
||||
component.onSuccess = null;
|
||||
component.showUdoNotificationBar = false;
|
||||
component._uploaderService.addToQueue = jasmine.createSpy('addToQueue');
|
||||
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
let fileFake = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
let filesList = [fileFake];
|
||||
|
||||
@ -94,14 +98,13 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
});
|
||||
|
||||
it('should show the loading messages in the notification bar when the files are dropped', () => {
|
||||
let component = componentFixture.componentInstance;
|
||||
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
||||
component.onSuccess = null;
|
||||
component.showUdoNotificationBar = true;
|
||||
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||
component._showUndoNotificationBar = jasmine.createSpy('_showUndoNotificationBar');
|
||||
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
let fileFake = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
let filesList = [fileFake];
|
||||
|
||||
@ -111,11 +114,10 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
});
|
||||
|
||||
it('should upload a file when dropped', done => {
|
||||
let component = componentFixture.componentInstance;
|
||||
component.currentFolderPath = '/root-fake-/sites-fake/document-library-fake';
|
||||
component.onSuccess = null;
|
||||
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
spyOn(component._uploaderService, 'uploadFilesInTheQueue');
|
||||
spyOn(component, '_showUndoNotificationBar').and.callFake( () => {
|
||||
expect(component._showUndoNotificationBar).toHaveBeenCalled();
|
||||
@ -139,11 +141,10 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
});
|
||||
|
||||
it('should throws an exception and show it in the notification bar when the folder already exist', done => {
|
||||
let component = componentFixture.componentInstance;
|
||||
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
||||
component.showUdoNotificationBar = true;
|
||||
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
let fakeRest = {
|
||||
response: {
|
||||
body: {
|
||||
@ -173,11 +174,10 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
});
|
||||
|
||||
it('should create a folder and call onFilesEntityDropped with the file inside the folder', done => {
|
||||
let component = componentFixture.componentInstance;
|
||||
component.currentFolderPath = '/root-fake-/sites-fake/document-library-fake';
|
||||
component.onSuccess = new EventEmitter();
|
||||
|
||||
componentFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
let itemEntity = {
|
||||
fullPath: '/folder-fake/file-fake.png',
|
||||
@ -224,4 +224,4 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
component.onFolderEntityDropped(folderEntry);
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
|
@ -60,7 +60,7 @@ export class UploadDragAreaComponent {
|
||||
|
||||
constructor(private _uploaderService: UploadService, translate: AlfrescoTranslationService) {
|
||||
this.translate = translate;
|
||||
this.translate.addTranslationFolder('node_modules/ng2-alfresco-upload/dist/src');
|
||||
translate.addTranslationFolder('node_modules/ng2-alfresco-upload/dist/src');
|
||||
}
|
||||
|
||||
ngOnChanges(changes) {
|
||||
@ -240,10 +240,12 @@ export class UploadDragAreaComponent {
|
||||
* @returns {string} - The message without placeholder
|
||||
*/
|
||||
private formatString(message: string, keys: any []) {
|
||||
if (message) {
|
||||
let i = keys.length;
|
||||
while (i--) {
|
||||
message = message.replace(new RegExp('\\{' + i + '\\}', 'gm'), keys[i]);
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
||||
|
||||
describe('AlfrescoDirectiveFileDraggable', () => {
|
||||
describe('Test ng2-alfresco-upload FileDraggableDirective', () => {
|
||||
|
||||
let component;
|
||||
|
||||
@ -101,9 +101,4 @@ describe('AlfrescoDirectiveFileDraggable', () => {
|
||||
component._onDragEnter(mockEvent);
|
||||
expect(component.getInputFocus()).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
@ -15,17 +15,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { ReflectiveInjector } from '@angular/core';
|
||||
import {
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService
|
||||
} from 'ng2-alfresco-core';
|
||||
import { UploadService } from './upload.service';
|
||||
import { AlfrescoSettingsService, AlfrescoApiService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
|
||||
declare let AlfrescoApi: any;
|
||||
declare let jasmine: any;
|
||||
declare let AlfrescoApi: any;
|
||||
|
||||
describe('AlfrescoUploadService', () => {
|
||||
let service, options: any;
|
||||
describe('Test ng2-alfresco-upload', () => {
|
||||
let service, injector, options;
|
||||
|
||||
options = {
|
||||
host: 'fakehost',
|
||||
@ -37,39 +40,39 @@ describe('AlfrescoUploadService', () => {
|
||||
}
|
||||
};
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
beforeEach(() => {
|
||||
injector = ReflectiveInjector.resolveAndCreate([
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoAuthenticationService,
|
||||
UploadService
|
||||
];
|
||||
]);
|
||||
});
|
||||
|
||||
beforeEach( inject([UploadService, AlfrescoApiService], (uploadService: UploadService, apiService: AlfrescoApiService) => {
|
||||
describe('UploadService ', () => {
|
||||
beforeEach(() => {
|
||||
service = injector.get(UploadService);
|
||||
service.apiService.setInstance(new AlfrescoApi({}));
|
||||
jasmine.Ajax.install();
|
||||
service = uploadService;
|
||||
apiService.setInstance(new AlfrescoApi({}));
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should return an empty queue if no elements are added', () => {
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
expect(service.getQueue().length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should add an element in the queue and returns it', () => {
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let filesFake = [{name: 'fake-name', size: 10}];
|
||||
service.addToQueue(filesFake);
|
||||
expect(service.getQueue().length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should add two elements in the queue and returns them', () => {
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let filesFake = [{name: 'fake-name', size: 10}, {name: 'fake-name2', size: 20}];
|
||||
service.addToQueue(filesFake);
|
||||
expect(service.getQueue().length).toEqual(2);
|
||||
@ -82,7 +85,7 @@ describe('AlfrescoUploadService', () => {
|
||||
expect(e.value).toBe('File uploaded');
|
||||
done();
|
||||
});
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let filesFake = [{name: 'fake-name', size: 10}];
|
||||
service.addToQueue(filesFake);
|
||||
service.uploadFilesInTheQueue('fake-dir', emitter);
|
||||
@ -105,7 +108,7 @@ describe('AlfrescoUploadService', () => {
|
||||
expect(e.value).toBe('Error file uploaded');
|
||||
done();
|
||||
});
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let filesFake = [{name: 'fake-name', size: 10}];
|
||||
service.addToQueue(filesFake);
|
||||
service.uploadFilesInTheQueue('', emitter);
|
||||
@ -126,7 +129,7 @@ describe('AlfrescoUploadService', () => {
|
||||
expect(e.value).toEqual('File aborted');
|
||||
done();
|
||||
});
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let filesFake = [{name: 'fake-name', size: 10}];
|
||||
service.addToQueue(filesFake);
|
||||
service.uploadFilesInTheQueue('', emitter);
|
||||
@ -142,7 +145,7 @@ describe('AlfrescoUploadService', () => {
|
||||
expect(e.value).toBe('Error file uploaded');
|
||||
done();
|
||||
});
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let filesFake = [{name: 'fake-name', size: 10}];
|
||||
service.addToQueue(filesFake);
|
||||
service.uploadFilesInTheQueue('', emitter);
|
||||
@ -152,7 +155,7 @@ describe('AlfrescoUploadService', () => {
|
||||
});
|
||||
|
||||
it('should make XHR progress request after the onprogress is called', (done) => {
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let fakeProgress = {
|
||||
loaded: 500,
|
||||
total: 1234,
|
||||
@ -185,7 +188,7 @@ describe('AlfrescoUploadService', () => {
|
||||
resolve(fakeRest);
|
||||
});
|
||||
spyOn(service, 'callApiCreateFolder').and.returnValue(fakePromise);
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let defaultPath = '';
|
||||
let folderName = 'fake-folder';
|
||||
service.createFolder(defaultPath, folderName).subscribe(res => {
|
||||
@ -208,7 +211,7 @@ describe('AlfrescoUploadService', () => {
|
||||
reject(fakeRest);
|
||||
});
|
||||
spyOn(service, 'callApiCreateFolder').and.returnValue(fakePromise);
|
||||
service.setOptions(options);
|
||||
service.setOptions(options, false);
|
||||
let defaultPath = '';
|
||||
let folderName = 'folder-duplicate-fake';
|
||||
service.createFolder(defaultPath, folderName).subscribe(
|
||||
@ -235,4 +238,5 @@ describe('AlfrescoUploadService', () => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().params.has('majorVersion')).toBe(true);
|
||||
});
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user