Commit b0b90c135076e6d4f66034cf92a2b342aa5fc60b
Exists in
master
and in
34 other branches
Merge branch 'ngforward' of softwarepublico.gov.br:noosfero-themes/angular-theme into ngforward
Conflicts: src/app/components/noosfero-articles/blog/blog.component.ts src/app/content-viewer/content-viewer.component.ts src/lib/ng-noosfero-api/http/article.service.ts
Showing
12 changed files
with
183 additions
and
36 deletions
Show diff stats
... | ... | @@ -0,0 +1,33 @@ |
1 | +"use strict"; | |
2 | +var path = require("path"); | |
3 | +var fs = require("fs"); | |
4 | +var remapIstanbul = require("remap-istanbul"); | |
5 | +var coveragePath = path.join(__dirname, "..", "coverage"); | |
6 | +console.log("COVERAGE PATH:", coveragePath); | |
7 | +fs.readdir(coveragePath, function (err, directories) { | |
8 | + if (err) { | |
9 | + console.error(err.message); | |
10 | + throw err; | |
11 | + } | |
12 | + directories.map(function (file) { | |
13 | + return path.join(coveragePath, file); | |
14 | + }).forEach(function (coverageFolder) { | |
15 | + var coverageFile = path.join(coverageFolder, "coverage-final.json"); | |
16 | + var replace = require("replace"); | |
17 | + var absoluteProjectPath = path.join(__dirname, "../"); | |
18 | + var loadCoverage = require('remap-istanbul/lib/loadCoverage'); | |
19 | + var remap = require('remap-istanbul/lib/remap'); | |
20 | + var writeReport = require('remap-istanbul/lib/writeReport'); | |
21 | + var collector = remap(loadCoverage(coverageFile), {}); | |
22 | + var Store = require("istanbul").Store; | |
23 | + var store = Store.create("fslookup"); | |
24 | + store.get = function (key) { | |
25 | + var pathNormalized = key.replace("src/webpack:/", ""); | |
26 | + pathNormalized = pathNormalized.replace(/\.ts\?(\w+)/, ".ts"); | |
27 | + return fs.readFileSync(pathNormalized, 'utf8'); | |
28 | + }; | |
29 | + writeReport(collector, 'html', coverageFolder, store); | |
30 | + writeReport(collector, 'json', path.join(coverageFolder, 'coverage-final-remaped.json'), store); | |
31 | + }); | |
32 | +}); | |
33 | +//# sourceMappingURL=remapCoverage.js.map | |
0 | 34 | \ No newline at end of file | ... | ... |
... | ... | @@ -0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;QAEH,IAAI,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC;QACtC,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACrC,KAAK,CAAC,GAAG,GAAG,UAAS,GAAG;YACpB,IAAI,cAAc,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;YACtD,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YAC9D,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACnD,CAAC,CAAA;QACD,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;QACtD,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,6BAA6B,CAAC,EAAE,KAAK,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;AAEP,CAAC,CAAC,CAAC"} | |
0 | 2 | \ No newline at end of file | ... | ... |
dev-scripts/remapCoverage.ts
1 | 1 | /** |
2 | 2 | * @script remap-coverage.ts |
3 | - * | |
3 | + * | |
4 | 4 | * Esse script serve para transformar as informações de cobertura geradas pelo karma-coverage |
5 | 5 | * e que originalmente é construída apontando para os arquivos javascript (já que os testes são executados em javascript) |
6 | 6 | * para a informação de cobertura apontando para os arquivos Typescript, utilizando os source maps gerados pelo compilador |
7 | 7 | * typescript |
8 | 8 | * @author: Abner Oliveira |
9 | - * | |
9 | + * | |
10 | 10 | * Examplo de uso: |
11 | - * | |
11 | + * | |
12 | 12 | * Na linha de comando, na pasta raiz do projeto, digite: |
13 | - * | |
13 | + * | |
14 | 14 | * ts-node dev-scripts/remap-coverage.ts |
15 | - * | |
15 | + * | |
16 | 16 | * Observação: O karma já deve ter sido executado antes, e a pasta de coverage deve ser "./coverage" |
17 | 17 | */ |
18 | 18 | |
... | ... | @@ -26,10 +26,10 @@ let coveragePath = path.join(__dirname, "..", "coverage"); |
26 | 26 | |
27 | 27 | // o pré-processador "coverage" do runner de tests "karma" gera uma pasta |
28 | 28 | // de coverage para cada browser em que os testes foram executados |
29 | -// iteraremos arqui então entre essas pastas para realizar o remap de cada uma | |
29 | +// iteraremos arqui então entre essas pastas para realizar o remap de cada uma | |
30 | 30 | |
31 | 31 | console.log("COVERAGE PATH:", coveragePath); |
32 | -// lendo o diretório coveragePath | |
32 | +// lendo o diretório coveragePath | |
33 | 33 | fs.readdir(coveragePath, (err, directories) => { |
34 | 34 | if (err) { |
35 | 35 | console.error(err.message); |
... | ... | @@ -57,17 +57,17 @@ fs.readdir(coveragePath, (err, directories) => { |
57 | 57 | // gerando dois reports: JSON e HTML |
58 | 58 | // remapIstanbul(coverageFile, |
59 | 59 | // { |
60 | - // "exclude": | |
60 | + // "exclude": | |
61 | 61 | // "json": path.join(coverageFolder, "coverage-final-remaped.json") |
62 | 62 | // }); |
63 | - | |
63 | + | |
64 | 64 | // replace({ |
65 | 65 | // regex: "src/webpack:/", |
66 | 66 | // replacement: "", |
67 | 67 | // paths: [coverageFile], |
68 | 68 | // sillent: true |
69 | 69 | // }); |
70 | - | |
70 | + | |
71 | 71 | let loadCoverage = require('remap-istanbul/lib/loadCoverage'); |
72 | 72 | let remap = require('remap-istanbul/lib/remap'); |
73 | 73 | let writeReport = require('remap-istanbul/lib/writeReport'); |
... | ... | @@ -90,13 +90,11 @@ fs.readdir(coveragePath, (err, directories) => { |
90 | 90 | let store = Store.create("fslookup"); |
91 | 91 | store.get = function(key) { |
92 | 92 | let pathNormalized = key.replace("src/webpack:/", ""); |
93 | - console.error("PATH >>> ", pathNormalized); | |
94 | 93 | pathNormalized = pathNormalized.replace(/\.ts\?(\w+)/, ".ts"); |
95 | - console.log("my store got called!", key, pathNormalized); | |
96 | 94 | return fs.readFileSync(pathNormalized, 'utf8'); |
97 | 95 | } |
98 | 96 | writeReport(collector, 'html', coverageFolder, store); |
99 | 97 | writeReport(collector, 'json', path.join(coverageFolder, 'coverage-final-remaped.json'), store); |
100 | 98 | }); |
101 | 99 | |
102 | -}); | |
103 | 100 | \ No newline at end of file |
101 | +}); | ... | ... |
karma.conf.js
... | ... | @@ -89,7 +89,7 @@ var webpackConfig = require("./webpack.config.js"); |
89 | 89 | module.exports = function (config) { |
90 | 90 | |
91 | 91 | var configuration = { |
92 | - basePath: '../angular-theme', | |
92 | + basePath: './', | |
93 | 93 | |
94 | 94 | files: listFiles(), |
95 | 95 | |
... | ... | @@ -144,14 +144,14 @@ module.exports = function (config) { |
144 | 144 | } |
145 | 145 | };*/ |
146 | 146 | /*configuration.webpack = _.merge({ |
147 | - | |
147 | + | |
148 | 148 | }, webpackConfig, { |
149 | 149 | devtool: 'source-map' |
150 | 150 | }), |
151 | 151 | configuration.webpackServer = { |
152 | 152 | quite: true |
153 | 153 | };*/ |
154 | - | |
154 | + | |
155 | 155 | // This is the default preprocessors configuration for a usage with Karma cli |
156 | 156 | // The coverage preprocessor is added in gulp/unit-test.js only for single tests |
157 | 157 | // It was not possible to do it there because karma doesn't let us now if we are | ... | ... |
package.json
... | ... | @@ -7,6 +7,8 @@ |
7 | 7 | "moment": "^2.11.2" |
8 | 8 | }, |
9 | 9 | "scripts": { |
10 | + "webpack": "webpack", | |
11 | + "karma": "karma", | |
10 | 12 | "coverage": "karma start --single-run; npm run remap-coverage", |
11 | 13 | "remap-coverage": "ts-node --project ./dev-scripts ./dev-scripts/remapCoverage.ts", |
12 | 14 | "test-single": "karma start --single-run", | ... | ... |
src/app/components/navbar/navbar.spec.ts
... | ... | @@ -113,10 +113,8 @@ describe("Components", () => { |
113 | 113 | directives: [Navbar] |
114 | 114 | }) |
115 | 115 | .then(fixture => { |
116 | - console.log("entrou no .then") | |
117 | 116 | let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; |
118 | 117 | spyOn($modal, "open"); |
119 | - //navbarComp.activate(); | |
120 | 118 | navbarComp.openLogin(); |
121 | 119 | expect($modal.open).toHaveBeenCalled(); |
122 | 120 | expect($modal.open).toHaveBeenCalledWith({ | ... | ... |
src/app/components/noosfero-articles/article/article_view.ts
1 | 1 | import { bundle, Input, Inject, Component, Directive } from 'ng-forward'; |
2 | -import {NoosferoArticleBlog} from "../blog/blog.component"; | |
2 | +import {ArticleBlog} from "../blog/blog.component"; | |
3 | 3 | |
4 | 4 | @Component({ |
5 | 5 | selector: 'noosfero-default-article', |
... | ... | @@ -15,7 +15,7 @@ export class ArticleDefaultView { |
15 | 15 | @Component({ |
16 | 16 | selector: 'noosfero-article', |
17 | 17 | template: 'not-used', |
18 | - directives: [ArticleDefaultView, NoosferoArticleBlog] | |
18 | + directives: [ArticleDefaultView, ArticleBlog] | |
19 | 19 | }) |
20 | 20 | @Inject("$element", "$scope", "$injector", "$compile") |
21 | 21 | export class ArticleView { | ... | ... |
src/app/components/noosfero-articles/blog/blog.component.spec.ts
0 → 100644
... | ... | @@ -0,0 +1,114 @@ |
1 | + | |
2 | +import {Input, provide, Component} from 'ng-forward'; | |
3 | +import {ArticleBlog} from './blog.component'; | |
4 | + | |
5 | +import {createComponentFromClass, quickCreateComponent, provideEmptyObjects, createProviderToValue} from "../../../../spec/helpers.ts"; | |
6 | + | |
7 | + | |
8 | +// this htmlTemplate will be re-used between the container components in this spec file | |
9 | +const htmlTemplate: string = '<noosfero-blog [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-blog>'; | |
10 | +let articleService = {}; | |
11 | + | |
12 | +describe("Blog Component", () => { | |
13 | + | |
14 | + // the karma preprocessor html2js transform the templates html into js files which put | |
15 | + // the templates to the templateCache into the module templates | |
16 | + // we need to load the module templates here as the template for the | |
17 | + // component Noosfero ArtileView will be load on our tests | |
18 | + beforeEach(angular.mock.module("templates")); | |
19 | + | |
20 | + function promiseResultTemplate(thenFunc: Function) { | |
21 | + let thenFuncEmpty = (func: Function) => { | |
22 | + // does nothing | |
23 | + //func() | |
24 | + }; | |
25 | + if (thenFunc) { | |
26 | + return { | |
27 | + then: thenFunc | |
28 | + } | |
29 | + } else { | |
30 | + return { | |
31 | + then: thenFuncEmpty | |
32 | + } | |
33 | + } | |
34 | + } | |
35 | + | |
36 | + beforeAll(() => { | |
37 | + // creating mock for articleService | |
38 | + articleService = { | |
39 | + getChildren: (article_id: number, filters: {}) => { | |
40 | + return promiseResultTemplate(); | |
41 | + } | |
42 | + }; | |
43 | + }); | |
44 | + | |
45 | + it("renders the blog content", (done: Function) => { | |
46 | + | |
47 | + // Creating a container component (ArticleContainerComponent) to include | |
48 | + // the component under test (ArticleView) | |
49 | + @Component({ | |
50 | + selector: 'test-container-component', | |
51 | + template: htmlTemplate, | |
52 | + directives: [ArticleBlog], | |
53 | + providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] | |
54 | + }) | |
55 | + class BlogContainerComponent { | |
56 | + article = { type: 'anyArticleType' }; | |
57 | + profile = { name: 'profile-name' }; | |
58 | + } | |
59 | + | |
60 | + createComponentFromClass(BlogContainerComponent).then((fixture) => { | |
61 | + | |
62 | + expect(fixture.debugElement.query('div.blog').length).toEqual(1); | |
63 | + | |
64 | + done(); | |
65 | + }); | |
66 | + | |
67 | + it("verify the blog data", (done: Function) => { | |
68 | + | |
69 | + articleService.getChildren = (article_id: number, filters: {}) => { | |
70 | + return promiseResultTemplate(() => { | |
71 | + return { | |
72 | + headers: { | |
73 | + total: 1 | |
74 | + }, | |
75 | + data: { | |
76 | + articles: [ | |
77 | + ] | |
78 | + } | |
79 | + } | |
80 | + }); | |
81 | + } | |
82 | + @Component({ | |
83 | + selector: 'test-container-component', | |
84 | + template: htmlTemplate, | |
85 | + directives: [ArticleBlog], | |
86 | + providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] | |
87 | + }) | |
88 | + class BlogContainerComponent { | |
89 | + article = { type: 'anyArticleType' }; | |
90 | + profile = { name: 'profile-name' }; | |
91 | + } | |
92 | + | |
93 | + createComponentFromClass(BlogContainerComponent).then((fixture) => { | |
94 | + // and here we can inspect and run the test assertions | |
95 | + | |
96 | + // gets the children component of ArticleContainerComponent | |
97 | + let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | |
98 | + | |
99 | + // and checks if the article View rendered was the Default Article View | |
100 | + //expect(articleView.constructor.prototype).toEqual(ArticleDefaultView.prototype); | |
101 | + expect(articleBlog["posts"]).toEqual([]); | |
102 | + expect(articleBlog["totalPosts"]).toEqual(1); | |
103 | + | |
104 | + | |
105 | + // done needs to be called (it isn't really needed, as we can read in | |
106 | + // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync) | |
107 | + // because createAsync in ng-forward is not really async, but as the intention | |
108 | + // here is write tests in angular 2 ways, this is recommended | |
109 | + done(); | |
110 | + }); | |
111 | + | |
112 | + }); | |
113 | + | |
114 | + }); | ... | ... |
src/app/components/noosfero-articles/blog/blog.component.ts
... | ... | @@ -7,8 +7,8 @@ import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.servi |
7 | 7 | selector: "noosfero-blog", |
8 | 8 | templateUrl: "app/components/noosfero-articles/blog/blog.html" |
9 | 9 | }) |
10 | -@Inject(ArticleService, "$scope") | |
11 | -export class NoosferoArticleBlog { | |
10 | +@Inject(ArticleService) | |
11 | +export class ArticleBlog { | |
12 | 12 | |
13 | 13 | @Input() article: Article; |
14 | 14 | @Input() profile: Profile; |
... | ... | @@ -18,22 +18,25 @@ export class NoosferoArticleBlog { |
18 | 18 | private currentPage: number; |
19 | 19 | private totalPosts: number = 0; |
20 | 20 | |
21 | - constructor(private ArticleService: ArticleService, private $scope: ng.IScope) { | |
22 | - } | |
21 | + constructor(private articleService: ArticleService) { } | |
23 | 22 | |
24 | 23 | ngOnInit() { |
25 | 24 | this.loadPage(); |
26 | 25 | } |
27 | 26 | |
28 | 27 | loadPage() { |
29 | - this.ArticleService.getChildren(this.article.id, { | |
28 | + let filters = { | |
30 | 29 | content_type: "TinyMceArticle", |
31 | 30 | per_page: this.perPage, |
32 | 31 | page: this.currentPage |
33 | - }).then((response: restangular.IResponse) => { | |
34 | - this.totalPosts = <number>(<any>response.headers("total")); | |
35 | - this.posts = response.data.articles; | |
36 | - }); | |
32 | + }; | |
33 | + | |
34 | + this.articleService | |
35 | + .getChildren(this.article.id, filters) | |
36 | + .then((response: restangular.IResponse) => { | |
37 | + this.totalPosts = <number>(<any>response.headers("total")); | |
38 | + this.posts = response.data.articles; | |
39 | + }); | |
37 | 40 | } |
38 | 41 | |
39 | 42 | } | ... | ... |
src/app/content-viewer/content-viewer.component.ts
... | ... | @@ -4,13 +4,13 @@ import * as noosfero from "../models/interfaces"; |
4 | 4 | import {ArticleView} from "../components/noosfero-articles/article/article_view"; |
5 | 5 | import {Input, Component, StateConfig, Inject} from "ng-forward"; |
6 | 6 | |
7 | -import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; | |
7 | +import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; | |
8 | 8 | import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; |
9 | 9 | |
10 | 10 | @Component({ |
11 | 11 | selector: "content-viewer", |
12 | 12 | templateUrl: "app/content-viewer/page.html", |
13 | - directives: [NoosferoArticleBlog, ArticleView] | |
13 | + directives: [ArticleBlog, ArticleView] | |
14 | 14 | }) |
15 | 15 | @Inject(ArticleService, "noosfero", "$log", "$stateParams") |
16 | 16 | export class ContentViewer { | ... | ... |
src/app/main/main.component.ts
1 | 1 | import {bundle, Component, StateConfig} from "ng-forward"; |
2 | -import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; | |
2 | +import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; | |
3 | 3 | |
4 | 4 | import {ArticleView} from "../components/noosfero-articles/article/article_view"; |
5 | 5 | |
... | ... | @@ -34,7 +34,7 @@ export class MainContent { |
34 | 34 | selector: 'main', |
35 | 35 | template: '<div ng-view></div>', |
36 | 36 | directives: [ |
37 | - NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, | |
37 | + ArticleBlog, ArticleView, Boxes, Block, LinkListBlock, | |
38 | 38 | MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, |
39 | 39 | MembersBlock, NoosferoTemplate |
40 | 40 | ], | ... | ... |
src/lib/ng-noosfero-api/http/article.service.ts
... | ... | @@ -5,9 +5,7 @@ import {Article} from "../../../app/models/interfaces"; |
5 | 5 | @Inject("Restangular") |
6 | 6 | export class ArticleService { |
7 | 7 | |
8 | - constructor(private Restangular: any) { | |
9 | - | |
10 | - } | |
8 | + constructor(private Restangular: any) { } | |
11 | 9 | |
12 | 10 | create(profileId: number, article: Article) { |
13 | 11 | return this.Restangular.one('profiles', profileId).customPOST( | ... | ... |