Commit 1fa4fdeaf2a3b6007f6b8730ff877c5e8f339b00
1 parent
41a1626d
Exists in
master
and in
31 other branches
fixed webpack errors and warnings
Showing
28 changed files
with
136 additions
and
93 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +let replace = require("replace"); | |
| 2 | + | |
| 3 | +import * as path from "path"; | |
| 4 | + | |
| 5 | +let wrong_jqlite_d_ts_file = path.join(__dirname, "../node_modules/ng-forward/cjs/util/jqlite-extensions.d.ts"); | |
| 6 | + | |
| 7 | +replace({ | |
| 8 | + regex: /import JQuery from \".\/\";/, | |
| 9 | + replacement: "", | |
| 10 | + paths: [wrong_jqlite_d_ts_file], | |
| 11 | + sillent: false | |
| 12 | +}); | |
| 13 | + | ... | ... |
package.json
| ... | ... | @@ -4,20 +4,22 @@ |
| 4 | 4 | "dependencies": { |
| 5 | 5 | "angular": "^1.5.0", |
| 6 | 6 | "angular-mock": "^1.0.0", |
| 7 | - "moment": "^2.11.2" | |
| 7 | + "moment": "^2.11.2", | |
| 8 | + "ng-forward": "0.0.1-alpha.12" | |
| 8 | 9 | }, |
| 9 | 10 | "scripts": { |
| 10 | 11 | "build": "webpack; gulp build", |
| 11 | 12 | "webpack": "webpack", |
| 12 | - "karma": "karma", | |
| 13 | + "karma": "concurrently \"webpack -w\" \"karma start\"", | |
| 13 | 14 | "coverage": "karma start --single-run; npm run remap-coverage", |
| 14 | 15 | "remap-coverage": "ts-node --project ./dev-scripts ./dev-scripts/remapCoverage.ts", |
| 15 | 16 | "test-single": "karma start --single-run", |
| 16 | 17 | "test-and-coverage": "karma start & npm run remap-coverage", |
| 17 | 18 | "test": "webpack -w --test", |
| 18 | - "postinstall": "npm install -g bower && bower install && typings install && cd dev-scripts && typings install", | |
| 19 | + "postinstall": "npm install -g bower; bower install; typings install; npm run fix-jqlite; cd dev-scripts; typings install", | |
| 19 | 20 | "start": "concurrently \"webpack -w\" \"gulp serve\"", |
| 20 | - "generate-indexes": "ts-node --project ./dev-scripts ./dev-scripts/generate-index-modules.ts" | |
| 21 | + "generate-indexes": "ts-node --project ./dev-scripts ./dev-scripts/generate-index-modules.ts", | |
| 22 | + "fix-jqlite": "ts-node --project ./dev-scripts dev-scripts/fix-jqlite.ts" | |
| 21 | 23 | }, |
| 22 | 24 | "devDependencies": { |
| 23 | 25 | "browser-sync": "~2.9.11", | ... | ... |
src/app/components/auth/auth_service.spec.ts
| ... | ... | @@ -55,7 +55,7 @@ describe("Services", () => { |
| 55 | 55 | let eventEmmited: boolean = false; |
| 56 | 56 | $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: User) => { |
| 57 | 57 | eventEmmited = true; |
| 58 | - expect(userThroughEvent).toEqual(user) | |
| 58 | + expect(userThroughEvent).toEqual(user); | |
| 59 | 59 | }); |
| 60 | 60 | |
| 61 | 61 | $httpBackend.flush(); | ... | ... |
src/app/components/language-selector/language-selector.component.spec.ts
| ... | ... | @@ -30,7 +30,7 @@ describe("Components", () => { |
| 30 | 30 | }) |
| 31 | 31 | ].concat(helpers.provideFilters("translateFilter")) |
| 32 | 32 | }); |
| 33 | - } | |
| 33 | + }; | |
| 34 | 34 | |
| 35 | 35 | it("set available languages when change language", (done) => { |
| 36 | 36 | let component: LanguageSelector = new LanguageSelector( | ... | ... |
src/app/components/language-selector/language-selector.component.ts
| ... | ... | @@ -41,7 +41,7 @@ export class LanguageSelector { |
| 41 | 41 | |
| 42 | 42 | private changeMomentLocale(language: string) { |
| 43 | 43 | let localePromise = Promise.resolve(); |
| 44 | - if (language != "en") { | |
| 44 | + if (language !== "en") { | |
| 45 | 45 | localePromise = this.angularLoad.loadScript(`/bower_components/moment/locale/${language}.js`); |
| 46 | 46 | } |
| 47 | 47 | localePromise.then(() => { | ... | ... |
src/app/components/navbar/navbar.spec.ts
src/app/components/noosfero-articles/blog/blog.component.spec.ts
| ... | ... | @@ -73,14 +73,14 @@ describe("Blog Component", () => { |
| 73 | 73 | // the templates to the templateCache into the module templates |
| 74 | 74 | // we need to load the module templates here as the template for the |
| 75 | 75 | // component Noosfero ArtileView will be load on our tests |
| 76 | - angular.mock.module("templates") | |
| 76 | + angular.mock.module("templates"); | |
| 77 | 77 | |
| 78 | 78 | providers((provide: any) => { |
| 79 | 79 | return <any>[ |
| 80 | 80 | provide('ArticleService', { |
| 81 | 81 | useValue: articleService |
| 82 | 82 | }) |
| 83 | - ] | |
| 83 | + ]; | |
| 84 | 84 | }); |
| 85 | 85 | }); |
| 86 | 86 | ... | ... |
src/app/components/noosfero-articles/blog/blog.component.ts
| ... | ... | @@ -13,7 +13,7 @@ export class ArticleBlog { |
| 13 | 13 | @Input() article: noosfero.Article; |
| 14 | 14 | @Input() profile: Profile; |
| 15 | 15 | |
| 16 | - private posts: any[]; | |
| 16 | + private posts: noosfero.Article[]; | |
| 17 | 17 | private perPage: number = 3; |
| 18 | 18 | private currentPage: number; |
| 19 | 19 | private totalPosts: number = 0; |
| ... | ... | @@ -33,9 +33,9 @@ export class ArticleBlog { |
| 33 | 33 | |
| 34 | 34 | this.articleService |
| 35 | 35 | .getChildren(this.article, filters) |
| 36 | - .then((result: noosfero.RestResult<noosfero.Article>) => { | |
| 36 | + .then((result: noosfero.RestResult<noosfero.Article[]>) => { | |
| 37 | 37 | this.totalPosts = <number>result.headers("total"); |
| 38 | - this.posts = <noosfero.Article[]> result.data; | |
| 38 | + this.posts = result.data; | |
| 39 | 39 | }); |
| 40 | 40 | } |
| 41 | 41 | ... | ... |
src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts
| ... | ... | @@ -28,7 +28,7 @@ describe("Components", () => { |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // uses the TestComponentBuilder instance to initialize the component |
| 31 | - //.overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] }) | |
| 31 | + // .overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] }) | |
| 32 | 32 | tcb.createAsync(BlockContainerComponent).then(fixture => { |
| 33 | 33 | // and here we can inspect and run the test assertions |
| 34 | 34 | let myComponent: LinkListBlock = fixture.componentInstance; | ... | ... |
src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts
| ... | ... | @@ -28,14 +28,13 @@ describe("Components", () => { |
| 28 | 28 | // uses the TestComponentBuilder instance to initialize the component |
| 29 | 29 | tcb.createAsync(BlockContainerComponent).then(fixture => { |
| 30 | 30 | // and here we can inspect and run the test assertions |
| 31 | - //let myComponent: MainBlock = fixture.componentInstance; | |
| 31 | + // let myComponent: MainBlock = fixture.componentInstance; | |
| 32 | 32 | |
| 33 | 33 | // assure the block object inside the Block matches |
| 34 | 34 | // the provided through the parent component |
| 35 | - expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1) | |
| 35 | + expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1); | |
| 36 | 36 | done(); |
| 37 | 37 | }); |
| 38 | 38 | }); |
| 39 | - | |
| 40 | 39 | }); |
| 41 | 40 | }); |
| 42 | 41 | \ No newline at end of file | ... | ... |
src/app/components/noosfero-blocks/main-block/main-block.component.ts
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts
| ... | ... | @@ -30,14 +30,14 @@ describe("Components", () => { |
| 30 | 30 | |
| 31 | 31 | it("show image if present", () => { |
| 32 | 32 | helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { |
| 33 | - var elProfile = fixture.debugElement.componentViewChildren[0]; | |
| 33 | + let elProfile = fixture.debugElement.componentViewChildren[0]; | |
| 34 | 34 | expect(elProfile.query('div.profile-image-block').length).toEqual(1); |
| 35 | 35 | }); |
| 36 | 36 | }); |
| 37 | 37 | |
| 38 | 38 | it("has link to the profile", () => { |
| 39 | 39 | helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { |
| 40 | - var elProfile = fixture.debugElement.componentViewChildren[0]; | |
| 40 | + let elProfile = fixture.debugElement.componentViewChildren[0]; | |
| 41 | 41 | expect(elProfile.query('a.settings-link').length).toEqual(1); |
| 42 | 42 | }); |
| 43 | 43 | }); | ... | ... |
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
| ... | ... | @@ -10,30 +10,42 @@ const tcb = new TestComponentBuilder(); |
| 10 | 10 | describe("Components", () => { |
| 11 | 11 | describe("Recent Documents Block Component", () => { |
| 12 | 12 | |
| 13 | + let settingsObj = {}; | |
| 14 | + let mockedArticleService = { | |
| 15 | + getByProfile: (profile: noosfero.Profile, filters: any): any => { | |
| 16 | + return Promise.resolve({ data: [{ name: "article1" }], headers: (name: string) => { return name; } }); | |
| 17 | + } | |
| 18 | + }; | |
| 19 | + let profile = { name: 'profile-name' }; | |
| 13 | 20 | beforeEach(angular.mock.module("templates")); |
| 14 | 21 | |
| 15 | 22 | let state = jasmine.createSpyObj("state", ["go"]); |
| 16 | - let providers = [ | |
| 17 | - new Provider('$state', { useValue: state }), | |
| 18 | - new Provider('ArticleService', { | |
| 19 | - useValue: { | |
| 20 | - getByProfile: (profileId: number, filters: any): any => { | |
| 21 | - return Promise.resolve({ data: [{ name: "article1" }] , headers: (name: string) => {return name;}}); | |
| 22 | - } | |
| 23 | + | |
| 24 | + | |
| 25 | + function getProviders() { | |
| 26 | + return [ | |
| 27 | + new Provider('$state', { useValue: state }), | |
| 28 | + new Provider('ArticleService', { | |
| 29 | + useValue: mockedArticleService | |
| 30 | + }), | |
| 31 | + ].concat(provideFilters("truncateFilter", "stripTagsFilter")); | |
| 32 | + } | |
| 33 | + let componentClass: any = null; | |
| 34 | + | |
| 35 | + function getComponent() { | |
| 36 | + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlock], providers: getProviders() }) | |
| 37 | + class BlockContainerComponent { | |
| 38 | + block = { type: 'Block', settings: settingsObj }; | |
| 39 | + owner = profile; | |
| 40 | + constructor() { | |
| 23 | 41 | } |
| 24 | - }), | |
| 25 | - ].concat(provideFilters("truncateFilter", "stripTagsFilter")); | |
| 26 | - | |
| 27 | - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlock], providers: providers }) | |
| 28 | - class BlockContainerComponent { | |
| 29 | - block = { type: 'Block', settings: {} }; | |
| 30 | - owner = { name: 'profile-name' }; | |
| 31 | - constructor() { | |
| 32 | 42 | } |
| 43 | + return BlockContainerComponent; | |
| 33 | 44 | } |
| 34 | 45 | |
| 46 | + | |
| 35 | 47 | it("get recent documents from the article service", done => { |
| 36 | - tcb.createAsync(BlockContainerComponent).then(fixture => { | |
| 48 | + tcb.createAsync(getComponent()).then(fixture => { | |
| 37 | 49 | let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance; |
| 38 | 50 | expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]); |
| 39 | 51 | done(); |
| ... | ... | @@ -41,7 +53,7 @@ describe("Components", () => { |
| 41 | 53 | }); |
| 42 | 54 | |
| 43 | 55 | it("go to article page when open a document", done => { |
| 44 | - tcb.createAsync(BlockContainerComponent).then(fixture => { | |
| 56 | + tcb.createAsync(getComponent()).then(fixture => { | |
| 45 | 57 | let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance; |
| 46 | 58 | recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); |
| 47 | 59 | expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); |
| ... | ... | @@ -49,5 +61,20 @@ describe("Components", () => { |
| 49 | 61 | }); |
| 50 | 62 | }); |
| 51 | 63 | |
| 64 | + it("it uses default limit 5 if not defined on block", done => { | |
| 65 | + settingsObj = null; | |
| 66 | + mockedArticleService = jasmine.createSpyObj("mockedArticleService", ["getByProfile"]); | |
| 67 | + (<any>mockedArticleService).mocked = true; | |
| 68 | + let thenMocked = jasmine.createSpy("then"); | |
| 69 | + mockedArticleService.getByProfile = jasmine.createSpy("getByProfile").and.returnValue({then: thenMocked}); | |
| 70 | + let getByProfileFunct = mockedArticleService.getByProfile; | |
| 71 | + tcb.createAsync(getComponent()).then(fixture => { | |
| 72 | + let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance; | |
| 73 | + recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); | |
| 74 | + expect(getByProfileFunct).toHaveBeenCalledWith(profile, { content_type: 'TinyMceArticle', per_page: 5 }); | |
| 75 | + done(); | |
| 76 | + }); | |
| 77 | + }); | |
| 78 | + | |
| 52 | 79 | }); |
| 53 | 80 | }); |
| 54 | 81 | \ No newline at end of file | ... | ... |
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
| ... | ... | @@ -23,12 +23,12 @@ export class RecentDocumentsBlock { |
| 23 | 23 | this.profile = this.owner; |
| 24 | 24 | this.documents = []; |
| 25 | 25 | |
| 26 | - let limit = (this.block && this.block.settings) ? this.block.settings.limit : null || 5; | |
| 26 | + let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5; | |
| 27 | 27 | // FIXME get all text articles |
| 28 | 28 | // FIXME make the getByProfile a generic method where we tell the type passing a class TinyMceArticle |
| 29 | 29 | // and the promise should be of type TinyMceArticle[], per example |
| 30 | 30 | this.articleService.getByProfile(this.profile, { content_type: 'TinyMceArticle', per_page: limit }) |
| 31 | - .then((result: noosfero.RestResult<noosfero.Article>) => { | |
| 31 | + .then((result: noosfero.RestResult<noosfero.Article[]>) => { | |
| 32 | 32 | this.documents = <noosfero.Article[]>result.data; |
| 33 | 33 | this.documentsLoaded = true; |
| 34 | 34 | }); | ... | ... |
src/app/components/noosfero-boxes/boxes.component.spec.ts
| ... | ... | @@ -19,8 +19,8 @@ const htmlTemplate: string = '<noosfero-boxes [boxes]="ctrl.boxes" [owner]="ctrl |
| 19 | 19 | describe("Boxes Component", () => { |
| 20 | 20 | |
| 21 | 21 | beforeEach(() => { |
| 22 | - angular.mock.module("templates") | |
| 23 | - }) | |
| 22 | + angular.mock.module("templates"); | |
| 23 | + }); | |
| 24 | 24 | |
| 25 | 25 | @Component({ |
| 26 | 26 | selector: 'test-container-component', |
| ... | ... | @@ -43,8 +43,7 @@ describe("Boxes Component", () => { |
| 43 | 43 | |
| 44 | 44 | it("renders boxes into a container", (done: Function) => { |
| 45 | 45 | createComponentFromClass(BoxesContainerComponent).then((fixture) => { |
| 46 | - | |
| 47 | - var boxesHtml = fixture.debugElement; | |
| 46 | + let boxesHtml = fixture.debugElement; | |
| 48 | 47 | expect(boxesHtml.query('div.col-md-7').length).toEqual(1); |
| 49 | 48 | expect(boxesHtml.query('div.col-md-2-5').length).toEqual(1); |
| 50 | 49 | ... | ... |
src/app/components/noosfero/noosfero-template.filter.ts
| ... | ... | @@ -4,7 +4,7 @@ import {Pipe} from "ng-forward"; |
| 4 | 4 | export class NoosferoTemplate { |
| 5 | 5 | |
| 6 | 6 | transform(text: string, options: any) { |
| 7 | - for (var option in options) { | |
| 7 | + for (let option in options) { | |
| 8 | 8 | text = text.replace('{' + option + '}', options[option]); |
| 9 | 9 | } |
| 10 | 10 | return text; | ... | ... |
src/app/components/noosfero/profile-image/profile-image.component.spec.ts
| ... | ... | @@ -4,42 +4,42 @@ import {Pipe, Input, provide, Component} from 'ng-forward'; |
| 4 | 4 | |
| 5 | 5 | import * as helpers from "./../../../../spec/helpers"; |
| 6 | 6 | |
| 7 | -import {ProfileImage} from "./profile-image.component" | |
| 7 | +import {ProfileImage} from "./profile-image.component"; | |
| 8 | 8 | |
| 9 | 9 | const tcb = new TestComponentBuilder(); |
| 10 | 10 | |
| 11 | 11 | describe("Components", () => { |
| 12 | - | |
| 12 | + | |
| 13 | 13 | describe("Profile Image Component", () => { |
| 14 | 14 | |
| 15 | 15 | beforeEach(angular.mock.module("templates")); |
| 16 | - | |
| 16 | + | |
| 17 | 17 | it("show community users image if profile is not Person", done => { |
| 18 | 18 | helpers.tcb.createAsync(ProfileImage).then(fixture => { |
| 19 | - let profileImageComponent : ProfileImage = fixture.componentInstance | |
| 20 | - let profile = { id: 1, identifier: "myprofile", type: "Community" } | |
| 21 | - profileImageComponent.profile = profile | |
| 19 | + let profileImageComponent: ProfileImage = fixture.componentInstance; | |
| 20 | + let profile = { id: 1, identifier: "myprofile", type: "Community" }; | |
| 21 | + profileImageComponent.profile = profile; | |
| 22 | 22 | profileImageComponent.ngOnInit(); |
| 23 | 23 | |
| 24 | 24 | // Check the attribute |
| 25 | 25 | expect(profileImageComponent.defaultIcon).toBe("fa-users", "The default icon should be community users"); |
| 26 | - //var elProfile = fixture.debugElement.componentViewChildren[0]; | |
| 27 | - //expect(elProfile.query('div.profile-image-block').length).toEqual(1); | |
| 26 | + // var elProfile = fixture.debugElement.componentViewChildren[0]; | |
| 27 | + // expect(elProfile.query('div.profile-image-block').length).toEqual(1); | |
| 28 | 28 | done(); |
| 29 | 29 | }); |
| 30 | 30 | }); |
| 31 | - | |
| 31 | + | |
| 32 | 32 | it("show Person image if profile is Person", done => { |
| 33 | 33 | tcb.createAsync(ProfileImage).then(fixture => { |
| 34 | - let profileImageComponent : ProfileImage = fixture.componentInstance | |
| 35 | - let profile = { id: 1, identifier: "myprofile", type: "Person" } | |
| 36 | - profileImageComponent.profile = profile | |
| 34 | + let profileImageComponent: ProfileImage = fixture.componentInstance; | |
| 35 | + let profile = { id: 1, identifier: "myprofile", type: "Person" }; | |
| 36 | + profileImageComponent.profile = profile; | |
| 37 | 37 | profileImageComponent.ngOnInit(); |
| 38 | 38 | // Check the attribute |
| 39 | 39 | expect(profileImageComponent.defaultIcon).toEqual("fa-user", "The default icon should be person user"); |
| 40 | 40 | done(); |
| 41 | 41 | }); |
| 42 | 42 | }); |
| 43 | - | |
| 43 | + | |
| 44 | 44 | }); |
| 45 | 45 | }); |
| 46 | 46 | \ No newline at end of file | ... | ... |
src/app/components/noosfero/profile-image/profile-image.component.ts
src/app/content-viewer/content-viewer.component.spec.ts
| ... | ... | @@ -14,7 +14,7 @@ describe('Content Viewer Component', () => { |
| 14 | 14 | |
| 15 | 15 | let stateParamsService: any; |
| 16 | 16 | |
| 17 | - //loading the templates | |
| 17 | + // loading the templates | |
| 18 | 18 | beforeEach(() => { |
| 19 | 19 | angular.mock.module("templates"); |
| 20 | 20 | |
| ... | ... | @@ -32,7 +32,7 @@ describe('Content Viewer Component', () => { |
| 32 | 32 | provide('$stateParams', { |
| 33 | 33 | useValue: stateParamsService |
| 34 | 34 | }) |
| 35 | - ] | |
| 35 | + ]; | |
| 36 | 36 | }); |
| 37 | 37 | }); |
| 38 | 38 | |
| ... | ... | @@ -51,7 +51,7 @@ describe('Content Viewer Component', () => { |
| 51 | 51 | expect(fixture.debugElement.query('content-viewer').length).toEqual(1); |
| 52 | 52 | |
| 53 | 53 | done(); |
| 54 | - }) | |
| 54 | + }); | |
| 55 | 55 | }); |
| 56 | 56 | |
| 57 | 57 | it('check if article was loaded', (done: Function) => { |
| ... | ... | @@ -69,7 +69,7 @@ describe('Content Viewer Component', () => { |
| 69 | 69 | return helpers.mocks.promiseResultTemplate(profile); |
| 70 | 70 | }; |
| 71 | 71 | |
| 72 | - helpers.mocks.articleService.getByProfile = (id: number, params: any) => { | |
| 72 | + helpers.mocks.articleService.getOneByProfile = (id: number, params: any) => { | |
| 73 | 73 | return helpers.mocks.promiseResultTemplate({ |
| 74 | 74 | data: article |
| 75 | 75 | }); | ... | ... |
src/app/content-viewer/content-viewer.component.ts
| ... | ... | @@ -30,7 +30,7 @@ export class ContentViewer { |
| 30 | 30 | activate() { |
| 31 | 31 | this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { |
| 32 | 32 | this.profile = profile; |
| 33 | - return this.articleService.getByProfile(<any>this.profile, { path: this.$stateParams["page"] }); | |
| 33 | + return this.articleService.getOneByProfile(<any>this.profile, { path: this.$stateParams["page"] }); | |
| 34 | 34 | }).then((result: noosfero.RestResult<noosfero.Article>) => { |
| 35 | 35 | this.article = <noosfero.Article>result.data; |
| 36 | 36 | }); | ... | ... |
src/lib/ng-noosfero-api/http/article.service.ts
| ... | ... | @@ -36,12 +36,17 @@ export class ArticleService extends RestangularService<noosfero.Article> { |
| 36 | 36 | return rootElement.one(path, id).get<C>(queryParams, headers); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - getByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { | |
| 39 | + getByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article[]>> { | |
| 40 | 40 | let profileElement = this.profileService.get(<number>profile.id); |
| 41 | 41 | return this.list(profileElement, params); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { | |
| 44 | + getOneByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { | |
| 45 | + let profileElement = this.profileService.get(<number>profile.id); | |
| 46 | + return this.get(profile.id, params); | |
| 47 | + } | |
| 48 | + | |
| 49 | + getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article[]>> { | |
| 45 | 50 | return this.listSubElements(article, "children", params); |
| 46 | 51 | } |
| 47 | 52 | ... | ... |
src/lib/ng-noosfero-api/http/restangular_service.spec.ts
| ... | ... | @@ -19,7 +19,7 @@ describe("Restangular Service - base Class", () => { |
| 19 | 19 | return { |
| 20 | 20 | singular: "object", |
| 21 | 21 | plural: "objects" |
| 22 | - } | |
| 22 | + }; | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public getResourcePath() { |
| ... | ... | @@ -32,7 +32,7 @@ describe("Restangular Service - base Class", () => { |
| 32 | 32 | return { |
| 33 | 33 | singular: "rootObject", |
| 34 | 34 | plural: "rootObjects" |
| 35 | - } | |
| 35 | + }; | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public getResourcePath() { |
| ... | ... | @@ -59,7 +59,7 @@ describe("Restangular Service - base Class", () => { |
| 59 | 59 | it("list() calls GET /objects", (done) => { |
| 60 | 60 | $httpBackend.expectGET("/api/v1/objects").respond(200, { objects: [{ id: 1 }, { id: 2 }] }); |
| 61 | 61 | |
| 62 | - objectRestService.list().then((result: noosfero.RestResult<ObjectModel>) => { | |
| 62 | + objectRestService.list().then((result: noosfero.RestResult<ObjectModel[]>) => { | |
| 63 | 63 | expect(result.data).toBeDefined(); |
| 64 | 64 | expect((<ObjectModel[]>result.data).length).toEqual(2); |
| 65 | 65 | done(); |
| ... | ... | @@ -75,7 +75,7 @@ describe("Restangular Service - base Class", () => { |
| 75 | 75 | $httpBackend.expectGET("/api/v1/rootObjects/1/objects").respond(200, { objects: [{ id: 1 }, { id: 2 }] }); |
| 76 | 76 | let rootObj: RootObjectModel = rootObjectRestService.getElement(1); |
| 77 | 77 | |
| 78 | - objectRestService.list(rootObj).then((result: noosfero.RestResult<ObjectModel>) => { | |
| 78 | + objectRestService.list(rootObj).then((result: noosfero.RestResult<ObjectModel[]>) => { | |
| 79 | 79 | expect(result.data).toBeDefined(); |
| 80 | 80 | expect((<ObjectModel[]>result.data).length).toEqual(2); |
| 81 | 81 | done(); | ... | ... |
src/lib/ng-noosfero-api/http/restangular_service.ts
| ... | ... | @@ -104,8 +104,8 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
| 104 | 104 | * @param {number} id (description) |
| 105 | 105 | * @returns {ng.IPromise<T>} Returns a Promise to the Generic Type |
| 106 | 106 | */ |
| 107 | - public list(rootElement?: restangular.IElement, queryParams?: any, headers?: any): ng.IPromise<noosfero.RestResult<T>> { | |
| 108 | - let deferred = this.$q.defer<noosfero.RestResult<T>>(); | |
| 107 | + public list(rootElement?: restangular.IElement, queryParams?: any, headers?: any): ng.IPromise<noosfero.RestResult<T[]>> { | |
| 108 | + let deferred = this.$q.defer<noosfero.RestResult<T[]>>(); | |
| 109 | 109 | |
| 110 | 110 | let restRequest: ng.IPromise<any>; |
| 111 | 111 | |
| ... | ... | @@ -133,7 +133,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
| 133 | 133 | restRequest = obj.all(subElement).get(queryParams, headers); |
| 134 | 134 | restRequest.then(this.getHandleSuccessFunction(deferred)) |
| 135 | 135 | .catch(this.getHandleErrorFunction(deferred)); |
| 136 | - return deferred.promise;; | |
| 136 | + return deferred.promise; | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
| ... | ... | @@ -146,9 +146,9 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | if (rootElement) { |
| 149 | - restangularObj = rootElement.one(this.getResourcePath(), <string>obj.id); | |
| 149 | + restangularObj = rootElement.one(this.getResourcePath(), obj.id); | |
| 150 | 150 | } else { |
| 151 | - restangularObj = this.restangularService.one(this.getResourcePath(), <string>obj.id); | |
| 151 | + restangularObj = this.restangularService.one(this.getResourcePath(), obj.id); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | let deferred = this.$q.defer<noosfero.RestResult<T>>(); |
| ... | ... | @@ -176,9 +176,9 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
| 176 | 176 | let restangularObj: restangular.IElement; |
| 177 | 177 | |
| 178 | 178 | if (rootElement) { |
| 179 | - restangularObj = rootElement.one(this.getResourcePath(), <string>obj.id); | |
| 179 | + restangularObj = rootElement.one(this.getResourcePath(), obj.id); | |
| 180 | 180 | } else { |
| 181 | - restangularObj = this.restangularService.one(this.getResourcePath(), <string>obj.id); | |
| 181 | + restangularObj = this.restangularService.one(this.getResourcePath(), obj.id); | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | restRequest = restangularObj.put(queryParams, headers); |
| ... | ... | @@ -235,7 +235,6 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
| 235 | 235 | self.$log.debug("Request successfull executed", response.data, self, response); |
| 236 | 236 | } |
| 237 | 237 | deferred.resolve(<any>this.extractData(response)); |
| 238 | - //deferred.resolve(this.buildResult(response)); | |
| 239 | 238 | }; |
| 240 | 239 | return successFunction; |
| 241 | 240 | } | ... | ... |
src/lib/ng-noosfero-api/interfaces/articles_result.ts
src/lib/ng-noosfero-api/interfaces/rest_model.ts
src/lib/ng-noosfero-api/interfaces/rest_result.ts
src/spec/mocks.ts
| ... | ... | @@ -50,6 +50,17 @@ export var mocks = { |
| 50 | 50 | } |
| 51 | 51 | }; |
| 52 | 52 | }, |
| 53 | + getOneByProfile: (profileId: number, params?: any) => { | |
| 54 | + return { | |
| 55 | + then: (func?: Function) => { | |
| 56 | + if (func) func({ | |
| 57 | + data: { | |
| 58 | + article: null | |
| 59 | + } | |
| 60 | + }); | |
| 61 | + } | |
| 62 | + }; | |
| 63 | + }, | |
| 53 | 64 | getChildren: (articleId: number, params?: any) => { |
| 54 | 65 | return { |
| 55 | 66 | then: (func?: Function) => { if (func) func(); } |
| ... | ... | @@ -73,7 +84,7 @@ export var mocks = { |
| 73 | 84 | use: (lang?: string) => { |
| 74 | 85 | return lang ? Promise.resolve(lang) : "en"; |
| 75 | 86 | }, |
| 76 | - instant: (text: string) => { return text } | |
| 87 | + instant: (text: string) => { return text; } | |
| 77 | 88 | }, |
| 78 | 89 | tmhDynamicLocale: { |
| 79 | 90 | get: () => { }, | ... | ... |