From e386083ef5e11c4dda623ea53a34d814373e0898 Mon Sep 17 00:00:00 2001 From: Michel Felipe de Oliveira Ferreira - SUPDE/DESDR/DE502 <03385437598@serpro-1552831.(none)> Date: Thu, 31 Mar 2016 09:58:27 -0300 Subject: [PATCH] Fix helpers.ts type problems and added conditional to show profile custom-fields table --- src/app/profile/data/profile-data.component.spec.ts | 10 ++++++++-- src/app/profile/data/profile-data.component.ts | 8 ++++++++ src/app/profile/data/profile-data.html | 2 +- src/spec/helpers.ts | 6 +++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/app/profile/data/profile-data.component.spec.ts b/src/app/profile/data/profile-data.component.spec.ts index 6b9c620..bebaf77 100644 --- a/src/app/profile/data/profile-data.component.spec.ts +++ b/src/app/profile/data/profile-data.component.spec.ts @@ -14,6 +14,7 @@ describe('Profile data component', () => { let profileMock = { id: 1, + name: 'Profile Test', identifier: 'profile-test', type: 'Person' }; @@ -24,7 +25,7 @@ describe('Profile data component', () => { angular.mock.module("angularMoment"); providers((provide: any) => { - return helpers.provideFilters('TranslateProfile', 'translateFilter') + return helpers.provideFilters('TranslateProfile', 'translateFilter'); }); }); @@ -40,6 +41,8 @@ describe('Profile data component', () => { it('renders profile-data directive', () => { buildComponent().then((fixture: ComponentFixture) => { + let profileData: ProfileDataComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + expect(fixture.debugElement.query('div.table-responsive').length).toEqual(1); expect(fixture.debugElement.query('span.label-info').length).toEqual(1); }); @@ -49,8 +52,11 @@ describe('Profile data component', () => { profileMock.additional_data = { 'Address': 'Street A, Number 102' }; - buildComponent().then((fixture: ComponentFixture) => { + let profileData: ProfileDataComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + profileData.profile = profileMock; + + expect(profileData.hasCustomFields()).toBeTruthy(); expect(fixture.debugElement.query('div.profile-custom-fields').length).toEqual(1); }); }); diff --git a/src/app/profile/data/profile-data.component.ts b/src/app/profile/data/profile-data.component.ts index 031f816..2363e89 100644 --- a/src/app/profile/data/profile-data.component.ts +++ b/src/app/profile/data/profile-data.component.ts @@ -12,4 +12,12 @@ export class ProfileDataComponent { @Input() profile: noosfero.Profile; + hasCustomFields(): boolean { + let result: boolean = false; + if (this.profile) + result = (this.profile.additional_data) && Object.keys(this.profile.additional_data).length > 0; + + return result; + } + } diff --git a/src/app/profile/data/profile-data.html b/src/app/profile/data/profile-data.html index 4bdba86..d648d85 100644 --- a/src/app/profile/data/profile-data.html +++ b/src/app/profile/data/profile-data.html @@ -22,7 +22,7 @@ -
+

{{"profile.others_info" | translate}}

diff --git a/src/spec/helpers.ts b/src/spec/helpers.ts index 838562e..d1e4770 100644 --- a/src/spec/helpers.ts +++ b/src/spec/helpers.ts @@ -22,15 +22,15 @@ export function quickCreateComponent({ providers = [], directives = [], template = '
', - properties = {}, + properties = {}, }): Promise { @Component({ selector: 'test', template, directives, providers }) class Test { constructor() { - Object.keys(properties).forEach((key) => { - this[key] = properties[key]; + Object.keys(properties).forEach((key: any) => { + (this)[key] = properties[key]; }); } } -- libgit2 0.21.2