Commit af9fc87e08a4c8da2691da9c135ae3af6f8444a4
1 parent
490f391a
Exists in
master
and in
18 other branches
refactory of articles watchers
Showing
10 changed files
with
48 additions
and
34 deletions
Show diff stats
src/app/article/article-default-view-component.spec.ts
| ... | ... | @@ -68,13 +68,13 @@ describe("Components", () => { |
| 68 | 68 | */ |
| 69 | 69 | function doDeleteArticle() { |
| 70 | 70 | // Create a mock for the ArticleService removeArticle method |
| 71 | - spyOn(helper.component.articleService, 'removeArticle').and.callFake(function(param: noosfero.Article) { | |
| 71 | + spyOn(helper.component.articleService, 'remove').and.callFake(function(param: noosfero.Article) { | |
| 72 | 72 | return { |
| 73 | 73 | catch: () => {} |
| 74 | 74 | }; |
| 75 | 75 | }); |
| 76 | 76 | helper.component.delete(); |
| 77 | - expect(articleService.removeArticle).toHaveBeenCalled(); | |
| 77 | + expect(articleService.remove).toHaveBeenCalled(); | |
| 78 | 78 | // After the component delete method execution, fire the |
| 79 | 79 | // ArticleEvent.removed event |
| 80 | 80 | simulateRemovedEvent(); |
| ... | ... | @@ -84,7 +84,7 @@ describe("Components", () => { |
| 84 | 84 | * Simulate the ArticleService ArticleEvent.removed event |
| 85 | 85 | */ |
| 86 | 86 | function simulateRemovedEvent() { |
| 87 | - helper.component.articleService["notifyArticleRemovedListeners"](article); | |
| 87 | + helper.component.articleService["modelRemovedEventEmitter"].next(article); | |
| 88 | 88 | } |
| 89 | 89 | }); |
| 90 | 90 | ... | ... |
src/app/article/article-default-view.component.ts
| ... | ... | @@ -17,13 +17,13 @@ import {NotificationService} from "./../shared/services/notification.service"; |
| 17 | 17 | selector: 'noosfero-default-article', |
| 18 | 18 | templateUrl: 'app/article/article.html' |
| 19 | 19 | }) |
| 20 | -@Inject("$state", ArticleService, NotificationService) | |
| 20 | +@Inject("$state", ArticleService) | |
| 21 | 21 | export class ArticleDefaultViewComponent { |
| 22 | 22 | |
| 23 | 23 | @Input() article: noosfero.Article; |
| 24 | 24 | @Input() profile: noosfero.Profile; |
| 25 | 25 | |
| 26 | - constructor(private $state: ng.ui.IStateService, public articleService: ArticleService, protected notificationService: NotificationService) { | |
| 26 | + constructor(private $state: ng.ui.IStateService, public articleService: ArticleService) { | |
| 27 | 27 | // Subscribe to the Article Removed Event |
| 28 | 28 | this.articleService.subscribeToModelRemoved((article: noosfero.Article) => { |
| 29 | 29 | if (this.article.parent) { | ... | ... |
src/app/layout/blocks/recent-documents/recent-documents-block.component.spec.ts
| ... | ... | @@ -15,7 +15,7 @@ describe("Components", () => { |
| 15 | 15 | let article = <noosfero.Article>{ name: "article1" }; |
| 16 | 16 | let mockedBlockService = { |
| 17 | 17 | getApiContent: (block: noosfero.Block): any => { |
| 18 | - return Promise.resolve({ articles: [ article ], headers: (name: string) => { return name; } }); | |
| 18 | + return Promise.resolve({ articles: [article], headers: (name: string) => { return name; } }); | |
| 19 | 19 | } |
| 20 | 20 | }; |
| 21 | 21 | let articleService: any = helpers.mocks.articleService; |
| ... | ... | @@ -51,7 +51,7 @@ describe("Components", () => { |
| 51 | 51 | it("get recent documents from the block service", done => { |
| 52 | 52 | tcb.createAsync(getComponent()).then(fixture => { |
| 53 | 53 | let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; |
| 54 | - expect(recentDocumentsBlock.documents).toEqual([ article ]); | |
| 54 | + expect(recentDocumentsBlock.documents).toEqual([article]); | |
| 55 | 55 | done(); |
| 56 | 56 | }); |
| 57 | 57 | }); |
| ... | ... | @@ -71,16 +71,16 @@ describe("Components", () => { |
| 71 | 71 | expect(recentDocumentsBlock.documents.length).toEqual(1); |
| 72 | 72 | simulateRemovedEvent(recentDocumentsBlock); |
| 73 | 73 | expect(recentDocumentsBlock.documents.length).toEqual(0); |
| 74 | - done(); | |
| 75 | - }) | |
| 74 | + done(); | |
| 75 | + }); | |
| 76 | 76 | }); |
| 77 | - | |
| 77 | + | |
| 78 | 78 | /** |
| 79 | 79 | * Simulate the ArticleService ArticleEvent.removed event |
| 80 | 80 | */ |
| 81 | 81 | function simulateRemovedEvent(recentDocumentsBlock: RecentDocumentsBlockComponent) { |
| 82 | - recentDocumentsBlock.articleService["notifyArticleRemovedListeners"](article); | |
| 82 | + recentDocumentsBlock.articleService["modelRemovedEventEmitter"].next(article); | |
| 83 | 83 | } |
| 84 | - | |
| 84 | + | |
| 85 | 85 | }); |
| 86 | 86 | }); | ... | ... |
src/app/layout/blocks/recent-documents/recent-documents-block.component.ts
| ... | ... | @@ -30,7 +30,7 @@ export class RecentDocumentsBlockComponent { |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | watchArticles() { |
| 33 | - this.articleService.subscribeToArticleRemoved((article: noosfero.Article) => { | |
| 33 | + this.articleService.subscribeToModelRemoved((article: noosfero.Article) => { | |
| 34 | 34 | Arrays.remove(this.documents, article); |
| 35 | 35 | }); |
| 36 | 36 | } | ... | ... |
src/app/layout/blocks/statistics/statistics-block.component.spec.ts
| 1 | +import {provide} from 'ng-forward'; | |
| 1 | 2 | import {ComponentTestHelper, createClass} from './../../../../spec/component-test-helper'; |
| 2 | 3 | import {StatisticsBlockComponent} from './statistics-block.component'; |
| 3 | 4 | import * as helpers from "../../../../spec/helpers"; |
| 4 | 5 | |
| 5 | 6 | const htmlTemplate: string = '<noosfero-statistics-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-statistics-block>'; |
| 6 | 7 | |
| 8 | + | |
| 7 | 9 | describe("Components", () => { |
| 8 | 10 | |
| 9 | 11 | describe("Statistics Block Component", () => { |
| ... | ... | @@ -11,10 +13,15 @@ describe("Components", () => { |
| 11 | 13 | beforeEach(angular.mock.module("templates")); |
| 12 | 14 | |
| 13 | 15 | beforeEach((done) => { |
| 16 | + let articleService: any = helpers.mocks.articleService; | |
| 17 | + let blockService: any = jasmine.createSpyObj("blockService", ["getBlock"]); | |
| 14 | 18 | let cls = createClass({ |
| 15 | 19 | template: htmlTemplate, |
| 16 | 20 | directives: [StatisticsBlockComponent], |
| 17 | - providers: helpers.provideFilters("translateFilter"), | |
| 21 | + providers: [ | |
| 22 | + provide('ArticleService', { useValue: articleService }), | |
| 23 | + provide('BlockService', { useValue: blockService }) | |
| 24 | + ].concat(helpers.provideFilters("translateFilter")), | |
| 18 | 25 | properties: { |
| 19 | 26 | block: { |
| 20 | 27 | statistics: [ | ... | ... |
src/lib/ng-noosfero-api/http/article.service.spec.ts
| ... | ... | @@ -23,7 +23,7 @@ describe("Services", () => { |
| 23 | 23 | it("should remove article", (done) => { |
| 24 | 24 | let articleId = 1; |
| 25 | 25 | $httpBackend.expectDELETE(`/api/v1/articles/${articleId}`).respond(200, { success: "true" }); |
| 26 | - articleService.removeArticle(<noosfero.Article>{id: articleId}); | |
| 26 | + articleService.remove(<noosfero.Article>{id: articleId}); | |
| 27 | 27 | $httpBackend.flush(); |
| 28 | 28 | $httpBackend.verifyNoOutstandingExpectation(); |
| 29 | 29 | done(); | ... | ... |
src/lib/util/arrays.ts
src/plugins/comment_paragraph/block/discussion/discussion-block.component.spec.ts
| ... | ... | @@ -17,7 +17,7 @@ describe("Components", () => { |
| 17 | 17 | let article = <noosfero.Article>{ name: "article1" }; |
| 18 | 18 | let mockedBlockService = { |
| 19 | 19 | getApiContent: (content: any): any => { |
| 20 | - return Promise.resolve({ articles: [ article ], headers: (name: string) => { return name; } }); | |
| 20 | + return Promise.resolve({ articles: [article], headers: (name: string) => { return name; } }); | |
| 21 | 21 | } |
| 22 | 22 | }; |
| 23 | 23 | let articleService: any = helpers.mocks.articleService; |
| ... | ... | @@ -55,7 +55,7 @@ describe("Components", () => { |
| 55 | 55 | block.openDocument({ path: "path", profile: { identifier: "identifier" } }); |
| 56 | 56 | expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); |
| 57 | 57 | }); |
| 58 | - | |
| 58 | + | |
| 59 | 59 | it("verify removed article has been removed from list", () => { |
| 60 | 60 | expect(helper.component.documents.length).toEqual(1); |
| 61 | 61 | simulateRemovedEvent(); |
| ... | ... | @@ -65,7 +65,7 @@ describe("Components", () => { |
| 65 | 65 | * Simulate the ArticleService ArticleEvent.removed event |
| 66 | 66 | */ |
| 67 | 67 | function simulateRemovedEvent() { |
| 68 | - helper.component.articleService["notifyArticleRemovedListeners"](article); | |
| 69 | - } | |
| 68 | + helper.component.articleService["modelRemovedEventEmitter"].next(article); | |
| 69 | + } | |
| 70 | 70 | }); |
| 71 | 71 | }); | ... | ... |
src/plugins/comment_paragraph/block/discussion/discussion-block.component.ts
| 1 | 1 | import {Component, Inject, Input} from "ng-forward"; |
| 2 | 2 | import {BlockService} from "../../../../lib/ng-noosfero-api/http/block.service"; |
| 3 | -import {ArticleService} from "./../../../../lib/ng-noosfero-api/http/article.service" | |
| 4 | -import {Arrays} from "./../../../../lib/util/arrays" | |
| 3 | +import {ArticleService} from "./../../../../lib/ng-noosfero-api/http/article.service"; | |
| 4 | +import {Arrays} from "./../../../../lib/util/arrays"; | |
| 5 | 5 | |
| 6 | 6 | @Component({ |
| 7 | 7 | selector: "noosfero-comment-paragraph-plugin-discussion-block", |
| ... | ... | @@ -26,9 +26,9 @@ export class DiscussionBlockComponent { |
| 26 | 26 | }); |
| 27 | 27 | this.watchArticles(); |
| 28 | 28 | } |
| 29 | - | |
| 29 | + | |
| 30 | 30 | watchArticles() { |
| 31 | - this.articleService.subscribeToArticleRemoved((article: noosfero.Article) => { | |
| 31 | + this.articleService.subscribeToModelRemoved((article: noosfero.Article) => { | |
| 32 | 32 | Arrays.remove(this.documents, article); |
| 33 | 33 | }); |
| 34 | 34 | } | ... | ... |
src/spec/mocks.ts
| ... | ... | @@ -77,10 +77,14 @@ export var mocks: any = { |
| 77 | 77 | }, |
| 78 | 78 | articleService: { |
| 79 | 79 | articleRemovedFn: null, |
| 80 | - subscribeToArticleRemoved: (fn: Function) => { | |
| 80 | + articleAddedFn: null, | |
| 81 | + subscribeToModelRemoved: (fn: Function) => { | |
| 81 | 82 | mocks.articleService.articleRemovedFn = fn; |
| 82 | 83 | }, |
| 83 | - articleRemoved: | |
| 84 | + subscribeToModelAdded: (fn: Function) => { | |
| 85 | + mocks.articleService.articleAddedFn = fn; | |
| 86 | + }, | |
| 87 | + modelRemovedEventEmitter: | |
| 84 | 88 | { |
| 85 | 89 | subscribe: (fn: Function) => { |
| 86 | 90 | mocks.articleService.articleRemovedFn = fn; |
| ... | ... | @@ -90,18 +94,22 @@ export var mocks: any = { |
| 90 | 94 | } |
| 91 | 95 | } |
| 92 | 96 | , |
| 93 | - removeArticle: (article: noosfero.Article) => { | |
| 97 | + modelAddedEventEmitter: | |
| 98 | + { | |
| 99 | + subscribe: (fn: Function) => { | |
| 100 | + mocks.articleService.articleAddedFn = fn; | |
| 101 | + }, | |
| 102 | + next: (param: any) => { | |
| 103 | + mocks.articleService.articleAddedFn(param); | |
| 104 | + } | |
| 105 | + } | |
| 106 | + , | |
| 107 | + remove: (article: noosfero.Article) => { | |
| 94 | 108 | return { |
| 95 | 109 | catch: (func?: Function) => { |
| 96 | 110 | } |
| 97 | 111 | }; |
| 98 | 112 | }, |
| 99 | - notifyArticleRemovedListeners: (article: noosfero.Article) => { | |
| 100 | - mocks.articleService.articleRemoved.next(article); | |
| 101 | - }, | |
| 102 | - subscribe: (eventType: any, fn: Function) => { | |
| 103 | - mocks.articleService.articleRemoved.subscribe(fn); | |
| 104 | - }, | |
| 105 | 113 | getByProfile: (profileId: number, params?: any) => { |
| 106 | 114 | return { |
| 107 | 115 | then: (func?: Function) => { | ... | ... |