Commit d5a304a4ea340ad220de9d6b5a56826afc966567
Exists in
master
and in
18 other branches
merge with remove-article-confirmation. it closes issue #84
Showing
5 changed files
with
38 additions
and
9 deletions
Show diff stats
src/app/article/article-default-view-component.spec.ts
... | ... | @@ -19,6 +19,7 @@ describe("Components", () => { |
19 | 19 | describe("Article Default View Component", () => { |
20 | 20 | let helper: ComponentTestHelper<ArticleDefaultViewComponent>; |
21 | 21 | const defaultViewTemplate: string = '<noosfero-default-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-default-article>'; |
22 | + let notificationService = helpers.mocks.notificationService; | |
22 | 23 | let articleService: any = helpers.mocks.articleService; |
23 | 24 | let article = <noosfero.Article>{ |
24 | 25 | id: 1, |
... | ... | @@ -29,7 +30,8 @@ describe("Components", () => { |
29 | 30 | let state = <ng.ui.IStateService>jasmine.createSpyObj("state", ["go", "transitionTo"]); |
30 | 31 | let providers = [ |
31 | 32 | provide('$state', { useValue: state }), |
32 | - provide('ArticleService', { useValue: articleService }) | |
33 | + provide('ArticleService', { useValue: articleService }), | |
34 | + helpers.createProviderToValue('NotificationService', notificationService), | |
33 | 35 | ].concat(helpers.provideFilters("translateFilter")); |
34 | 36 | |
35 | 37 | /** |
... | ... | @@ -67,23 +69,33 @@ describe("Components", () => { |
67 | 69 | * Execute the delete method on the target component |
68 | 70 | */ |
69 | 71 | function doDeleteArticle() { |
72 | + // Create a mock for the notification service confirmation | |
73 | + spyOn(helper.component.notificationService, 'confirmation').and.callFake(function (params: Function) { | |
74 | + | |
75 | + }); | |
70 | 76 | // Create a mock for the ArticleService removeArticle method |
71 | - spyOn(helper.component.articleService, 'remove').and.callFake(function(param: noosfero.Article) { | |
77 | + spyOn(helper.component.articleService, 'remove').and.callFake(function (param: noosfero.Article) { | |
78 | + | |
72 | 79 | return { |
73 | - catch: () => {} | |
80 | + catch: () => { } | |
74 | 81 | }; |
75 | 82 | }); |
76 | 83 | helper.component.delete(); |
84 | + expect(notificationService.confirmation).toHaveBeenCalled(); | |
85 | + helper.component.doDelete(); | |
77 | 86 | expect(articleService.remove).toHaveBeenCalled(); |
87 | + | |
78 | 88 | // After the component delete method execution, fire the |
79 | 89 | // ArticleEvent.removed event |
80 | 90 | simulateRemovedEvent(); |
81 | 91 | } |
82 | 92 | |
83 | 93 | /** |
84 | - * Simulate the ArticleService ArticleEvent.removed event | |
94 | + * Simulate the Notification Service confirmation and ArticleService | |
95 | + * notifyArticleRemovedListeners event | |
85 | 96 | */ |
86 | 97 | function simulateRemovedEvent() { |
98 | + helper.component.notificationService["confirmation"]({ title: "Title", message: "Message" }, () => { }); | |
87 | 99 | helper.component.articleService["modelRemovedEventEmitter"].next(article); |
88 | 100 | } |
89 | 101 | }); | ... | ... |
src/app/article/article-default-view.component.ts
... | ... | @@ -5,7 +5,8 @@ import {MacroDirective} from "./macro/macro.directive"; |
5 | 5 | import {ArticleToolbarHotspotComponent} from "../hotspot/article-toolbar-hotspot.component"; |
6 | 6 | import {ArticleContentHotspotComponent} from "../hotspot/article-content-hotspot.component"; |
7 | 7 | import {ArticleService} from "./../../lib/ng-noosfero-api/http/article.service"; |
8 | -import {NotificationService} from "./../shared/services/notification.service"; | |
8 | +import { NotificationService } from "./../shared/services/notification.service"; | |
9 | + | |
9 | 10 | /** |
10 | 11 | * @ngdoc controller |
11 | 12 | * @name ArticleDefaultView |
... | ... | @@ -17,13 +18,13 @@ import {NotificationService} from "./../shared/services/notification.service"; |
17 | 18 | selector: 'noosfero-default-article', |
18 | 19 | templateUrl: 'app/article/article.html' |
19 | 20 | }) |
20 | -@Inject("$state", ArticleService) | |
21 | +@Inject("$state", ArticleService, NotificationService) | |
21 | 22 | export class ArticleDefaultViewComponent { |
22 | 23 | |
23 | 24 | @Input() article: noosfero.Article; |
24 | 25 | @Input() profile: noosfero.Profile; |
25 | 26 | |
26 | - constructor(private $state: ng.ui.IStateService, public articleService: ArticleService) { | |
27 | + constructor(private $state: ng.ui.IStateService, public articleService: ArticleService, public notificationService: NotificationService) { | |
27 | 28 | // Subscribe to the Article Removed Event |
28 | 29 | this.articleService.subscribeToModelRemoved((article: noosfero.Article) => { |
29 | 30 | if (this.article.parent) { |
... | ... | @@ -31,13 +32,20 @@ export class ArticleDefaultViewComponent { |
31 | 32 | } else { |
32 | 33 | this.$state.transitionTo('main.profile.info', { profile: this.article.profile.identifier }); |
33 | 34 | } |
35 | + this.notificationService.success({ title: "article.remove.success.title", message: "article.remove.success.message" }); | |
34 | 36 | }); |
35 | 37 | } |
36 | 38 | |
37 | 39 | delete() { |
38 | - this.articleService.remove(this.article); | |
40 | + this.notificationService.confirmation({ title: "article.remove.confirmation.title", message: "article.remove.confirmation.message" }, () => { | |
41 | + this.doDelete(); | |
42 | + }); | |
43 | + | |
39 | 44 | } |
40 | 45 | |
46 | + doDelete() { | |
47 | + this.articleService.remove(this.article); | |
48 | + } | |
41 | 49 | } |
42 | 50 | |
43 | 51 | /** | ... | ... |
src/languages/en.json
... | ... | @@ -56,6 +56,10 @@ |
56 | 56 | "article.basic_editor.cancel": "Cancel", |
57 | 57 | "article.basic_editor.success.title": "Good job!", |
58 | 58 | "article.basic_editor.success.message": "Article saved!", |
59 | + "article.remove.success.title": "Good job!", | |
60 | + "article.remove.success.message": "Article removed!", | |
61 | + "article.remove.confirmation.title": "Are you sure?", | |
62 | + "article.remove.confirmation.message": "You will not be able to recover this article!", | |
59 | 63 | "article.basic_editor.visibility": "Visibility", |
60 | 64 | "article.basic_editor.visibility.public": "Public", |
61 | 65 | "article.basic_editor.visibility.private": "Private", | ... | ... |
src/languages/pt.json
... | ... | @@ -53,6 +53,10 @@ |
53 | 53 | "article.basic_editor.cancel": "Cancelar", |
54 | 54 | "article.basic_editor.success.title": "Bom trabalho!", |
55 | 55 | "article.basic_editor.success.message": "Artigo salvo com sucesso!", |
56 | + "article.remove.success.title": "Bom trabalho!", | |
57 | + "article.remove.success.message": "Artigo removido!", | |
58 | + "article.remove.confirmation.title": "Tem certeza?", | |
59 | + "article.remove.confirmation.message": "Não será possível recuperar este artigo!", | |
56 | 60 | "article.basic_editor.visibility": "Visibilidade", |
57 | 61 | "article.basic_editor.visibility.public": "Público", |
58 | 62 | "article.basic_editor.visibility.private": "Privado", | ... | ... |
src/spec/mocks.ts