diff --git a/src/app/layout/blocks/statistics/statistics-block.component.spec.ts b/src/app/layout/blocks/statistics/statistics-block.component.spec.ts index eb18139..e40f645 100644 --- a/src/app/layout/blocks/statistics/statistics-block.component.spec.ts +++ b/src/app/layout/blocks/statistics/statistics-block.component.spec.ts @@ -1,36 +1,117 @@ -import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; -import {Component} from 'ng-forward'; - +import {ComponentTestHelper, createClass} from './../../../../spec/component-test-helper'; import {StatisticsBlockComponent} from './statistics-block.component'; - -const tcb = new TestComponentBuilder(); +import * as helpers from "../../../../spec/helpers"; const htmlTemplate: string = ''; describe("Components", () => { describe("Statistics Block Component", () => { - + let helper: ComponentTestHelper; beforeEach(angular.mock.module("templates")); - beforeEach(angular.mock.module("ngSanitize")); - - it("display title stored in block attribute", done => { - @Component({ - selector: 'test-container-component', + beforeEach((done) => { + let cls = createClass({ template: htmlTemplate, directives: [StatisticsBlockComponent], - }) - class CustomBlockType { - block: any = { settings: { user_counter: 'block content' } }; - owner: any = { name: 'profile-name' }; - } - tcb.createAsync(CustomBlockType).then(fixture => { - expect(fixture.debugElement.query(".statistics-block").text().trim()).toEqual('block content'); - done(); + providers: helpers.provideFilters("translateFilter"), + properties: { + block: { + user_counter: 1, users: 10, enterprise_counter: 1, enterprises: 20, + product_counter: 1, products: 30, community_counter: 1, communities: 40, + category_counter: 1, categories: 50, tag_counter: 1, tags: 60, + comment_counter: 1, comments: 70, hit_counter: 1, hits: 80 + } + } + // this.counters.push({ 'should_display': this.block.enterprise_counter, 'value': this.block.enterprises, 'name': 'enterprises' }) + // this.counters.push({ 'should_display': this.block.product_counter, 'value': this.block.products, 'name': 'products' }) + // this.counters.push({ 'should_display': this.block.community_counter, 'value': this.block.communities, 'name': 'communities' }) + // this.counters.push({ 'should_display': this.block.category_counter, 'value': this.block.categories, 'name': 'categories' }) + // this.counters.push({ 'should_display': this.block.tag_counter, 'value': this.block.tags, 'name': 'tags' }) + // this.counters.push({ 'should_display': this.block.comment_counter, 'value': this.block.comments, 'name': 'comments' }) + // this.counters.push({ 'should_display': this.block.hit_counter, 'value': this.block.hits, 'name': 'hits' }) }); + helper = new ComponentTestHelper(cls, done); }); - }); + it("get user counter information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 10, 'name': 'users' }); + }); + + it("get user enterprise information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 20, 'name': 'enterprises' }); + }); + + it("get product counter information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 30, 'name': 'products' }); + }); + + it("get community counter information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 40, 'name': 'communities' }); + }); + + it("get category counter information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 50, 'name': 'categories' }); + }); + it("get tag counter information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 60, 'name': 'tags' }); + }); + + it("get comment counter information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 70, 'name': 'comments' }); + }); + + it("get hit counter information in array", () => { + helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey; }); + expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 80, 'name': 'hits' }); + }); + + it("should render the user count information", () => { + expect(helper.find('.list-group-item.users').length).toEqual(1, "The statistics-block should have a list item with users class"); + }); + + + // it("should not render user count information if has no configuration on block", () => { + // helper.component.counters.forEach((obj: any) => { delete obj.$$hashKey }); + // expect(helper.component.counters).toContain({ 'should_display': 1, 'value': 30, 'name': 'enterprises' }); + // }); + + // this.counters.push({ 'should_display': this.block.enterprise_counter, 'value': this.block.enterprises, 'name': 'enterprises' }) + // this.counters.push({ 'should_display': this.block.product_counter, 'value': this.block.products, 'name': 'products' }) + // this.counters.push({ 'should_display': this.block.community_counter, 'value': this.block.communities, 'name': 'communities' }) + // this.counters.push({ 'should_display': this.block.category_counter, 'value': this.block.categories, 'name': 'categories' }) + // this.counters.push({ 'should_display': this.block.tag_counter, 'value': this.block.tags, 'name': 'tags' }) + // this.counters.push({ 'should_display': this.block.comment_counter, 'value': this.block.comments, 'name': 'comments' }) + // this.counters.push({ 'should_display': this.block.hit_counter, 'value': this.block.hits, 'name': 'hits' }) + + /** + * There are helper functions to access the JQuery DOM like this. + */ + // it("render the profile image for each person", () => { + // expect(helper.all("list-group-item").length).toEqual(3); + // }); + + /** + * The main debugElement element is also available + */ + // it("render the main noosfero people block", () => { + // expect(helper.debugElement.children().length).toEqual(1, "The people-block should have a div children"); + // }); + + /** + * Just another example of a JQuery DOM helper function + */ + // it("render the noosfero people block div", () => { + // let div = helper.findChildren("noosfero-people-block", "div"); + // expect(div.className).toBe('people-block', "The class should be people-block"); + // }); + }); }); diff --git a/src/app/layout/blocks/statistics/statistics-block.component.ts b/src/app/layout/blocks/statistics/statistics-block.component.ts index ad9cda9..71f8b39 100644 --- a/src/app/layout/blocks/statistics/statistics-block.component.ts +++ b/src/app/layout/blocks/statistics/statistics-block.component.ts @@ -1,4 +1,4 @@ -import {Component, Input} from "ng-forward"; +import {Input, Inject, Component} from "ng-forward"; @Component({ selector: "noosfero-statistics-block", @@ -7,12 +7,20 @@ import {Component, Input} from "ng-forward"; export class StatisticsBlockComponent { - @Input() block: any; + @Input() block: noosfero.StatisticsBlock; @Input() owner: any; - html: string; + counters: any = []; ngOnInit() { - this.html = this.block.settings.user_counter; + this.counters.push({ 'should_display': this.block.user_counter, 'value': this.block.users, 'name': 'users' }); + this.counters.push({ 'should_display': this.block.enterprise_counter, 'value': this.block.enterprises, 'name': 'enterprises' }); + this.counters.push({ 'should_display': this.block.product_counter, 'value': this.block.products, 'name': 'products' }); + this.counters.push({ 'should_display': this.block.community_counter, 'value': this.block.communities, 'name': 'communities' }); + this.counters.push({ 'should_display': this.block.category_counter, 'value': this.block.categories, 'name': 'categories' }); + this.counters.push({ 'should_display': this.block.tag_counter, 'value': this.block.tags, 'name': 'tags' }); + this.counters.push({ 'should_display': this.block.comment_counter, 'value': this.block.comments, 'name': 'comments' }); + this.counters.push({ 'should_display': this.block.hit_counter, 'value': this.block.hits, 'name': 'hits' }); + } } diff --git a/src/app/layout/blocks/statistics/statistics-block.html b/src/app/layout/blocks/statistics/statistics-block.html index fac39a9..6ffb45c 100644 --- a/src/app/layout/blocks/statistics/statistics-block.html +++ b/src/app/layout/blocks/statistics/statistics-block.html @@ -1,2 +1,9 @@ -
+
+
    +
  • + {{counter.value}} + {{"statistics." + counter.name | translate}} +
  • + +
diff --git a/src/app/layout/blocks/statistics/statistics.scss b/src/app/layout/blocks/statistics/statistics.scss new file mode 100644 index 0000000..f75bb24 --- /dev/null +++ b/src/app/layout/blocks/statistics/statistics.scss @@ -0,0 +1,3 @@ +.statistics-block { + background-color: blue; +} diff --git a/src/languages/en.json b/src/languages/en.json index 6468ecc..58c4b8a 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -46,5 +46,13 @@ "article.basic_editor.success.message": "Article saved!", "article.basic_editor.visibility": "Visibility", "article.basic_editor.visibility.public": "Public", - "article.basic_editor.visibility.private": "Private" + "article.basic_editor.visibility.private": "Private", + "statistics.users": "Users", + "statistics.enterprises": "Enterprises", + "statistics.products": "Products", + "statistics.communities": "Communities", + "statistics.categories": "Categories", + "statistics.tags": "Tags", + "statistics.comments": "Comments", + "statistics.hits": "Hits" } diff --git a/src/languages/pt.json b/src/languages/pt.json index ee6b6ae..17a82db 100644 --- a/src/languages/pt.json +++ b/src/languages/pt.json @@ -46,5 +46,13 @@ "article.basic_editor.success.message": "Artigo salvo com sucesso!", "article.basic_editor.visibility": "Visibilidade", "article.basic_editor.visibility.public": "Público", - "article.basic_editor.visibility.private": "Privado" + "article.basic_editor.visibility.private": "Privado", + "statistics.users": "Usuários", + "statistics.enterprises": "Empreendimentos", + "statistics.products": "Produtos", + "statistics.communities": "Comunidades", + "statistics.categories": "Categorias", + "statistics.tags": "Tags", + "statistics.comments": "Comentários", + "statistics.hits": "Acessos" } diff --git a/src/lib/ng-noosfero-api/interfaces/statistics_block.ts b/src/lib/ng-noosfero-api/interfaces/statistics_block.ts new file mode 100644 index 0000000..94a97e0 --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/statistics_block.ts @@ -0,0 +1,20 @@ +namespace noosfero { + export interface StatisticsBlock extends Block { + user_counter: boolean; + users: number; + enterprise_counter: boolean; + enterprises: number; + product_counter: boolean; + products: number; + community_counter: boolean; + communities: number; + category_counter: boolean; + categories: number; + tag_counter: boolean; + tags: number; + comment_counter: boolean; + comments: number; + hit_counter: boolean; + hits: number; + } +} -- libgit2 0.21.2