diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.js b/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.js
deleted file mode 100644
index cded10c..0000000
--- a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.js
+++ /dev/null
@@ -1,33 +0,0 @@
-(function() {
- 'use strict';
-
- angular
- .module('noosferoApp')
- .component('noosferoRecentDocumentsBlock', {
- restrict: 'E',
- templateUrl: 'app/components/noosfero-blocks/recent-documents/recent-documents.html',
- bindings: {
- block: '<',
- owner: '<'
- },
- controller: RecentDocumentsController
- });
-
- /** @ngInject */
- function RecentDocumentsController(noosfero, $state) {
- var vm = this;
- vm.profile = vm.owner;
- vm.documents = [];
-
- vm.openDocument = function(article) {
- $state.go("main.profile.page", {page: article.path, profile: article.profile.identifier});
- }
-
- var limit = vm.block.settings.limit || 5;
- //FIXME get all text articles
- noosfero.profiles.one(vm.profile.id).one('articles').get({content_type: 'TinyMceArticle', per_page: limit}).then(function(response) {
- vm.documents = response.data.articles;
- });
- }
-
-})();
diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts b/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
new file mode 100644
index 0000000..8b4a180
--- /dev/null
+++ b/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
@@ -0,0 +1,52 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Provider, Input, provide, Component} from 'ng-forward';
+
+import {RecentDocumentsBlock} from './recent-documents.component';
+
+const htmlTemplate: string = '';
+
+const tcb = new TestComponentBuilder();
+
+describe("Recent Documents 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('ArticleService', {
+ useValue: {
+ getByProfile: (profileId: number, filters: any): any => {
+ return Promise.resolve({ data: { articles: [{ name: "article1" }] } });
+ }
+ }
+ }),
+ ];
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlock], providers: providers })
+ class BlockContainerComponent {
+ block = { type: 'Block', settings: {} };
+ owner = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+
+ it("get recent documents from the article service", done => {
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
+ expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]);
+ done();
+ });
+ });
+
+ it("go to article page when open a document", done => {
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
+ recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
+ expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" });
+ done();
+ });
+ });
+
+});
diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts b/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
new file mode 100644
index 0000000..401f720
--- /dev/null
+++ b/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
@@ -0,0 +1,35 @@
+import {Component, Inject, Input} from "ng-forward";
+import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service";
+
+@Component({
+ selector: "noosfero-recent-documents-block",
+ templateUrl: 'app/components/noosfero-blocks/recent-documents/recent-documents.html'
+})
+@Inject(ArticleService, "$state")
+export class RecentDocumentsBlock {
+
+ @Input() block: any;
+ @Input() owner: any;
+
+ profile: any;
+ documents: any;
+
+ constructor(private ArticleService: ArticleService, private $state: any) {
+ }
+
+ ngOnInit() {
+ this.profile = this.owner;
+ this.documents = [];
+
+ var limit = (this.block && this.block.settings) ? this.block.settings.limit : null || 5;
+ //FIXME get all text articles
+ this.ArticleService.getByProfile(this.profile.id, { content_type: 'TinyMceArticle', per_page: limit }).then((response: any) => {
+ this.documents = response.data.articles;
+ });
+ }
+
+ openDocument(article: any) {
+ this.$state.go("main.profile.page", { page: article.path, profile: article.profile.identifier });
+ }
+
+}
diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.html b/src/app/components/noosfero-blocks/recent-documents/recent-documents.html
index 84afdf1..0c5f80f 100644
--- a/src/app/components/noosfero-blocks/recent-documents/recent-documents.html
+++ b/src/app/components/noosfero-blocks/recent-documents/recent-documents.html
@@ -1,5 +1,5 @@
-