diff --git a/src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts b/src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts new file mode 100644 index 0000000..d1395d7 --- /dev/null +++ b/src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts @@ -0,0 +1,64 @@ +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Pipe, Input, provide, Component} from 'ng-forward'; + +import {LinkListBlock} from './link-list.component'; + +const tcb = new TestComponentBuilder(); + +const htmlTemplate: string = ''; + + +describe("Link List Block Component", () => { + + beforeEach(angular.mock.module("templates")); + + it("receives the block and the owner as inputs", done => { + + // Creating a container component (BlockContainerComponent) to include + // the component under test (Block) + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [LinkListBlock] }) + class BlockContainerComponent { + block = { type: 'Block' }; + owner = { name: 'profile-name' }; + constructor() { + } + } + + // uses the TestComponentBuilder instance to initialize the component + //.overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] }) + tcb.createAsync(BlockContainerComponent).then(fixture => { + // and here we can inspect and run the test assertions + let myComponent: LinkListBlock = fixture.componentInstance; + + // assure the block object inside the Block matches + // the provided through the parent component + expect(myComponent.block.type).toEqual("Block"); + expect(myComponent.owner.name).toEqual("profile-name"); + done(); + }); + }); + + + it("display links stored in block settings", done => { + + @Pipe('noosferoTemplateFilter') + class NoosferoTemplateFilter { + transform(input: any, changeTo: any) { + return input; + } + } + + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [LinkListBlock] }) + class CustomBlockType { + block: any = { settings: { links: [{ name: 'link1', address: 'address1' }, { name: 'link2', address: 'address2' }] } }; + owner: any = { name: 'profile-name' }; + constructor() { + } + } + tcb.overrideView(LinkListBlock, { templateUrl: "app/components/noosfero-blocks/link-list/link-list.html", pipes: [NoosferoTemplateFilter] }).createAsync(CustomBlockType).then(fixture => { + expect(fixture.debugElement.queryAll(".link-list-block a").length).toEqual(2); + done(); + }); + }); + +}); diff --git a/src/app/components/noosfero-blocks/link-list/link-list.component.ts b/src/app/components/noosfero-blocks/link-list/link-list.component.ts index 58ba6b6..0f89091 100644 --- a/src/app/components/noosfero-blocks/link-list/link-list.component.ts +++ b/src/app/components/noosfero-blocks/link-list/link-list.component.ts @@ -12,7 +12,9 @@ export class LinkListBlock { links: any; ngOnInit() { - this.links = this.block.settings.links; + if (this.block && this.block.settings) { + this.links = this.block.settings.links; + } } } -- libgit2 0.21.2