mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
Merge pull request #201 from Alfresco/dev-mvitale-189
#189 Fix upload component tests
This commit is contained in:
commit
b1a5eb4736
@ -0,0 +1,51 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
System.register(['./src/components/datatable.component', './src/data/datatable-adapter', './src/data/object-datatable-adapter'], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var datatable_component_1;
|
||||
var ALFRESCO_DATATABLE_DIRECTIVES;
|
||||
var exportedNames_1 = {
|
||||
'ALFRESCO_DATATABLE_DIRECTIVES': true
|
||||
};
|
||||
function exportStar_1(m) {
|
||||
var exports = {};
|
||||
for(var n in m) {
|
||||
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n];
|
||||
}
|
||||
exports_1(exports);
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (datatable_component_1_1) {
|
||||
datatable_component_1 = datatable_component_1_1;
|
||||
exportStar_1(datatable_component_1_1);
|
||||
},
|
||||
function (datatable_adapter_1_1) {
|
||||
exportStar_1(datatable_adapter_1_1);
|
||||
},
|
||||
function (object_datatable_adapter_1_1) {
|
||||
exportStar_1(object_datatable_adapter_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("ALFRESCO_DATATABLE_DIRECTIVES", ALFRESCO_DATATABLE_DIRECTIVES = [
|
||||
datatable_component_1.DataTableComponent
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=ng2-alfresco-datatable.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ng2-alfresco-datatable.js","sourceRoot":"","sources":["ng2-alfresco-datatable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;QAWU,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;YAA7B,2CAAA,6BAA6B,GAAU;gBAChD,wCAAkB;aACrB,CAAA,CAAC"}
|
@ -0,0 +1,100 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
System.register(['./src/components/document-list', './src/components/content-column', './src/components/content-column-list', './src/components/content-action', './src/components/content-action-list', './src/services/folder-actions.service', './src/services/document-actions.service', './src/services/alfresco.service', './src/models/column-sorting.model'], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var document_list_1, content_column_1, content_column_list_1, content_action_1, content_action_list_1, folder_actions_service_1, document_actions_service_1, alfresco_service_1;
|
||||
var DOCUMENT_LIST_DIRECTIVES, DOCUMENT_LIST_PROVIDERS;
|
||||
var exportedNames_1 = {
|
||||
'DOCUMENT_LIST_DIRECTIVES': true,
|
||||
'DOCUMENT_LIST_PROVIDERS': true
|
||||
};
|
||||
function exportStar_1(m) {
|
||||
var exports = {};
|
||||
for(var n in m) {
|
||||
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n];
|
||||
}
|
||||
exports_1(exports);
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (document_list_1_1) {
|
||||
document_list_1 = document_list_1_1;
|
||||
exportStar_1(document_list_1_1);
|
||||
},
|
||||
function (content_column_1_1) {
|
||||
content_column_1 = content_column_1_1;
|
||||
exportStar_1(content_column_1_1);
|
||||
},
|
||||
function (content_column_list_1_1) {
|
||||
content_column_list_1 = content_column_list_1_1;
|
||||
exportStar_1(content_column_list_1_1);
|
||||
},
|
||||
function (content_action_1_1) {
|
||||
content_action_1 = content_action_1_1;
|
||||
exportStar_1(content_action_1_1);
|
||||
},
|
||||
function (content_action_list_1_1) {
|
||||
content_action_list_1 = content_action_list_1_1;
|
||||
exportStar_1(content_action_list_1_1);
|
||||
},
|
||||
function (folder_actions_service_1_1) {
|
||||
folder_actions_service_1 = folder_actions_service_1_1;
|
||||
exportStar_1(folder_actions_service_1_1);
|
||||
},
|
||||
function (document_actions_service_1_1) {
|
||||
document_actions_service_1 = document_actions_service_1_1;
|
||||
exportStar_1(document_actions_service_1_1);
|
||||
},
|
||||
function (alfresco_service_1_1) {
|
||||
alfresco_service_1 = alfresco_service_1_1;
|
||||
exportStar_1(alfresco_service_1_1);
|
||||
},
|
||||
function (column_sorting_model_1_1) {
|
||||
exportStar_1(column_sorting_model_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("default",{
|
||||
directives: [
|
||||
document_list_1.DocumentList,
|
||||
content_column_1.ContentColumn,
|
||||
content_column_list_1.ContentColumnList,
|
||||
content_action_1.ContentAction,
|
||||
content_action_list_1.ContentActionList
|
||||
],
|
||||
providers: [
|
||||
alfresco_service_1.AlfrescoService,
|
||||
folder_actions_service_1.FolderActionsService,
|
||||
document_actions_service_1.DocumentActionsService
|
||||
]
|
||||
});
|
||||
exports_1("DOCUMENT_LIST_DIRECTIVES", DOCUMENT_LIST_DIRECTIVES = [
|
||||
document_list_1.DocumentList,
|
||||
content_column_1.ContentColumn,
|
||||
content_column_list_1.ContentColumnList,
|
||||
content_action_1.ContentAction,
|
||||
content_action_list_1.ContentActionList
|
||||
]);
|
||||
exports_1("DOCUMENT_LIST_PROVIDERS", DOCUMENT_LIST_PROVIDERS = [
|
||||
alfresco_service_1.AlfrescoService,
|
||||
folder_actions_service_1.FolderActionsService,
|
||||
document_actions_service_1.DocumentActionsService
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=ng2-alfresco-documentlist.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ng2-alfresco-documentlist.js","sourceRoot":"","sources":["ng2-alfresco-documentlist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;QA0CU,wBAAwB,EAQxB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAvBpC,oBAAe;gBACX,UAAU,EAAE;oBACR,4BAAY;oBACZ,8BAAa;oBACb,uCAAiB;oBACjB,8BAAa;oBACb,uCAAiB;iBACpB;gBACD,SAAS,EAAE;oBACP,kCAAe;oBACf,6CAAoB;oBACpB,iDAAsB;iBACzB;aACJ,EAAC;YAEW,sCAAA,wBAAwB,GAAU;gBAC3C,4BAAY;gBACZ,8BAAa;gBACb,uCAAiB;gBACjB,8BAAa;gBACb,uCAAiB;aACpB,CAAA,CAAC;YAEW,qCAAA,uBAAuB,GAAU;gBAC1C,kCAAe;gBACf,6CAAoB;gBACpB,iDAAsB;aACzB,CAAA,CAAC"}
|
53
ng2-components/ng2-alfresco-login/ng2-alfresco-login.js
Normal file
53
ng2-components/ng2-alfresco-login/ng2-alfresco-login.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
System.register(['./src/components/alfresco-login.component', './src/services/alfresco-authentication.service'], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var alfresco_login_component_1, alfresco_authentication_service_1;
|
||||
var ALFRESCO_LOGIN_DIRECTIVES, ALFRESCO_AUTHENTICATION;
|
||||
var exportedNames_1 = {
|
||||
'ALFRESCO_LOGIN_DIRECTIVES': true,
|
||||
'ALFRESCO_AUTHENTICATION': true
|
||||
};
|
||||
function exportStar_1(m) {
|
||||
var exports = {};
|
||||
for(var n in m) {
|
||||
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n];
|
||||
}
|
||||
exports_1(exports);
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (alfresco_login_component_1_1) {
|
||||
alfresco_login_component_1 = alfresco_login_component_1_1;
|
||||
exportStar_1(alfresco_login_component_1_1);
|
||||
},
|
||||
function (alfresco_authentication_service_1_1) {
|
||||
alfresco_authentication_service_1 = alfresco_authentication_service_1_1;
|
||||
exportStar_1(alfresco_authentication_service_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("default",{
|
||||
directives: [alfresco_login_component_1.AlfrescoLoginComponent],
|
||||
providers: [alfresco_authentication_service_1.AlfrescoAuthenticationService]
|
||||
});
|
||||
exports_1("ALFRESCO_LOGIN_DIRECTIVES", ALFRESCO_LOGIN_DIRECTIVES = [alfresco_login_component_1.AlfrescoLoginComponent]);
|
||||
exports_1("ALFRESCO_AUTHENTICATION", ALFRESCO_AUTHENTICATION = [alfresco_authentication_service_1.AlfrescoAuthenticationService]);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=ng2-alfresco-login.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ng2-alfresco-login.js","sourceRoot":"","sources":["ng2-alfresco-login.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;QAaU,yBAAyB,EACzB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;YANpC,oBAAe;gBACX,UAAU,EAAE,CAAC,iDAAsB,CAAC;gBACpC,SAAS,EAAE,CAAC,+DAA6B,CAAC;aAC7C,EAAC;YAEW,uCAAA,yBAAyB,GAAU,CAAC,iDAAsB,CAAC,CAAA,CAAC;YAC5D,qCAAA,uBAAuB,GAAU,CAAC,+DAA6B,CAAC,CAAA,CAAC"}
|
62
ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js
Normal file
62
ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js
Normal file
@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
System.register(['./src/components/upload-drag-area.component', './src/directives/file-draggable.directive', './src/components/upload-button.component', './src/services/upload.service'], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var upload_drag_area_component_1, file_draggable_directive_1, upload_button_component_1;
|
||||
var ALFRESCO_ULPOAD_COMPONENT;
|
||||
var exportedNames_1 = {
|
||||
'ALFRESCO_ULPOAD_COMPONENT': true
|
||||
};
|
||||
function exportStar_1(m) {
|
||||
var exports = {};
|
||||
for(var n in m) {
|
||||
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n];
|
||||
}
|
||||
exports_1(exports);
|
||||
}
|
||||
return {
|
||||
setters:[
|
||||
function (upload_drag_area_component_1_1) {
|
||||
upload_drag_area_component_1 = upload_drag_area_component_1_1;
|
||||
exportStar_1(upload_drag_area_component_1_1);
|
||||
},
|
||||
function (file_draggable_directive_1_1) {
|
||||
file_draggable_directive_1 = file_draggable_directive_1_1;
|
||||
exportStar_1(file_draggable_directive_1_1);
|
||||
},
|
||||
function (upload_button_component_1_1) {
|
||||
upload_button_component_1 = upload_button_component_1_1;
|
||||
exportStar_1(upload_button_component_1_1);
|
||||
},
|
||||
function (upload_service_1_1) {
|
||||
exportStar_1(upload_service_1_1);
|
||||
}],
|
||||
execute: function() {
|
||||
exports_1("default",{
|
||||
component: [upload_drag_area_component_1.UploadDragAreaComponent, upload_button_component_1.UploadButtonComponent],
|
||||
directives: [file_draggable_directive_1.FileDraggableDirective]
|
||||
});
|
||||
exports_1("ALFRESCO_ULPOAD_COMPONENT", ALFRESCO_ULPOAD_COMPONENT = [
|
||||
upload_drag_area_component_1.UploadDragAreaComponent,
|
||||
upload_button_component_1.UploadButtonComponent,
|
||||
file_draggable_directive_1.FileDraggableDirective
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=ng2-alfresco-upload.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ng2-alfresco-upload.js","sourceRoot":"","sources":["ng2-alfresco-upload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;QAgCU,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YALtC,oBAAe;gBACb,SAAS,EAAE,CAAC,oDAAuB,EAAE,+CAAqB,CAAC;gBAC3D,UAAU,EAAE,CAAC,iDAAsB,CAAC;aACrC,EAAC;YAEW,uCAAA,yBAAyB,GAAU;gBAC9C,oDAAuB;gBACvB,+CAAqB;gBACrB,iDAAsB;aACvB,CAAA,CAAC"}
|
@ -0,0 +1,59 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export class AlfrescoApiMock {
|
||||
|
||||
static getClientWithTicket(basePath: string, ticket: string) {
|
||||
return {authentications: {basicAuth: {password: 'fake-password', type: 'fake-basic', username: 'fake-user'}}};
|
||||
}
|
||||
|
||||
}
|
||||
export module AlfrescoApiMock {
|
||||
|
||||
export class NodesApi {
|
||||
|
||||
constructor(alfrescoClient: any) {
|
||||
}
|
||||
|
||||
addNode(nodeId, nodeBody, opts) {
|
||||
if (nodeId && nodeBody.name !== 'folder-duplicate-fake') {
|
||||
return new Promise(function (resolve, reject) {
|
||||
resolve({
|
||||
entry: {
|
||||
isFile: false,
|
||||
isFolder: true
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject({
|
||||
response: {
|
||||
body: {
|
||||
error: {
|
||||
statusCode: 409
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -27,22 +27,11 @@ export class TranslationMock {
|
||||
|
||||
public onLangChange: EventEmitter<LangChangeEvent> = new EventEmitter<LangChangeEvent>();
|
||||
|
||||
setDefaultLang() {
|
||||
console.log('mock');
|
||||
}
|
||||
|
||||
use() {
|
||||
console.log('mock');
|
||||
}
|
||||
|
||||
addTranslationFolder() {
|
||||
|
||||
}
|
||||
|
||||
public get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
|
||||
if (!key) {
|
||||
throw new Error('Parameter "key" required');
|
||||
}
|
||||
return Observable.of(key);
|
||||
}
|
||||
}
|
||||
|
@ -15,14 +15,71 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Observer } from 'rxjs/Observer';
|
||||
import { FileModel } from '../models/file.model';
|
||||
|
||||
export class UploadServiceMock {
|
||||
|
||||
private _baseUrlPath: string = 'fakebaseurlpath';
|
||||
private _url: string = 'fakeurl';
|
||||
private _formFields: Object = {};
|
||||
|
||||
filesUpload$: Observable<any>;
|
||||
totalCompleted$: Observable<number>;
|
||||
|
||||
public setOptions(options: any): void {
|
||||
this._url = options._url || this._url;
|
||||
this._baseUrlPath = options.baseUrlPath || this._baseUrlPath;
|
||||
this._formFields = options.formFields != null ? options.formFields : this._formFields;
|
||||
}
|
||||
|
||||
addToQueue(files: any[]): FileModel[] {
|
||||
this.filesUpload$ = new Observable(observer => {
|
||||
observer.next(files);
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
createFolder(relativePath: string, name: string) {
|
||||
let promise: Promise<any>;
|
||||
if (name !== 'folder-duplicate-fake') {
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
resolve({
|
||||
entry: {
|
||||
userId: 'fake-username',
|
||||
id: 'fake-post-token'
|
||||
}
|
||||
})
|
||||
});
|
||||
} else {
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
reject({
|
||||
response: {
|
||||
body: {
|
||||
error: {
|
||||
statusCode: 409
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return Observable.fromPromise(promise)
|
||||
.map(res => {
|
||||
return res;
|
||||
})
|
||||
.do(data => console.log('Node data', data))
|
||||
.catch((error => {
|
||||
return Observable.throw(error);
|
||||
}));
|
||||
}
|
||||
|
||||
public uploadFilesInTheQueue(directory: string, elementEmit: any): void {
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<div *ngIf="filesUploadingList" class="file-dialog" [ngClass]="{show: isDialogActive}">
|
||||
<div class="header">
|
||||
<div class="title">
|
||||
{{totalCompleted}} {{'FILE_UPLOAD.MESSAGES.COMPLETED' | translate}}
|
||||
<span id="total-upload-completed">{{totalCompleted}}</span> {{'FILE_UPLOAD.MESSAGES.COMPLETED' | translate}}
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<div class="minimize-button" [ngClass]="{active: _isDialogMinimized}" (click)="toggleDialogMinimize()">
|
||||
|
@ -24,8 +24,11 @@ import {
|
||||
import { provide } from '@angular/core';
|
||||
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
||||
import { FileModel } from '../models/file.model';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadServiceMock } from '../assets/upload.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
describe('FileUploadDialog', () => {
|
||||
|
||||
@ -33,11 +36,106 @@ describe('FileUploadDialog', () => {
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
provide(AlfrescoTranslationService, {useClass: TranslationMock})
|
||||
provide(AlfrescoSettingsService, {useClass: AlfrescoSettingsService}),
|
||||
provide(AlfrescoTranslationService, {useClass: TranslationMock}),
|
||||
provide(UploadService, {useClass: UploadServiceMock})
|
||||
];
|
||||
});
|
||||
|
||||
it('should render dialog box with css class show', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
it('should render completed upload 1 when an element is added to Observer',
|
||||
inject([TestComponentBuilder, UploadService],
|
||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
||||
return tcb
|
||||
.createAsync(FileUploadingDialogComponent)
|
||||
.then((fixture) => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
file.progress = {'percent': 50};
|
||||
|
||||
updService.totalCompleted$ = new Observable(observer => {
|
||||
observer.next(1);
|
||||
});
|
||||
|
||||
let component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
component.filesUploadingList = [file];
|
||||
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('#total-upload-completed').innerText).toEqual('1');
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
it('should render dialog box with css class show when an element is added to Observer',
|
||||
inject([TestComponentBuilder, UploadService],
|
||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
||||
return tcb
|
||||
.createAsync(FileUploadingDialogComponent)
|
||||
.then((fixture) => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
file.progress = {'percent': 50};
|
||||
|
||||
updService.addToQueue([file]);
|
||||
|
||||
|
||||
let component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
component.filesUploadingList = [file];
|
||||
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
it('should render dialog box with css class show when the toggleShowDialog is called',
|
||||
inject([TestComponentBuilder, UploadService],
|
||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
||||
return tcb
|
||||
.createAsync(FileUploadingDialogComponent)
|
||||
.then((fixture) => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
|
||||
let component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
component.filesUploadingList = [file];
|
||||
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
|
||||
component.toggleShowDialog();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
it('should render dialog box with css class hide',
|
||||
inject([TestComponentBuilder],
|
||||
(tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(FileUploadingDialogComponent)
|
||||
.then((fixture) => {
|
||||
@ -48,12 +146,40 @@ describe('FileUploadDialog', () => {
|
||||
let file = new FileModel(fileFake);
|
||||
let component = fixture.componentInstance;
|
||||
component.filesUploadingList = [file];
|
||||
component.isDialogActive = true;
|
||||
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
component.showDialog();
|
||||
|
||||
component.toggleShowDialog();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog');
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
it('should render minimize dialog as default',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(FileUploadingDialogComponent)
|
||||
.then((fixture) => {
|
||||
let fileFake = {
|
||||
id: 'fake-id',
|
||||
name: 'fake-name'
|
||||
};
|
||||
let file = new FileModel(fileFake);
|
||||
let component = fixture.componentInstance;
|
||||
component.filesUploadingList = [file];
|
||||
component.isDialogActive = true;
|
||||
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
|
||||
component.toggleDialogMinimize();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(compiled.querySelector('.minimize-button').getAttribute('class')).toEqual('minimize-button active');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
@ -60,6 +60,7 @@ export class FileUploadingDialogComponent implements OnInit{
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if(this._uploaderService.filesUpload$) {
|
||||
this._uploaderService.filesUpload$.subscribe((fileList: FileModel[]) => {
|
||||
this.filesUploadingList = fileList;
|
||||
if (this.filesUploadingList.length > 0) {
|
||||
@ -67,11 +68,14 @@ export class FileUploadingDialogComponent implements OnInit{
|
||||
this.cd.detectChanges();
|
||||
}
|
||||
});
|
||||
}
|
||||
if(this._uploaderService.totalCompleted$) {
|
||||
this._uploaderService.totalCompleted$.subscribe((total: number) => {
|
||||
this.totalCompleted = total;
|
||||
this.cd.detectChanges();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display and hide the dialog component.
|
||||
|
@ -19,15 +19,25 @@ import { describe, expect, it, inject, beforeEachProviders } from '@angular/core
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { provide } from '@angular/core';
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadServiceMock } from '../assets/upload.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { AlfrescoApiMock } from '../assets/AlfrescoApi.mock';
|
||||
|
||||
|
||||
declare var AlfrescoApi: any;
|
||||
|
||||
describe('AlfrescoUploadButton', () => {
|
||||
|
||||
beforeEach( () => {
|
||||
window['AlfrescoApi'] = AlfrescoApiMock;
|
||||
window['componentHandler'] = null;
|
||||
});
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
provide(AlfrescoSettingsService, {useClass: AlfrescoSettingsService}),
|
||||
provide(AlfrescoTranslationService, {useClass: TranslationMock}),
|
||||
provide(UploadService, {useClass: UploadServiceMock})
|
||||
];
|
||||
@ -72,37 +82,74 @@ describe('AlfrescoUploadButton', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should call onFilesAdded method', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
it('should call uploadFile with the default folder', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(UploadButtonComponent)
|
||||
.then((fixture) => {
|
||||
let component = fixture.componentInstance;
|
||||
component.onFilesAdded = jasmine.createSpy('onFilesAdded');
|
||||
component.uploaddirectory = 'folder-default';
|
||||
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
||||
|
||||
fixture.detectChanges();
|
||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
|
||||
let fakeEvent = {
|
||||
currentTarget: {files: [{name: 'fake-name', size: 10}]}
|
||||
currentTarget: {
|
||||
files: [file]
|
||||
},
|
||||
target: {value: 'fake-value'}
|
||||
};
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(component.onFilesAdded).toHaveBeenCalledWith(fakeEvent);
|
||||
expect(component.uploadFiles).toHaveBeenCalledWith('folder-default', [file]);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should render dialog box with css class show',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
it('should create a folder and call upload file', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(UploadButtonComponent)
|
||||
.then((fixture) => {
|
||||
let component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
|
||||
component._showDialog();
|
||||
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
||||
let doneFn = jasmine.createSpy('success');
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||
|
||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
|
||||
let fakeEvent = {
|
||||
currentTarget: {
|
||||
files: [file]
|
||||
},
|
||||
target: {value: 'fake-value'}
|
||||
};
|
||||
component.onDirectoryAdded(fakeEvent);
|
||||
expect(doneFn).not.toHaveBeenCalledWith(fakeEvent);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should throws an exception when the folder already exist', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(UploadButtonComponent)
|
||||
.then((fixture) => {
|
||||
let component = fixture.componentInstance;
|
||||
|
||||
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'folder-duplicate-fake/fake-name-1.json'};
|
||||
|
||||
let fakeEvent = {
|
||||
currentTarget: {
|
||||
files: [file]
|
||||
},
|
||||
target: {value: 'fake-value'}
|
||||
};
|
||||
component.onDirectoryAdded(fakeEvent);
|
||||
expect(component.uploadFiles).not.toHaveBeenCalledWith(fakeEvent);
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
|
@ -135,10 +135,12 @@ export class UploadButtonComponent {
|
||||
},
|
||||
error => {
|
||||
let errorMessagePlaceholder = this.getErrorMessage(error.response);
|
||||
if (errorMessagePlaceholder) {
|
||||
let errorMessage = this.formatString(errorMessagePlaceholder, [directoryName]);
|
||||
if (errorMessage) {
|
||||
this._showErrorNotificationBar(errorMessage);
|
||||
}
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
@ -222,6 +224,7 @@ export class UploadButtonComponent {
|
||||
messageTranslate = this.translate.get('FILE_UPLOAD.MESSAGES.PROGRESS');
|
||||
actionTranslate = this.translate.get('FILE_UPLOAD.ACTION.UNDO');
|
||||
|
||||
if(this.undoNotificationBar.nativeElement.MaterialSnackbar) {
|
||||
this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({
|
||||
message: messageTranslate.value,
|
||||
timeout: 3000,
|
||||
@ -233,6 +236,7 @@ export class UploadButtonComponent {
|
||||
actionText: actionTranslate.value
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive the error message using the error status code
|
||||
@ -257,11 +261,13 @@ export class UploadButtonComponent {
|
||||
componentHandler.upgradeAllRegistered();
|
||||
}
|
||||
|
||||
if (this.undoNotificationBar.nativeElement.MaterialSnackbar) {
|
||||
this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({
|
||||
message: errorMessage,
|
||||
timeout: 3000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the site from the path
|
||||
|
@ -18,6 +18,10 @@
|
||||
import { it, describe, beforeEach, expect } from '@angular/core/testing';
|
||||
import { UploadService } from './upload.service';
|
||||
import { FileModel } from './../models/file.model';
|
||||
import { AlfrescoApiMock } from '../assets/AlfrescoApi.mock';
|
||||
|
||||
|
||||
declare var AlfrescoApi: any;
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
@ -42,6 +46,7 @@ class MockUploadService extends UploadService {
|
||||
|
||||
describe('AlfrescoUploadService', () => {
|
||||
let service: MockUploadService,
|
||||
serviceUpload: UploadService,
|
||||
options: any;
|
||||
|
||||
options = {
|
||||
@ -56,7 +61,9 @@ describe('AlfrescoUploadService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
window['AlfrescoApi'] = AlfrescoApiMock;
|
||||
service = new MockUploadService(options);
|
||||
serviceUpload = new UploadService(options);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -160,4 +167,55 @@ describe('AlfrescoUploadService', () => {
|
||||
});
|
||||
expect(doneFn).toHaveBeenCalledWith('Single File uploaded');
|
||||
});
|
||||
|
||||
it('should make XHR done request after the folder is created', (done) => {
|
||||
let fakeRest = {
|
||||
entry: {
|
||||
isFile: false,
|
||||
isFolder: true
|
||||
}
|
||||
};
|
||||
service.setOptions(options);
|
||||
let defaultPath = '';
|
||||
let folderName = 'fake-folder';
|
||||
service.createFolder(defaultPath, folderName).subscribe(res => {
|
||||
expect(res).toEqual(fakeRest);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throws an exception when a folder already exist', (done) => {
|
||||
let fakeRest = {
|
||||
response: {
|
||||
body: {
|
||||
error: {
|
||||
statusCode: 409
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
service.setOptions(options);
|
||||
let defaultPath = '';
|
||||
let folderName = 'folder-duplicate-fake';
|
||||
service.createFolder(defaultPath, folderName).subscribe(
|
||||
res => {
|
||||
},
|
||||
error => {
|
||||
expect(error).toEqual(fakeRest);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should create an XHR object ', () => {
|
||||
service.setOptions(options);
|
||||
let filesFake = {name: 'fake-name', size: 10};
|
||||
let uploadingFileModel = new FileModel(filesFake);
|
||||
let xhrRequest = serviceUpload.createXMLHttpRequestInstance(uploadingFileModel, null);
|
||||
expect(xhrRequest.upload).toBeDefined();
|
||||
expect(xhrRequest.upload.onabort).toBeDefined();
|
||||
expect(xhrRequest.upload.onprogress).toBeDefined();
|
||||
expect(xhrRequest.upload.onerror).toBeDefined();
|
||||
expect(xhrRequest.onreadystatechange).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ export class UploadService {
|
||||
private _queue: FileModel[] = [];
|
||||
|
||||
filesUpload$: Observable<FileModel[]>;
|
||||
totalCompleted$: Observable<number>;
|
||||
totalCompleted$: Observable<any>;
|
||||
private _filesUploadObserver: Observer<FileModel[]>;
|
||||
private _totalCompletedObserver: Observer<number>;
|
||||
|
||||
@ -115,15 +115,7 @@ export class UploadService {
|
||||
* @returns {AlfrescoApi.ApiClient}
|
||||
*/
|
||||
private getAlfrescoClient() {
|
||||
let defaultClient = new AlfrescoApi.ApiClient();
|
||||
defaultClient.basePath = this.getHost() + this.getBaseUrl();
|
||||
|
||||
// Configure HTTP basic authorization: basicAuth
|
||||
let basicAuth = defaultClient.authentications['basicAuth'];
|
||||
basicAuth.username = 'ROLE_TICKET';
|
||||
basicAuth.password = this.getAlfrescoTicket();
|
||||
|
||||
return defaultClient;
|
||||
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,7 +152,7 @@ export class UploadService {
|
||||
uploadingFileModel.setUploading();
|
||||
this.uploadFile(uploadingFileModel, directory, elementEmit);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an XMLHttpRequest and return it
|
||||
@ -220,8 +212,6 @@ export class UploadService {
|
||||
uploadFile(uploadingFileModel: FileModel, directory: string, elementEmit: EventEmitter<any>): void {
|
||||
// Configure HTTP basic authorization: basicAuth
|
||||
let basicAuth = this._alfrescoClient.authentications['basicAuth'];
|
||||
basicAuth.username = 'ROLE_TICKET';
|
||||
basicAuth.password = this.getAlfrescoTicket();
|
||||
|
||||
let form = new FormData();
|
||||
form.append(this._fieldName, uploadingFileModel.file, uploadingFileModel.name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user