From b3bfce0bd0a28bfd58db38d16d70ee43dc6ccdb7 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 28 Mar 2016 09:55:54 -0300 Subject: [PATCH] Add tests for communities block --- src/app/layout/blocks/communities-block/communities-block.component.spec.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+), 0 deletions(-) create mode 100644 src/app/layout/blocks/communities-block/communities-block.component.spec.ts diff --git a/src/app/layout/blocks/communities-block/communities-block.component.spec.ts b/src/app/layout/blocks/communities-block/communities-block.component.spec.ts new file mode 100644 index 0000000..f81581d --- /dev/null +++ b/src/app/layout/blocks/communities-block/communities-block.component.spec.ts @@ -0,0 +1,51 @@ +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Provider, Input, provide, Component} from 'ng-forward'; + +import {CommunitiesBlockComponent} from './communities-block.component'; + +const htmlTemplate: string = ''; + +const tcb = new TestComponentBuilder(); + +describe("Components", () => { + describe("Communities Block Component", () => { + + beforeEach(angular.mock.module("templates")); + + let state = jasmine.createSpyObj("state", ["go"]); + let providers = [ + new Provider('truncateFilter', { useValue: () => { } }), + new Provider('stripTagsFilter', { useValue: () => { } }), + new Provider('$state', { useValue: state }), + new Provider('CommunityService', { + useValue: { + list: (profileId: number, params: any): any => { + return Promise.resolve({ data: [{ identifier: "community1" }] }); + } + } + }), + ]; + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [CommunitiesBlockComponent], providers: providers }) + class BlockContainerComponent { + block = { type: 'Block', settings: {} }; + owner = { name: 'profile-name' }; + } + + it("get communities", done => { + tcb.createAsync(BlockContainerComponent).then(fixture => { + let block: CommunitiesBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + expect(block.profiles).toEqual([{ identifier: "community1" }]); + done(); + }); + }); + + it("render the profile image for each community", done => { + tcb.createAsync(BlockContainerComponent).then(fixture => { + fixture.debugElement.getLocal("$rootScope").$apply(); + expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); + done(); + }); + }); + + }); +}); -- libgit2 0.21.2