profile-description-block-plugin-profile-description-block.spec.ts 2.4 KB
import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
import {Provider, Input, provide, Component} from 'ng-forward';
import {provideFilters} from '../../../../spec/helpers';
import {ProfileDescriptionBlockPluginProfileDescriptionBlockComponent} from './profile-description-block-plugin-profile-description-block.component';
import * as helpers from "./../../../../spec/helpers";

const htmlTemplate: string = '<noosfero-profile-description-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-profile-description-block>';

const tcb = new TestComponentBuilder();

describe("Components", () => {
    describe("Profile Description Block Component", () => {

        let person = <noosfero.Person>{ name: "Person" };
        let mockedService = {
            getApiContent: (block: noosfero.Block): any => {
                return Promise.resolve({ description: "This is my description", headers: (name: string) => { return name; } });
            }
        };
        beforeEach(angular.mock.module("templates"));

        let state = jasmine.createSpyObj("state", ["go"]);

        function getProviders() {
            return [
                new Provider('$state', { useValue: state }),
                new Provider('BlockService', {
                    useValue: mockedService
                })
            ].concat(provideFilters("truncateFilter", "stripTagsFilter"));
        }
        let componentClass: any = null;

        function getComponent() {
            @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ProfileDescriptionBlockPluginProfileDescriptionBlockComponent], providers: getProviders() })
            class BlockContainerComponent {
                block = { type: 'Block', settings: {} };
                owner = person;
                constructor() {
                }
            }
            return BlockContainerComponent;
        }

        it("get description from block service", done => {
            tcb.createAsync(getComponent()).then(fixture => {
                let ProfileDescriptionBlockPluginProfileDescriptionBlock: ProfileDescriptionBlockPluginProfileDescriptionBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
                expect(ProfileDescriptionBlockPluginProfileDescriptionBlock.description).toEqual('This is my description');
                done();
            });
        });

    });
});