diff --git a/src/plugins/comment_paragraph/block/discussion/discussion-block.component.spec.ts b/src/plugins/comment_paragraph/block/discussion/discussion-block.component.spec.ts new file mode 100644 index 0000000..bdd24cf --- /dev/null +++ b/src/plugins/comment_paragraph/block/discussion/discussion-block.component.spec.ts @@ -0,0 +1,54 @@ +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Provider, Input, provide, Component} from 'ng-forward'; +import {provideFilters} from '../../../../spec/helpers'; +import {DiscussionBlockComponent} from './discussion-block.component'; +import {ComponentTestHelper, createClass} from './../../../../spec/component-test-helper'; + +const htmlTemplate: string = ''; + +const tcb = new TestComponentBuilder(); + +describe("Components", () => { + describe("Discussion Block Component", () => { + + let helper: ComponentTestHelper; + let settingsObj = {}; + let mockedBlockService = { + getApiContent: (block: noosfero.Block): any => { + return Promise.resolve({ articles: [{ name: "article1" }], headers: (name: string) => { return name; } }); + } + }; + let profile = { name: 'profile-name' }; + + let state = jasmine.createSpyObj("state", ["go"]); + + let providers = [ + new Provider('$state', { useValue: state }), + new Provider('BlockService', { + useValue: mockedBlockService + }), + ].concat(provideFilters("truncateFilter", "stripTagsFilter", "translateFilter", "amDateFormatFilter")); + + beforeEach(angular.mock.module("templates")); + + beforeEach((done) => { + let cls = createClass({ + template: htmlTemplate, + directives: [DiscussionBlockComponent], + providers: providers, + properties: {} + }); + helper = new ComponentTestHelper(cls, done); + }); + + it("get discussions from the block service", () => { + expect(helper.component.documents).toEqual([{ name: "article1" }]); + }); + + it("go to article page when open a document", () => { + let block = helper.component; + block.openDocument({ path: "path", profile: { identifier: "identifier" } }); + expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); + }); + }); +}); diff --git a/src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts b/src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts index 33824f6..afceacc 100644 --- a/src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts +++ b/src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts @@ -1,48 +1,26 @@ import {Component, Inject, Input} from "ng-forward"; -import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; +import {BlockService} from "../../../../lib/ng-noosfero-api/http/block.service"; @Component({ selector: "noosfero-comment-paragraph-plugin-discussion-block", templateUrl: 'plugins/comment_paragraph/block/discussion/discussion-block.html' }) -@Inject(ArticleService, "$state") +@Inject(BlockService, "$state") export class DiscussionBlockComponent { @Input() block: any; @Input() owner: any; - profile: any; - documents: any; + profile: noosfero.Profile; + documents: Array; - documentsLoaded: boolean = false; - - constructor(private articleService: ArticleService, private $state: any) { } + constructor(private blockService: BlockService, private $state: any) { } ngOnInit() { this.profile = this.owner; - this.documents = []; - - let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 50; - let params: any = { content_type: 'CommentParagraphPlugin::Discussion', per_page: limit, order: 'start_date DESC' }; - let now = new Date().toISOString(); - switch (this.block.settings['discussion_status']) { - case 0: - params['from_start_date'] = now; - break; - case 1: - params['until_start_date'] = now; - params['from_end_date'] = now; - break; - case 2: - params['until_end_date'] = now; - break; - } - console.log(this.block.settings['discussion_status']); - this.articleService.getByProfile(this.profile, params) - .then((result: noosfero.RestResult) => { - this.documents = result.data; - this.documentsLoaded = true; - }); + this.blockService.getApiContent(this.block).then((content: any) => { + this.documents = content.articles; + }); } openDocument(article: any) { -- libgit2 0.21.2