Commit b07589aabca77dafb91532dd39b4619940ccaa2d
1 parent
e386083e
Exists in
master
and in
1 other branch
Move post comment component to its folder
Showing
10 changed files
with
110 additions
and
106 deletions
Show diff stats
src/app/article/comment/comments.component.spec.ts
@@ -2,7 +2,7 @@ import {Provider, provide, Component} from 'ng-forward'; | @@ -2,7 +2,7 @@ import {Provider, provide, Component} from 'ng-forward'; | ||
2 | import * as helpers from "../../../spec/helpers"; | 2 | import * as helpers from "../../../spec/helpers"; |
3 | 3 | ||
4 | import {CommentsComponent} from './comments.component'; | 4 | import {CommentsComponent} from './comments.component'; |
5 | -import {PostCommentComponent} from "./post-comment.component"; | 5 | +import {PostCommentComponent} from "./post-comment/post-comment.component"; |
6 | 6 | ||
7 | const htmlTemplate: string = '<noosfero-comments [article]="ctrl.article"></noosfero-comments>'; | 7 | const htmlTemplate: string = '<noosfero-comments [article]="ctrl.article"></noosfero-comments>'; |
8 | 8 |
src/app/article/comment/comments.component.ts
1 | import { Inject, Input, Component, provide } from 'ng-forward'; | 1 | import { Inject, Input, Component, provide } from 'ng-forward'; |
2 | -import { PostCommentComponent } from "./post-comment.component"; | 2 | +import { PostCommentComponent } from "./post-comment/post-comment.component"; |
3 | import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; | 3 | import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; |
4 | import { CommentComponent } from "./comment.component"; | 4 | import { CommentComponent } from "./comment.component"; |
5 | 5 |
src/app/article/comment/post-comment.component.spec.ts
@@ -1,66 +0,0 @@ | @@ -1,66 +0,0 @@ | ||
1 | -import {Provider, provide, Component} from 'ng-forward'; | ||
2 | -import * as helpers from "../../../spec/helpers"; | ||
3 | - | ||
4 | -import {PostCommentComponent} from './post-comment.component'; | ||
5 | - | ||
6 | -const htmlTemplate: string = '<noosfero-post-comment [article]="ctrl.article" [reply-of]="ctrl.comment"></noosfero-post-comment>'; | ||
7 | - | ||
8 | -describe("Components", () => { | ||
9 | - describe("Post Comment Component", () => { | ||
10 | - | ||
11 | - beforeEach(angular.mock.module("templates")); | ||
12 | - | ||
13 | - let commentService = jasmine.createSpyObj("commentService", ["createInArticle"]); | ||
14 | - let providers = [ | ||
15 | - new Provider('CommentService', { useValue: commentService }), | ||
16 | - new Provider('NotificationService', { useValue: helpers.mocks.notificationService }) | ||
17 | - ].concat(helpers.provideFilters("translateFilter")); | ||
18 | - | ||
19 | - @Component({ selector: 'test-container-component', directives: [PostCommentComponent], template: htmlTemplate, providers: providers }) | ||
20 | - class ContainerComponent { | ||
21 | - article = { id: 1 }; | ||
22 | - comment = { id: 2 }; | ||
23 | - } | ||
24 | - | ||
25 | - it("render the post comment form", done => { | ||
26 | - helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
27 | - expect(fixture.debugElement.queryAll("form").length).toEqual(1); | ||
28 | - done(); | ||
29 | - }); | ||
30 | - }); | ||
31 | - | ||
32 | - it("emit an event when create comment", done => { | ||
33 | - helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
34 | - let component: PostCommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
35 | - commentService.createInArticle = jasmine.createSpy("createInArticle").and.returnValue(helpers.mocks.promiseResultTemplate({ data: {} })); | ||
36 | - component["$rootScope"].$emit = jasmine.createSpy("$emit"); | ||
37 | - component.save(); | ||
38 | - expect(component["$rootScope"].$emit).toHaveBeenCalledWith(PostCommentComponent.EVENT_COMMENT_RECEIVED, jasmine.any(Object)); | ||
39 | - done(); | ||
40 | - }); | ||
41 | - }); | ||
42 | - | ||
43 | - it("notify success when create comment", done => { | ||
44 | - helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
45 | - let component: PostCommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
46 | - commentService.createInArticle = jasmine.createSpy("createInArticle").and.returnValue(helpers.mocks.promiseResultTemplate({ data: {} })); | ||
47 | - component["notificationService"].success = jasmine.createSpy("success"); | ||
48 | - component.save(); | ||
49 | - expect(component["notificationService"].success).toHaveBeenCalled(); | ||
50 | - done(); | ||
51 | - }); | ||
52 | - }); | ||
53 | - | ||
54 | - it("set the reply id when reply to a comment", done => { | ||
55 | - helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
56 | - let component: PostCommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
57 | - component.comment = <any>{ reply_of_id: null }; | ||
58 | - component.replyOf = <any>{ id: 10 }; | ||
59 | - component.save(); | ||
60 | - expect(component.comment.reply_of_id).toEqual(component.replyOf.id); | ||
61 | - done(); | ||
62 | - }); | ||
63 | - }); | ||
64 | - | ||
65 | - }); | ||
66 | -}); |
src/app/article/comment/post-comment.component.ts
@@ -1,30 +0,0 @@ | @@ -1,30 +0,0 @@ | ||
1 | -import { Inject, Input, Component } from 'ng-forward'; | ||
2 | -import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; | ||
3 | -import { NotificationService } from "../../shared/services/notification.service"; | ||
4 | - | ||
5 | -@Component({ | ||
6 | - selector: 'noosfero-post-comment', | ||
7 | - templateUrl: 'app/article/comment/post-comment.html' | ||
8 | -}) | ||
9 | -@Inject(CommentService, NotificationService, "$rootScope") | ||
10 | -export class PostCommentComponent { | ||
11 | - | ||
12 | - public static EVENT_COMMENT_RECEIVED = "comment.received"; | ||
13 | - | ||
14 | - @Input() article: noosfero.Article; | ||
15 | - @Input() replyOf: noosfero.Comment; | ||
16 | - | ||
17 | - comment: noosfero.Comment; | ||
18 | - | ||
19 | - constructor(private commentService: CommentService, private notificationService: NotificationService, private $rootScope: ng.IScope) { } | ||
20 | - | ||
21 | - save() { | ||
22 | - if (this.replyOf && this.comment) { | ||
23 | - this.comment.reply_of_id = this.replyOf.id; | ||
24 | - } | ||
25 | - this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult<noosfero.Comment>) => { | ||
26 | - this.$rootScope.$emit(PostCommentComponent.EVENT_COMMENT_RECEIVED, result.data); | ||
27 | - this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); | ||
28 | - }); | ||
29 | - } | ||
30 | -} |
src/app/article/comment/post-comment.html
@@ -1,6 +0,0 @@ | @@ -1,6 +0,0 @@ | ||
1 | -<form> | ||
2 | - <div class="form-group"> | ||
3 | - <textarea class="form-control custom-control" rows="3" ng-model="ctrl.comment.body"></textarea> | ||
4 | - </div> | ||
5 | - <button type="submit" class="btn btn-default" ng-click="ctrl.save()">{{"comment.post" | translate}}</button> | ||
6 | -</form> |
src/app/article/comment/post-comment/post-comment.component.spec.ts
0 → 100644
@@ -0,0 +1,66 @@ | @@ -0,0 +1,66 @@ | ||
1 | +import {Provider, provide, Component} from 'ng-forward'; | ||
2 | +import * as helpers from "../../../../spec/helpers"; | ||
3 | + | ||
4 | +import {PostCommentComponent} from './post-comment.component'; | ||
5 | + | ||
6 | +const htmlTemplate: string = '<noosfero-post-comment [article]="ctrl.article" [reply-of]="ctrl.comment"></noosfero-post-comment>'; | ||
7 | + | ||
8 | +describe("Components", () => { | ||
9 | + describe("Post Comment Component", () => { | ||
10 | + | ||
11 | + beforeEach(angular.mock.module("templates")); | ||
12 | + | ||
13 | + let commentService = jasmine.createSpyObj("commentService", ["createInArticle"]); | ||
14 | + let providers = [ | ||
15 | + new Provider('CommentService', { useValue: commentService }), | ||
16 | + new Provider('NotificationService', { useValue: helpers.mocks.notificationService }) | ||
17 | + ].concat(helpers.provideFilters("translateFilter")); | ||
18 | + | ||
19 | + @Component({ selector: 'test-container-component', directives: [PostCommentComponent], template: htmlTemplate, providers: providers }) | ||
20 | + class ContainerComponent { | ||
21 | + article = { id: 1 }; | ||
22 | + comment = { id: 2 }; | ||
23 | + } | ||
24 | + | ||
25 | + it("render the post comment form", done => { | ||
26 | + helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
27 | + expect(fixture.debugElement.queryAll("form").length).toEqual(1); | ||
28 | + done(); | ||
29 | + }); | ||
30 | + }); | ||
31 | + | ||
32 | + it("emit an event when create comment", done => { | ||
33 | + helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
34 | + let component: PostCommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
35 | + commentService.createInArticle = jasmine.createSpy("createInArticle").and.returnValue(helpers.mocks.promiseResultTemplate({ data: {} })); | ||
36 | + component["$rootScope"].$emit = jasmine.createSpy("$emit"); | ||
37 | + component.save(); | ||
38 | + expect(component["$rootScope"].$emit).toHaveBeenCalledWith(PostCommentComponent.EVENT_COMMENT_RECEIVED, jasmine.any(Object)); | ||
39 | + done(); | ||
40 | + }); | ||
41 | + }); | ||
42 | + | ||
43 | + it("notify success when create comment", done => { | ||
44 | + helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
45 | + let component: PostCommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
46 | + commentService.createInArticle = jasmine.createSpy("createInArticle").and.returnValue(helpers.mocks.promiseResultTemplate({ data: {} })); | ||
47 | + component["notificationService"].success = jasmine.createSpy("success"); | ||
48 | + component.save(); | ||
49 | + expect(component["notificationService"].success).toHaveBeenCalled(); | ||
50 | + done(); | ||
51 | + }); | ||
52 | + }); | ||
53 | + | ||
54 | + it("set the reply id when reply to a comment", done => { | ||
55 | + helpers.createComponentFromClass(ContainerComponent).then(fixture => { | ||
56 | + let component: PostCommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
57 | + component.comment = <any>{ reply_of_id: null }; | ||
58 | + component.replyOf = <any>{ id: 10 }; | ||
59 | + component.save(); | ||
60 | + expect(component.comment.reply_of_id).toEqual(component.replyOf.id); | ||
61 | + done(); | ||
62 | + }); | ||
63 | + }); | ||
64 | + | ||
65 | + }); | ||
66 | +}); |
src/app/article/comment/post-comment/post-comment.component.ts
0 → 100644
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +import { Inject, Input, Component } from 'ng-forward'; | ||
2 | +import { CommentService } from "../../../../lib/ng-noosfero-api/http/comment.service"; | ||
3 | +import { NotificationService } from "../../../shared/services/notification.service"; | ||
4 | + | ||
5 | +@Component({ | ||
6 | + selector: 'noosfero-post-comment', | ||
7 | + templateUrl: 'app/article/comment/post-comment/post-comment.html' | ||
8 | +}) | ||
9 | +@Inject(CommentService, NotificationService, "$rootScope") | ||
10 | +export class PostCommentComponent { | ||
11 | + | ||
12 | + public static EVENT_COMMENT_RECEIVED = "comment.received"; | ||
13 | + | ||
14 | + @Input() article: noosfero.Article; | ||
15 | + @Input() replyOf: noosfero.Comment; | ||
16 | + | ||
17 | + comment: noosfero.Comment; | ||
18 | + | ||
19 | + constructor(private commentService: CommentService, private notificationService: NotificationService, private $rootScope: ng.IScope) { } | ||
20 | + | ||
21 | + save() { | ||
22 | + if (this.replyOf && this.comment) { | ||
23 | + this.comment.reply_of_id = this.replyOf.id; | ||
24 | + } | ||
25 | + this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult<noosfero.Comment>) => { | ||
26 | + this.$rootScope.$emit(PostCommentComponent.EVENT_COMMENT_RECEIVED, result.data); | ||
27 | + this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); | ||
28 | + }); | ||
29 | + } | ||
30 | +} |
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
1 | +<form> | ||
2 | + <div class="form-group"> | ||
3 | + <textarea class="form-control custom-control" rows="3" ng-model="ctrl.comment.body"></textarea> | ||
4 | + </div> | ||
5 | + <button type="submit" class="btn btn-default" ng-click="ctrl.save()">{{"comment.post" | translate}}</button> | ||
6 | +</form> |
src/languages/en.json
@@ -29,5 +29,7 @@ | @@ -29,5 +29,7 @@ | ||
29 | "notification.error.default.title": "Oops...", | 29 | "notification.error.default.title": "Oops...", |
30 | "notification.profile.not_found": "Page not found", | 30 | "notification.profile.not_found": "Page not found", |
31 | "notification.http_error.401.message": "Unauthorized", | 31 | "notification.http_error.401.message": "Unauthorized", |
32 | - "notification.http_error.500.message": "Server error" | 32 | + "notification.http_error.500.message": "Server error", |
33 | + "comment.post": "Post a comment", | ||
34 | + "comment.reply": "reply" | ||
33 | } | 35 | } |
src/languages/pt.json
@@ -29,5 +29,7 @@ | @@ -29,5 +29,7 @@ | ||
29 | "notification.error.default.title": "Oops...", | 29 | "notification.error.default.title": "Oops...", |
30 | "notification.profile.not_found": "Página não encontrada", | 30 | "notification.profile.not_found": "Página não encontrada", |
31 | "notification.http_error.401.message": "Não autorizado", | 31 | "notification.http_error.401.message": "Não autorizado", |
32 | - "notification.http_error.500.message": "Erro no servidor" | 32 | + "notification.http_error.500.message": "Erro no servidor", |
33 | + "comment.post": "Commentar", | ||
34 | + "comment.reply": "responder" | ||
33 | } | 35 | } |