From a48326098628e227718d9bbed0d40eadb4027579 Mon Sep 17 00:00:00 2001 From: Michel Felipe de Oliveira Ferreira Date: Thu, 3 Mar 2016 15:20:57 -0300 Subject: [PATCH] Migrate MainBlock Component to ngForward --- src/app/components/noosfero-blocks/main-block/main-block.component.js | 20 -------------------- src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts | 40 ++++++++++++++++++++++++++++++++++++++++ src/app/components/noosfero-blocks/main-block/main-block.component.ts | 10 ++++++++++ src/app/index.ts | 1 - src/app/main/main.component.ts | 4 +++- 5 files changed, 53 insertions(+), 22 deletions(-) delete mode 100644 src/app/components/noosfero-blocks/main-block/main-block.component.js create mode 100644 src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts create mode 100644 src/app/components/noosfero-blocks/main-block/main-block.component.ts diff --git a/src/app/components/noosfero-blocks/main-block/main-block.component.js b/src/app/components/noosfero-blocks/main-block/main-block.component.js deleted file mode 100644 index 30c6943..0000000 --- a/src/app/components/noosfero-blocks/main-block/main-block.component.js +++ /dev/null @@ -1,20 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('noosferoApp') - .component('noosferoMainBlock', { - restrict: 'E', - templateUrl: 'app/components/noosfero-blocks/main-block/main-block.html', - bindings: { - block: '<', - owner: '<' - }, - controller: MainBlockController - }); - - /** @ngInject */ - function MainBlockController() { - } - -})(); diff --git a/src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts b/src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts new file mode 100644 index 0000000..356168f --- /dev/null +++ b/src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts @@ -0,0 +1,40 @@ +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Input, provide, Component, StateConfig} from 'ng-forward'; + +import {MainBlock} from './main-block.component'; +import {NoosferoApp} from '../../../index.module'; + +const tcb = new TestComponentBuilder(); + +const htmlTemplate: string = ''; + + +describe("Main Block Component", () => { + + // the karma preprocessor html2js transform the templates html into js files which put + // the templates to the templateCache into the module templates + // we need to load the module templates here as the template for the + // component Block will be load on our tests + beforeEach(angular.mock.module("templates")); + + it("check if the main block has a tag with ui-view attribute", done => { + + // Creating a container component (BlockContainerComponent) to include + // the component under test (Block) + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [MainBlock] }) + class BlockContainerComponent { + } + + // uses the TestComponentBuilder instance to initialize the component + tcb.createAsync(BlockContainerComponent).then(fixture => { + // and here we can inspect and run the test assertions + //let myComponent: MainBlock = fixture.componentInstance; + + // assure the block object inside the Block matches + // the provided through the parent component + expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1) + done(); + }); + }); + +}); diff --git a/src/app/components/noosfero-blocks/main-block/main-block.component.ts b/src/app/components/noosfero-blocks/main-block/main-block.component.ts new file mode 100644 index 0000000..d9831a0 --- /dev/null +++ b/src/app/components/noosfero-blocks/main-block/main-block.component.ts @@ -0,0 +1,10 @@ +import {Component, Input} from 'ng-forward' +import {Block} from '../block.component'; + +@Component({ + selector: 'noosfero-main-block', + templateUrl: 'app/components/noosfero-blocks/main-block/main-block.html' +}) +export class MainBlock { + +} diff --git a/src/app/index.ts b/src/app/index.ts index b3c5d62..1c87889 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -44,7 +44,6 @@ NoosferoApp.addController("AuthController", AuthController); require("./components/navbar/navbar.directive.js"); require("./components/noosfero-activities/activities.component.js"); require("./components/noosfero-activities/activity/activity.component.js"); -require("./components/noosfero-blocks/main-block/main-block.component.js"); require("./components/noosfero-blocks/members-block/members-block.component.js"); require("./components/noosfero-blocks/profile-image/profile-image.component.js"); require("./components/noosfero-blocks/recent-documents/recent-documents.component.js"); diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 8f610ba..cd4f149 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -12,6 +12,8 @@ import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.c import {AuthService} from "./../components/auth/auth_service"; import {Session} from "./../components/auth/session"; +import {MainBlock} from "../components/noosfero-blocks/main-block/main-block.component"; + @Component({ selector: 'main-content', templateUrl: "app/main/main.html", @@ -24,7 +26,7 @@ export class MainContent { @Component({ selector: 'main', template: '
', - directives: [NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock], + directives: [NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, MainBlock], providers: [AuthService, Session] }) @StateConfig([ -- libgit2 0.21.2