From 4745cb931bdaac9100fb832a5e564e28bbe4fd37 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Tue, 4 Oct 2016 15:38:30 +0100 Subject: [PATCH] fix test angular2 Finale release tag component #749 --- .../ng2-alfresco-tag/karma-test-shim.js | 24 +---- ng2-components/ng2-alfresco-tag/karma.conf.js | 11 +-- ng2-components/ng2-alfresco-tag/package.json | 12 +-- .../components/tag-actions.component.spec.ts | 87 +++++++++++-------- .../src/components/tag-actions.component.ts | 3 +- .../src/components/tag-list.component.spec.ts | 70 ++++++++------- .../src/components/tag-list.component.ts | 3 +- .../tag-node-list.component.spec.ts | 68 +++++++++------ .../src/components/tag-node-list.component.ts | 3 +- .../src/services/tag.service.spec.ts | 30 ++++--- ng2-components/ng2-alfresco-tag/tsconfig.json | 4 +- 11 files changed, 163 insertions(+), 152 deletions(-) diff --git a/ng2-components/ng2-alfresco-tag/karma-test-shim.js b/ng2-components/ng2-alfresco-tag/karma-test-shim.js index 9662cebf0a..6d41e195b3 100644 --- a/ng2-components/ng2-alfresco-tag/karma-test-shim.js +++ b/ng2-components/ng2-alfresco-tag/karma-test-shim.js @@ -54,18 +54,8 @@ var map = { 'ng2-translate': 'npm:ng2-translate', 'alfresco-js-api': 'npm:alfresco-js-api/dist', - 'ng2-activiti-form': 'npm:ng2-activiti-form/dist', - 'ng2-activiti-processlist': 'npm:ng2-activiti-processlist/dist', - 'ng2-activiti-tasklist': 'npm:ng2-activiti-tasklist/dist', 'ng2-alfresco-core': 'npm:ng2-alfresco-core/dist', - 'ng2-alfresco-datatable': 'npm:ng2-alfresco-datatable/dist', - 'ng2-alfresco-documentlist': 'npm:ng2-alfresco-documentlist/dist', - 'ng2-alfresco-login': 'npm:ng2-alfresco-login/dist', - 'ng2-alfresco-search': 'npm:ng2-alfresco-search/dist', - 'ng2-alfresco-tag': 'npm:ng2-alfresco-tag/dist', - 'ng2-alfresco-upload': 'npm:ng2-alfresco-upload/dist', - 'ng2-alfresco-viewer': 'npm:ng2-alfresco-viewer/dist', - 'ng2-alfresco-webscript': 'npm:ng2-alfresco-webscript/dist' + 'ng2-alfresco-tag': 'npm:ng2-alfresco-tag/dist' }; var packages = { @@ -74,18 +64,8 @@ var packages = { 'ng2-translate': { defaultExtension: 'js' }, 'alfresco-js-api': { main: './alfresco-js-api.js', defaultExtension: 'js'}, - 'ng2-activiti-form': { main: './index.js', defaultExtension: 'js'}, - 'ng2-activiti-processlist': { main: './index.js', defaultExtension: 'js'}, - 'ng2-activiti-tasklist': { main: './index.js', defaultExtension: 'js'}, 'ng2-alfresco-core': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-datatable': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-documentlist': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-login': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-search': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-tag': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-upload': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-viewer': { main: './index.js', defaultExtension: 'js'}, - 'ng2-alfresco-webscript': { main: './index.js', defaultExtension: 'js'} + 'ng2-alfresco-tag': { main: './index.js', defaultExtension: 'js'} }; var config = { diff --git a/ng2-components/ng2-alfresco-tag/karma.conf.js b/ng2-components/ng2-alfresco-tag/karma.conf.js index f6004cd36b..f2041beb56 100644 --- a/ng2-components/ng2-alfresco-tag/karma.conf.js +++ b/ng2-components/ng2-alfresco-tag/karma.conf.js @@ -44,18 +44,9 @@ module.exports = function (config) { {pattern: 'dist/**/*.css', included: true, served: true, watched: true}, // ng2-components - { pattern: 'node_modules/ng2-activiti-form/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-activiti-processlist/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-activiti-tasklist/dist/**/*.js', included: false, served: true, watched: false }, { pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-alfresco-documentlist/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-alfresco-login/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-alfresco-search/dist/**/*.js', included: false, served: true, watched: false }, + { pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js.map', included: false, served: true, watched: false }, { pattern: 'node_modules/ng2-alfresco-tag/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-alfresco-upload/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-alfresco-viewer/dist/**/*.js', included: false, served: true, watched: false }, - { pattern: 'node_modules/ng2-alfresco-webscript/dist/**/*.js', included: false, served: true, watched: false }, // paths to support debugging with source maps in dev tools {pattern: 'src/**/*.ts', included: false, watched: false}, diff --git a/ng2-components/ng2-alfresco-tag/package.json b/ng2-components/ng2-alfresco-tag/package.json index b4e3296af3..70e9252f1d 100644 --- a/ng2-components/ng2-alfresco-tag/package.json +++ b/ng2-components/ng2-alfresco-tag/package.json @@ -40,15 +40,15 @@ "@angular/platform-browser-dynamic": "2.0.0", "@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", - - "alfresco-js-api": "^0.3.0", - "ng2-translate": "2.5.0", - "ng2-alfresco-core": "0.3.2" + "zone.js": "^0.6.23" }, "devDependencies": { "@types/core-js": "^0.9.32", @@ -78,7 +78,7 @@ ], "license-check-config": { "src": [ - "./dist/**/*.js" + "./dist/**/*.js" ], "path": "assets/license_header.txt", "blocking": false, diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts index 6344804116..df46e40240 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts @@ -15,18 +15,50 @@ * limitations under the License. */ -/* -import { it, describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { TagActionsComponent } from '../components/tag-actions.component'; +import { DebugElement } from '@angular/core'; +import { + AlfrescoAuthenticationService, + AlfrescoSettingsService, + AlfrescoApiService, + CoreModule +} from 'ng2-alfresco-core'; import { TagService } from '../services/tag.service'; -import { TagActionsComponent } from './tag-actions.component'; declare let jasmine: any; -describe('Tag actions list', () => { +describe('Test ng2-alfresco-tag Tag actions list', () => { - let tagActionsListFixture, element, component; + let component: any; + let fixture: ComponentFixture; + let debug: DebugElement; + let element: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + CoreModule + ], + declarations: [TagActionsComponent], + providers: [ + AlfrescoSettingsService, + AlfrescoAuthenticationService, + AlfrescoApiService, + TagService + ] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TagActionsComponent); + component = fixture.componentInstance; + + debug = fixture.debugElement; + element = fixture.nativeElement; + component = fixture.componentInstance; + fixture.detectChanges(); + }); let dataTag = { 'list': { @@ -45,25 +77,6 @@ describe('Tag actions list', () => { } }; - beforeEachProviders(() => { - return [ - AlfrescoSettingsService, - AlfrescoAuthenticationService, - AlfrescoApiService, - TagService - ]; - }); - - beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - return tcb - .createAsync(TagActionsComponent) - .then(fixture => { - tagActionsListFixture = fixture; - element = tagActionsListFixture.nativeElement; - component = tagActionsListFixture.componentInstance; - }); - })); - describe('Rendering tests', () => { beforeEach(() => { @@ -78,7 +91,7 @@ describe('Tag actions list', () => { component.nodeId = 'fake-node-id'; component.resultsEmitter.subscribe(() => { - tagActionsListFixture.detectChanges(); + fixture.detectChanges(); expect(element.querySelector('#tag_name_0').innerHTML).toBe('test1'); expect(element.querySelector('#tag_name_1').innerHTML).toBe('test2'); @@ -104,12 +117,15 @@ describe('Tag actions list', () => { component.nodeId = 'fake-node-id'; component.resultsEmitter.subscribe(() => { - tagActionsListFixture.detectChanges(); - element.querySelector('#tag_delete_0').click(); - tagActionsListFixture.detectChanges(); + fixture.detectChanges(); - expect(jasmine.Ajax.requests.at(1).url). - toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/0ee933fa-57fc-4587-8a77-b787e814f1d2'); + let deleteButton: any = element.querySelector('#tag_delete_0'); + deleteButton.click(); + + fixture.detectChanges(); + + expect(jasmine.Ajax.requests.at(1).url) + .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/0ee933fa-57fc-4587-8a77-b787e814f1d2'); expect(jasmine.Ajax.requests.at(1).method).toBe('DELETE'); done(); }); @@ -127,13 +143,14 @@ describe('Tag actions list', () => { component.nodeId = 'fake-node-id'; component.newTagName = 'fake-tag-name'; - tagActionsListFixture.detectChanges(); + fixture.detectChanges(); component.addEmitter.subscribe(() => { done(); }); - element.querySelector('#add-tag').click(); + let addButton: any = element.querySelector('#add-tag'); + addButton.click(); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 @@ -141,4 +158,4 @@ describe('Tag actions list', () => { }); }); }); -*/ + diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts index 6022b9d651..d5fad0c9a8 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts @@ -25,10 +25,9 @@ import { TagService } from '../services/tag.service'; * * @returns {TagComponent} . */ -declare let __moduleName: string; @Component({ - moduleId: __moduleName, + moduleId: module.id, selector: 'alfresco-tag-node-actions-list', templateUrl: './tag-actions.component.html', styleUrls: ['./tag-actions.component.css'] diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts index 6ec679a824..842b2b397d 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts @@ -15,24 +15,21 @@ * limitations under the License. */ -describe('TagList', () => { - it('should be upgraded', () => { - expect(true).toBe(true); - }); -}); -/* -import { it, describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { TagList } from '../components/tag-list.component'; +import { DebugElement } from '@angular/core'; +import { + AlfrescoAuthenticationService, + AlfrescoSettingsService, + AlfrescoApiService, + CoreModule +} from 'ng2-alfresco-core'; import { TagService } from '../services/tag.service'; -import { TagList } from './tag-list.component'; declare let jasmine: any; -describe('Tag list All ECM', () => { - - let tagListFixture, element, component; +describe('Test ng2-alfresco-tag Tag list All ECM', () => { let dataTag = { 'list': { @@ -50,24 +47,36 @@ describe('Tag list All ECM', () => { } }; - beforeEachProviders(() => { - return [ - AlfrescoSettingsService, - AlfrescoAuthenticationService, - AlfrescoApiService, - TagService - ]; + let component: any; + let fixture: ComponentFixture; + let debug: DebugElement; + let element: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + CoreModule + ], + declarations: [TagList], + providers: [ + AlfrescoSettingsService, + AlfrescoAuthenticationService, + AlfrescoApiService, + TagService + ] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TagList); + component = fixture.componentInstance; + + debug = fixture.debugElement; + element = fixture.nativeElement; + component = fixture.componentInstance; + fixture.detectChanges(); }); - beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - return tcb - .createAsync(TagList) - .then(fixture => { - tagListFixture = fixture; - element = tagListFixture.nativeElement; - component = tagListFixture.componentInstance; - }); - })); describe('Rendering tests', () => { @@ -83,7 +92,7 @@ describe('Tag list All ECM', () => { component.nodeId = 'fake-node-id'; component.resultsEmitter.subscribe(() => { - tagListFixture.detectChanges(); + fixture.detectChanges(); expect(element.querySelector('#tag_name_0').innerHTML).toBe('test1'); expect(element.querySelector('#tag_name_1').innerHTML).toBe('test2'); @@ -102,4 +111,3 @@ describe('Tag list All ECM', () => { }); }); }); -*/ diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts index 3613520825..5b43004127 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts @@ -25,10 +25,9 @@ import { TagService } from '../services/tag.service'; * * @returns {TagList} . */ -declare let __moduleName: string; @Component({ - moduleId: __moduleName, + moduleId: module.id, selector: 'alfresco-tag-list', templateUrl: './tag-list.component.html' }) diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts index 9199f2695b..344930c13a 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts @@ -15,18 +15,21 @@ * limitations under the License. */ -/* -import { it, describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { TagNodeList } from '../components/tag-node-list.component'; +import { DebugElement } from '@angular/core'; +import { + AlfrescoAuthenticationService, + AlfrescoSettingsService, + AlfrescoApiService, + CoreModule +} from 'ng2-alfresco-core'; import { TagService } from '../services/tag.service'; -import { TagNodeList } from './tag-node-list.component'; declare let jasmine: any; describe('Tag relative node list', () => { - let tagNodeListFixture, element, component; let dataTag = { 'list': { @@ -44,25 +47,36 @@ describe('Tag relative node list', () => { } }; - beforeEachProviders(() => { - return [ - AlfrescoSettingsService, - AlfrescoAuthenticationService, - AlfrescoApiService, - TagService - ]; - }); + let component: any; + let fixture: ComponentFixture; + let debug: DebugElement; + let element: HTMLElement; - beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - return tcb - .createAsync(TagNodeList) - .then(fixture => { - tagNodeListFixture = fixture; - element = tagNodeListFixture.nativeElement; - component = tagNodeListFixture.componentInstance; - }); + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + CoreModule + ], + declarations: [TagNodeList], + providers: [ + AlfrescoSettingsService, + AlfrescoAuthenticationService, + AlfrescoApiService, + TagService + ] + }).compileComponents(); })); + beforeEach(() => { + fixture = TestBed.createComponent(TagNodeList); + component = fixture.componentInstance; + + debug = fixture.debugElement; + element = fixture.nativeElement; + component = fixture.componentInstance; + fixture.detectChanges(); + }); + describe('Rendering tests', () => { beforeEach(() => { @@ -77,7 +91,7 @@ describe('Tag relative node list', () => { component.nodeId = 'fake-node-id'; component.resultsEmitter.subscribe(() => { - tagNodeListFixture.detectChanges(); + fixture.detectChanges(); expect(element.querySelector('#tag_name_0').innerHTML).toBe('test1'); expect(element.querySelector('#tag_name_1').innerHTML).toBe('test2'); @@ -103,8 +117,10 @@ describe('Tag relative node list', () => { component.nodeId = 'fake-node-id'; component.resultsEmitter.subscribe(() => { - tagNodeListFixture.detectChanges(); - element.querySelector('#tag_delete_0').click(); + fixture.detectChanges(); + + let deleteButton: any = element.querySelector('#tag_delete_0'); + deleteButton.click(); expect(jasmine.Ajax.requests.mostRecent().url). toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/0ee933fa-57fc-4587-8a77-b787e814f1d2'); @@ -122,4 +138,4 @@ describe('Tag relative node list', () => { }); }); }); -*/ + diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts index fdcb68a45a..a76eb8554e 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts @@ -25,10 +25,9 @@ import { TagService } from '../services/tag.service'; * * @returns {TagNodeList} . */ -declare let __moduleName: string; @Component({ - moduleId: __moduleName, + moduleId: module.id, selector: 'alfresco-tag-node-list', templateUrl: './tag-node-list.component.html', styleUrls: ['./tag-node-list.component.css'] diff --git a/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts b/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts index b7e40a15a4..637d568e98 100644 --- a/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts @@ -15,30 +15,32 @@ * limitations under the License. */ -/* -import { describe, expect, it, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; -import { TagService } from './tag.service'; +import { ReflectiveInjector } from '@angular/core'; +import { + AlfrescoAuthenticationService, + AlfrescoSettingsService, + AlfrescoApiService +} from 'ng2-alfresco-core'; +import { TagService } from '../services/tag.service'; declare let jasmine: any; describe('Tag service', () => { - let service; + let service, injector; - beforeEachProviders(() => { - - return [ + beforeEach(() => { + injector = ReflectiveInjector.resolveAndCreate([ AlfrescoSettingsService, - AlfrescoAuthenticationService, AlfrescoApiService, + AlfrescoAuthenticationService, TagService - ]; + ]); }); - beforeEach(inject([TagService], (tagService: TagService) => { - service = tagService; - })); + beforeEach(() => { + service = injector.get(TagService); + }); describe('Content tests', () => { @@ -114,4 +116,4 @@ describe('Tag service', () => { }); }); }); -*/ + diff --git a/ng2-components/ng2-alfresco-tag/tsconfig.json b/ng2-components/ng2-alfresco-tag/tsconfig.json index ae39a67a17..c586e1848e 100644 --- a/ng2-components/ng2-alfresco-tag/tsconfig.json +++ b/ng2-components/ng2-alfresco-tag/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es5", - "module": "system", + "module": "commonjs", "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, @@ -16,7 +16,7 @@ "noImplicitUseStrict": false, "noFallthroughCasesInSwitch": true, "outDir": "dist", - "types": ["core-js", "jasmine"] + "types": ["core-js", "jasmine", "node"] }, "exclude": [ "demo",