From 734ad25f6107d6f09737e3dc4edf44d0c2d30651 Mon Sep 17 00:00:00 2001 From: Caio SBA Date: Wed, 6 Jul 2016 17:25:57 -0300 Subject: [PATCH] [WIP] Ticket #76: Recent activities block: Tests, CSS and templates infrastructure (with already two templates implemented) --- src/app/layout/blocks/recent-activities-plugin-activities/activities/create_article.html | 1 + src/app/layout/blocks/recent-activities-plugin-activities/activities/new_friendship.html | 6 ++++++ src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.spec.ts | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.ts | 23 +++++++++++++++++------ src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.html | 23 ++++++++++++----------- src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.scss | 9 +++++++++ 6 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 src/app/layout/blocks/recent-activities-plugin-activities/activities/create_article.html create mode 100644 src/app/layout/blocks/recent-activities-plugin-activities/activities/new_friendship.html diff --git a/src/app/layout/blocks/recent-activities-plugin-activities/activities/create_article.html b/src/app/layout/blocks/recent-activities-plugin-activities/activities/create_article.html new file mode 100644 index 0000000..85c923b --- /dev/null +++ b/src/app/layout/blocks/recent-activities-plugin-activities/activities/create_article.html @@ -0,0 +1 @@ +{{'published an article:' | translate}} {{activity.params.name}} diff --git a/src/app/layout/blocks/recent-activities-plugin-activities/activities/new_friendship.html b/src/app/layout/blocks/recent-activities-plugin-activities/activities/new_friendship.html new file mode 100644 index 0000000..766124e --- /dev/null +++ b/src/app/layout/blocks/recent-activities-plugin-activities/activities/new_friendship.html @@ -0,0 +1,6 @@ +{{'has made new friends:' | translate}}
+ + + + + diff --git a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.spec.ts b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.spec.ts index 70b786d..ecf7c72 100644 --- a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.spec.ts +++ b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.spec.ts @@ -1 +1,56 @@ -// TODO +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; +import {Provider, Input, provide, Component} from 'ng-forward'; +import {provideFilters} from '../../../../spec/helpers'; +import {RecentActivitiesPluginActivitiesBlockComponent} from './recent-activities-plugin-activities-block.component'; +import * as helpers from "./../../../../spec/helpers"; + +const htmlTemplate: string = ''; + +const tcb = new TestComponentBuilder(); + +describe("Components", () => { + describe("Recent Activities Block Component", () => { + + let settingsObj = {}; + let person = { name: "Person" }; + let mockedService = { + getApiContent: (block: noosfero.Block): any => { + return Promise.resolve({ activities: [{ verb: 'new_friendship' }], headers: (name: string) => { return name; } }); + } + }; + beforeEach(angular.mock.module("templates")); + + let state = jasmine.createSpyObj("state", ["go"]); + + + function getProviders() { + return [ + new Provider('$state', { useValue: state }), + new Provider('BlockService', { + useValue: mockedService + }) + ].concat(provideFilters("truncateFilter", "stripTagsFilter")); + } + let componentClass: any = null; + + function getComponent() { + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentActivitiesPluginActivitiesBlockComponent], providers: getProviders() }) + class BlockContainerComponent { + block = { type: 'Block', settings: settingsObj }; + owner = person; + constructor() { + } + } + return BlockContainerComponent; + } + + it("get activities from block service", done => { + tcb.createAsync(getComponent()).then(fixture => { + let RecentActivitiesPluginActivitiesBlock: RecentActivitiesPluginActivitiesBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + expect(RecentActivitiesPluginActivitiesBlock.activities[0]['verb']).toEqual('new_friendship'); + done(); + }); + }); + + }); +}); diff --git a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.ts b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.ts index a6680c2..4450af3 100644 --- a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.ts +++ b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.component.ts @@ -17,16 +17,27 @@ export class RecentActivitiesPluginActivitiesBlockComponent { constructor(private blockService: BlockService, private $state: any) { } + getActivityTemplate(activity: any) { + return 'app/layout/blocks/recent-activities-plugin-activities/activities/' + activity.verb + '.html'; + } + + urlFor(params: any) { + let url = '//' + params.host; + if (params.port) { + url += ':' + params.port; + } + url += '/' + params.profile + '/'; + if (params.page) { + url += params.page.join('/'); + } + return url; + } + ngOnInit() { this.profile = this.owner; this.activities = []; this.blockService.getApiContent(this.block).then((content: any) => { - let activities: any = []; - for (let i = 0; i < content.activities.length; i++) { - let activity = content.activities[i]; - activities.push({ created_at: activity.created_at, description: 'TODO' }); - } - this.activities = activities.slice(); + this.activities = content.activities; }); } } diff --git a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.html b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.html index 70a5b5a..b9a1500 100644 --- a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.html +++ b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.html @@ -1,13 +1,14 @@ -
-
-
-
- -
- - - -
-
+
+
+ +
+ + + +
diff --git a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.scss b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.scss index 12357aa..b357d62 100644 --- a/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.scss +++ b/src/app/layout/blocks/recent-activities-plugin-activities/recent-activities-plugin-activities-block.scss @@ -1,3 +1,12 @@ .col-md-2-5 .deckgrid[deckgrid]::before { visibility: hidden; } + +.recent-activities-block { + img { + padding: 1px; + border: 1px solid #ccc; + margin-right: 2px; + margin-top: 2px; + } +} -- libgit2 0.21.2