From 604c1c7ebab27ced6c3fc42ed70f4715141b2a24 Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Wed, 15 Jun 2016 13:09:00 +0100 Subject: [PATCH 1/2] #189 Fix upload test --- .../ng2-alfresco-datatable.js | 51 ++++++ .../ng2-alfresco-datatable.js.map | 1 + .../ng2-alfresco-documentlist.js | 100 +++++++++++ .../ng2-alfresco-documentlist.js.map | 1 + .../ng2-alfresco-login/ng2-alfresco-login.js | 53 ++++++ .../ng2-alfresco-login.js.map | 1 + .../ng2-alfresco-upload.js | 62 +++++++ .../ng2-alfresco-upload.js.map | 1 + .../src/assets/AlfrescoApi.mock.ts | 59 +++++++ .../src/assets/translation.service.mock.ts | 11 -- .../src/assets/upload.service.mock.ts | 57 ++++++ .../file-uploading-dialog.component.html | 2 +- .../file-uploading-dialog.component.spec.ts | 164 ++++++++++++++++-- .../file-uploading-dialog.component.ts | 24 +-- .../upload-button.component.spec.ts | 85 +++++++-- .../src/components/upload-button.component.ts | 40 +++-- .../src/services/upload.service.spec.ts | 44 +++++ .../src/services/upload.service.ts | 16 +- 18 files changed, 682 insertions(+), 90 deletions(-) create mode 100644 ng2-components/ng2-alfresco-datatable/ng2-alfresco-datatable.js create mode 100644 ng2-components/ng2-alfresco-datatable/ng2-alfresco-datatable.js.map create mode 100644 ng2-components/ng2-alfresco-documentlist/ng2-alfresco-documentlist.js create mode 100644 ng2-components/ng2-alfresco-documentlist/ng2-alfresco-documentlist.js.map create mode 100644 ng2-components/ng2-alfresco-login/ng2-alfresco-login.js create mode 100644 ng2-components/ng2-alfresco-login/ng2-alfresco-login.js.map create mode 100644 ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js create mode 100644 ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js.map create mode 100644 ng2-components/ng2-alfresco-upload/src/assets/AlfrescoApi.mock.ts diff --git a/ng2-components/ng2-alfresco-datatable/ng2-alfresco-datatable.js b/ng2-components/ng2-alfresco-datatable/ng2-alfresco-datatable.js new file mode 100644 index 0000000000..60afee4b0d --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/ng2-alfresco-datatable.js @@ -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 \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-datatable/ng2-alfresco-datatable.js.map b/ng2-components/ng2-alfresco-datatable/ng2-alfresco-datatable.js.map new file mode 100644 index 0000000000..4b1b2d8aa7 --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/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"} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-documentlist/ng2-alfresco-documentlist.js b/ng2-components/ng2-alfresco-documentlist/ng2-alfresco-documentlist.js new file mode 100644 index 0000000000..412c4b9b32 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/ng2-alfresco-documentlist.js @@ -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 \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-documentlist/ng2-alfresco-documentlist.js.map b/ng2-components/ng2-alfresco-documentlist/ng2-alfresco-documentlist.js.map new file mode 100644 index 0000000000..347c1d4161 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/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"} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-login/ng2-alfresco-login.js b/ng2-components/ng2-alfresco-login/ng2-alfresco-login.js new file mode 100644 index 0000000000..d8ea9f45e8 --- /dev/null +++ b/ng2-components/ng2-alfresco-login/ng2-alfresco-login.js @@ -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 \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-login/ng2-alfresco-login.js.map b/ng2-components/ng2-alfresco-login/ng2-alfresco-login.js.map new file mode 100644 index 0000000000..2077ee571a --- /dev/null +++ b/ng2-components/ng2-alfresco-login/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"} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js b/ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js new file mode 100644 index 0000000000..5d741e1a2b --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js @@ -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 \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js.map b/ng2-components/ng2-alfresco-upload/ng2-alfresco-upload.js.map new file mode 100644 index 0000000000..d067363b0e --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/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"} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/src/assets/AlfrescoApi.mock.ts b/ng2-components/ng2-alfresco-upload/src/assets/AlfrescoApi.mock.ts new file mode 100644 index 0000000000..3c09f32923 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/src/assets/AlfrescoApi.mock.ts @@ -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 + } + } + } + }); + }); + } + } + + } + +} diff --git a/ng2-components/ng2-alfresco-upload/src/assets/translation.service.mock.ts b/ng2-components/ng2-alfresco-upload/src/assets/translation.service.mock.ts index b28942f5d0..3ddf9a9050 100644 --- a/ng2-components/ng2-alfresco-upload/src/assets/translation.service.mock.ts +++ b/ng2-components/ng2-alfresco-upload/src/assets/translation.service.mock.ts @@ -27,22 +27,11 @@ export class TranslationMock { public onLangChange: EventEmitter = new EventEmitter(); - setDefaultLang() { - console.log('mock'); - } - - use() { - console.log('mock'); - } - addTranslationFolder() { } public get(key: string|Array, interpolateParams?: Object): Observable { - if (!key) { - throw new Error('Parameter "key" required'); - } return Observable.of(key); } } diff --git a/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts b/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts index 700b3ed82b..9466baa39d 100644 --- a/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts +++ b/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts @@ -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; + totalCompleted$: Observable; + 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; + 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 { + }; + + + } diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.html b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.html index 2e394bdbd2..2c6982cb07 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.html +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.html @@ -1,7 +1,7 @@
- {{totalCompleted}} {{'FILE_UPLOAD.MESSAGES.COMPLETED' | translate}} + {{totalCompleted}} {{'FILE_UPLOAD.MESSAGES.COMPLETED' | translate}}
diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts index 92535da31a..e2e3c586f0 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts @@ -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,27 +36,150 @@ 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) => { - 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]; + 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}; - let compiled = fixture.debugElement.nativeElement; - component.showDialog(); - fixture.detectChanges(); + updService.totalCompleted$ = new Observable(observer => { + observer.next(1); + }); - expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show'); - }); - })); + 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) => { + 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.toggleShowDialog(); + fixture.detectChanges(); + + 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'); + }); + })); }); diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts index 8fb22dcb28..562332e7f2 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts @@ -60,17 +60,21 @@ export class FileUploadingDialogComponent implements OnInit{ } ngOnInit() { - this._uploaderService.filesUpload$.subscribe((fileList: FileModel[]) => { - this.filesUploadingList = fileList; - if (this.filesUploadingList.length > 0) { - this.isDialogActive = true; + if(this._uploaderService.filesUpload$) { + this._uploaderService.filesUpload$.subscribe((fileList: FileModel[]) => { + this.filesUploadingList = fileList; + if (this.filesUploadingList.length > 0) { + this.isDialogActive = true; + this.cd.detectChanges(); + } + }); + } + if(this._uploaderService.totalCompleted$) { + this._uploaderService.totalCompleted$.subscribe((total: number) => { + this.totalCompleted = total; this.cd.detectChanges(); - } - }); - this._uploaderService.totalCompleted$.subscribe((total: number) => { - this.totalCompleted = total; - this.cd.detectChanges(); - }); + }); + } } /** diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index b78c52f559..296f73d0ee 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -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) => { - return tcb - .createAsync(UploadButtonComponent) - .then((fixture) => { - let component = fixture.componentInstance; - fixture.detectChanges(); - let compiled = fixture.debugElement.nativeElement; + it('should create a folder and call upload file', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { + return tcb + .createAsync(UploadButtonComponent) + .then((fixture) => { + let component = fixture.componentInstance; + + component.uploadFiles = jasmine.createSpy('uploadFiles'); + let doneFn = jasmine.createSpy('success'); + + fixture.detectChanges(); + + 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); + }); + })); - component._showDialog(); - fixture.detectChanges(); - expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show'); - }); - })); }); - diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts index 6d8378129e..3cbaf0ccde 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts @@ -135,9 +135,11 @@ export class UploadButtonComponent { }, error => { let errorMessagePlaceholder = this.getErrorMessage(error.response); - let errorMessage = this.formatString(errorMessagePlaceholder, [directoryName]); - if (errorMessage) { - this._showErrorNotificationBar(errorMessage); + if (errorMessagePlaceholder) { + let errorMessage = this.formatString(errorMessagePlaceholder, [directoryName]); + if (errorMessage) { + this._showErrorNotificationBar(errorMessage); + } } console.log(error); } @@ -222,16 +224,18 @@ export class UploadButtonComponent { messageTranslate = this.translate.get('FILE_UPLOAD.MESSAGES.PROGRESS'); actionTranslate = this.translate.get('FILE_UPLOAD.ACTION.UNDO'); - this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ - message: messageTranslate.value, - timeout: 3000, - actionHandler: function () { - latestFilesAdded.forEach((uploadingFileModel: FileModel) => { - uploadingFileModel.setAbort(); - }); - }, - actionText: actionTranslate.value - }); + if(this.undoNotificationBar.nativeElement.MaterialSnackbar) { + this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ + message: messageTranslate.value, + timeout: 3000, + actionHandler: function () { + latestFilesAdded.forEach((uploadingFileModel: FileModel) => { + uploadingFileModel.setAbort(); + }); + }, + actionText: actionTranslate.value + }); + } } /** @@ -257,10 +261,12 @@ export class UploadButtonComponent { componentHandler.upgradeAllRegistered(); } - this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ - message: errorMessage, - timeout: 3000 - }); + if (this.undoNotificationBar.nativeElement.MaterialSnackbar) { + this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ + message: errorMessage, + timeout: 3000 + }); + } } /** diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index fda3163482..0ce10389e0 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -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; @@ -56,6 +60,7 @@ describe('AlfrescoUploadService', () => { beforeEach(() => { jasmine.Ajax.install(); + window['AlfrescoApi'] = AlfrescoApiMock; service = new MockUploadService(options); }); @@ -160,4 +165,43 @@ 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(); + } + ); + }); }); diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts index b88c314a33..01df09f10d 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -43,7 +43,7 @@ export class UploadService { private _queue: FileModel[] = []; filesUpload$: Observable; - totalCompleted$: Observable; + totalCompleted$: Observable; private _filesUploadObserver: Observer; private _totalCompletedObserver: Observer; @@ -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): 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); From abfe5932ff71780f5f56f03218bf2194d6d52f00 Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Wed, 15 Jun 2016 15:02:42 +0100 Subject: [PATCH 2/2] Add xmlHttpReq test --- .../src/services/upload.service.spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index 0ce10389e0..c23d6c7fe1 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -46,6 +46,7 @@ class MockUploadService extends UploadService { describe('AlfrescoUploadService', () => { let service: MockUploadService, + serviceUpload: UploadService, options: any; options = { @@ -62,6 +63,7 @@ describe('AlfrescoUploadService', () => { jasmine.Ajax.install(); window['AlfrescoApi'] = AlfrescoApiMock; service = new MockUploadService(options); + serviceUpload = new UploadService(options); }); afterEach(() => { @@ -204,4 +206,16 @@ describe('AlfrescoUploadService', () => { } ); }); + + 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(); + }); });