Commit a48326098628e227718d9bbed0d40eadb4027579

Authored by Michel Felipe
1 parent 0da8c631

Migrate MainBlock Component to ngForward

src/app/components/noosfero-blocks/main-block/main-block.component.js
... ... @@ -1,20 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular
5   - .module('noosferoApp')
6   - .component('noosferoMainBlock', {
7   - restrict: 'E',
8   - templateUrl: 'app/components/noosfero-blocks/main-block/main-block.html',
9   - bindings: {
10   - block: '<',
11   - owner: '<'
12   - },
13   - controller: MainBlockController
14   - });
15   -
16   - /** @ngInject */
17   - function MainBlockController() {
18   - }
19   -
20   -})();
src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
  2 +import {Input, provide, Component, StateConfig} from 'ng-forward';
  3 +
  4 +import {MainBlock} from './main-block.component';
  5 +import {NoosferoApp} from '../../../index.module';
  6 +
  7 +const tcb = new TestComponentBuilder();
  8 +
  9 +const htmlTemplate: string = '<noosfero-main-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-main-block>';
  10 +
  11 +
  12 +describe("Main Block Component", () => {
  13 +
  14 + // the karma preprocessor html2js transform the templates html into js files which put
  15 + // the templates to the templateCache into the module templates
  16 + // we need to load the module templates here as the template for the
  17 + // component Block will be load on our tests
  18 + beforeEach(angular.mock.module("templates"));
  19 +
  20 + it("check if the main block has a tag with ui-view attribute", done => {
  21 +
  22 + // Creating a container component (BlockContainerComponent) to include
  23 + // the component under test (Block)
  24 + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [MainBlock] })
  25 + class BlockContainerComponent {
  26 + }
  27 +
  28 + // uses the TestComponentBuilder instance to initialize the component
  29 + tcb.createAsync(BlockContainerComponent).then(fixture => {
  30 + // and here we can inspect and run the test assertions
  31 + //let myComponent: MainBlock = fixture.componentInstance;
  32 +
  33 + // assure the block object inside the Block matches
  34 + // the provided through the parent component
  35 + expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1)
  36 + done();
  37 + });
  38 + });
  39 +
  40 +});
... ...
src/app/components/noosfero-blocks/main-block/main-block.component.ts 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +import {Component, Input} from 'ng-forward'
  2 +import {Block} from '../block.component';
  3 +
  4 +@Component({
  5 + selector: 'noosfero-main-block',
  6 + templateUrl: 'app/components/noosfero-blocks/main-block/main-block.html'
  7 +})
  8 +export class MainBlock {
  9 +
  10 +}
... ...
src/app/index.ts
... ... @@ -44,7 +44,6 @@ NoosferoApp.addController(&quot;AuthController&quot;, AuthController);
44 44 require("./components/navbar/navbar.directive.js");
45 45 require("./components/noosfero-activities/activities.component.js");
46 46 require("./components/noosfero-activities/activity/activity.component.js");
47   -require("./components/noosfero-blocks/main-block/main-block.component.js");
48 47 require("./components/noosfero-blocks/members-block/members-block.component.js");
49 48 require("./components/noosfero-blocks/profile-image/profile-image.component.js");
50 49 require("./components/noosfero-blocks/recent-documents/recent-documents.component.js");
... ...
src/app/main/main.component.ts
... ... @@ -12,6 +12,8 @@ import {LinkListBlock} from &quot;../components/noosfero-blocks/link-list/link-list.c
12 12 import {AuthService} from "./../components/auth/auth_service";
13 13 import {Session} from "./../components/auth/session";
14 14  
  15 +import {MainBlock} from "../components/noosfero-blocks/main-block/main-block.component";
  16 +
15 17 @Component({
16 18 selector: 'main-content',
17 19 templateUrl: "app/main/main.html",
... ... @@ -24,7 +26,7 @@ export class MainContent {
24 26 @Component({
25 27 selector: 'main',
26 28 template: '<div ng-view></div>',
27   - directives: [NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock],
  29 + directives: [NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, MainBlock],
28 30 providers: [AuthService, Session]
29 31 })
30 32 @StateConfig([
... ...