diff --git a/ng2-components/ng2-alfresco-upload/package.json b/ng2-components/ng2-alfresco-upload/package.json index 29cd07eeb6..92651777f6 100644 --- a/ng2-components/ng2-alfresco-upload/package.json +++ b/ng2-components/ng2-alfresco-upload/package.json @@ -9,7 +9,8 @@ "tsc": "tsc", "tsc:w": "tsc -w", "typings": "typings", - "test": "live-server --open=index.html --entry-file=test/ " + "test": "live-server --open=index.html --entry-file=test/ ", + "test:w": "concurrently \"npm run tsc:w\" \"npm run test\" " }, "repository": { "type": "git", @@ -51,7 +52,8 @@ "live-server": "^0.9.2", "tslint": "^3.8.1", "typescript": "^1.8.10", - "typings": "^0.7.12" + "typings": "^0.7.12", + "concurrently": "^2.0.0" }, "license-check-config": { "src": [ diff --git a/ng2-components/ng2-alfresco-upload/test/assets/translation.service.mock.ts b/ng2-components/ng2-alfresco-upload/test/assets/translation.service.mock.ts new file mode 100644 index 0000000000..35ada2db31 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/test/assets/translation.service.mock.ts @@ -0,0 +1,40 @@ +/** + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {Observable} from 'rxjs/Observable'; +import {provide, EventEmitter} from 'angular2/core'; +import {LangChangeEvent} from 'ng2-translate/ng2-translate'; + + +export class TranslationMock { + + public onLangChange: EventEmitter = new EventEmitter(); + + setDefaultLang() { + + } + + use() { + } + + public get(key: string|Array, interpolateParams?: Object): Observable { + if (!key) { + throw new Error('Parameter "key" required'); + } + return Observable.of(key); + } +} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/test/components/file-uploading-dialog.component.spec.ts b/ng2-components/ng2-alfresco-upload/test/components/file-uploading-dialog.component.spec.ts new file mode 100644 index 0000000000..0b50e12d55 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/test/components/file-uploading-dialog.component.spec.ts @@ -0,0 +1,43 @@ +/** + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import {TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS} from 'angular2/platform/testing/browser'; +import {it, describe, expect, injectAsync, TestComponentBuilder, setBaseTestProviders} from 'angular2/testing'; +import {Component} from 'angular2/core'; +import {FileUploadingDialogComponent} from '../../../src/components/file-uploading-dialog.component'; + +describe('FileUploadDialog', () => { + + //setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS); + + it('should render dialog box with css class show', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + return tcb + .createAsync(FileUploadingDialogComponent) + .then((fixture) => { + let component = fixture.componentInstance; + fixture.detectChanges(); + + let compiled = fixture.debugElement.nativeElement; + component._showDialog(); + fixture.detectChanges(); + + expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show'); + }); + })); +}); + diff --git a/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts index 2f7d9057ee..d86d9e3d02 100644 --- a/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts @@ -17,14 +17,22 @@ import {TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS} from 'angular2/platform/testing/browser'; -import {it, describe, expect, injectAsync, TestComponentBuilder, setBaseTestProviders} from 'angular2/testing'; +import {it, describe, expect, injectAsync, beforeEachProviders, TestComponentBuilder, setBaseTestProviders} from 'angular2/testing'; import {Component, provide, Injector} from 'angular2/core'; import {UploadButtonComponent} from '../../../src/components/upload-button.component'; +import {TranslateService, LangChangeEvent} from 'ng2-translate/ng2-translate'; +import {TranslationMock} from '../assets/translation.service.mock'; describe('AlfrescoUploadButton', () => { setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS); + beforeEachProviders(() => { + return [ + provide(TranslateService, {useClass: TranslationMock}) + ]; + }); + it('should render upload-single-file button as default', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { return tcb .createAsync(UploadButtonComponent) diff --git a/ng2-components/ng2-alfresco-upload/test/index.html b/ng2-components/ng2-alfresco-upload/test/index.html index 33f43a9724..75c6315b4b 100644 --- a/ng2-components/ng2-alfresco-upload/test/index.html +++ b/ng2-components/ng2-alfresco-upload/test/index.html @@ -29,7 +29,17 @@ System.config({ packages: { 'test': {defaultExtension: 'js'}, - 'src': {defaultExtension: 'js'} + 'src': {defaultExtension: 'js'}, + 'ng2-translate': { + defaultExtension: 'js' + }, + 'rxjs': { + defaultExtension: 'js' + } + }, + map: { + 'ng2-translate': '../node_modules/ng2-translate', + 'rxjs': '../node_modules/rxjs' } }); diff --git a/ng2-components/ng2-alfresco-upload/test/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/test/services/upload.service.spec.ts index bd24df0ffa..a2eb311813 100644 --- a/ng2-components/ng2-alfresco-upload/test/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/test/services/upload.service.spec.ts @@ -67,14 +67,12 @@ describe('AlfrescoUploadService', () => { }); it('should add an element in the queue and returns it', () => { - service.setXMLHttpRequest(xhr); 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.setXMLHttpRequest(xhr); let filesFake = [{name: 'fake-name', size: 10}, {name: 'fake-name2', size: 20} ]; service.addToQueue(filesFake); expect(service.getQueue().length).toEqual(2); @@ -84,7 +82,7 @@ describe('AlfrescoUploadService', () => { service.setXMLHttpRequest(xhr); let filesFake = [{name: 'fake-name', size: 10}]; service.addToQueue(filesFake); - + service.uploadFilesInTheQueue(''); expect(jasmine.Ajax.requests.mostRecent().url).toBe('/some/cool/url'); expect(doneFn).not.toHaveBeenCalled(); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -99,7 +97,7 @@ describe('AlfrescoUploadService', () => { service.setXMLHttpRequest(xhr); let filesFake = [{name: 'fake-name', size: 10}]; service.addToQueue(filesFake); - + service.uploadFilesInTheQueue(''); expect(jasmine.Ajax.requests.mostRecent().url).toBe('/some/cool/url'); expect(doneFn).not.toHaveBeenCalled(); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -114,6 +112,7 @@ describe('AlfrescoUploadService', () => { service.setXMLHttpRequest(xhr); let filesFake = [{name: 'fake-name', size: 10}]; service.addToQueue(filesFake); + service.uploadFilesInTheQueue(''); let file = service.getQueue(); file[0].setAbort(); expect(xhr.abort).toHaveBeenCalled();