Commit e386083ef5e11c4dda623ea53a34d814373e0898

Authored by Michel Felipe de Oliveira Ferreira - SUPDE/DESDR/DE502
1 parent 5b219f8d
Exists in master and in 1 other branch dev-fixes

Fix helpers.ts type problems and added conditional to show profile custom-fields table

src/app/profile/data/profile-data.component.spec.ts
@@ -14,6 +14,7 @@ describe('Profile data component', () => { @@ -14,6 +14,7 @@ describe('Profile data component', () => {
14 14
15 let profileMock = <noosfero.Profile>{ 15 let profileMock = <noosfero.Profile>{
16 id: 1, 16 id: 1,
  17 + name: 'Profile Test',
17 identifier: 'profile-test', 18 identifier: 'profile-test',
18 type: 'Person' 19 type: 'Person'
19 }; 20 };
@@ -24,7 +25,7 @@ describe(&#39;Profile data component&#39;, () =&gt; { @@ -24,7 +25,7 @@ describe(&#39;Profile data component&#39;, () =&gt; {
24 angular.mock.module("angularMoment"); 25 angular.mock.module("angularMoment");
25 26
26 providers((provide: any) => { 27 providers((provide: any) => {
27 - return <any>helpers.provideFilters('TranslateProfile', 'translateFilter') 28 + return <any>helpers.provideFilters('TranslateProfile', 'translateFilter');
28 }); 29 });
29 }); 30 });
30 31
@@ -40,6 +41,8 @@ describe(&#39;Profile data component&#39;, () =&gt; { @@ -40,6 +41,8 @@ describe(&#39;Profile data component&#39;, () =&gt; {
40 41
41 it('renders profile-data directive', () => { 42 it('renders profile-data directive', () => {
42 buildComponent().then((fixture: ComponentFixture) => { 43 buildComponent().then((fixture: ComponentFixture) => {
  44 + let profileData: ProfileDataComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
  45 +
43 expect(fixture.debugElement.query('div.table-responsive').length).toEqual(1); 46 expect(fixture.debugElement.query('div.table-responsive').length).toEqual(1);
44 expect(fixture.debugElement.query('span.label-info').length).toEqual(1); 47 expect(fixture.debugElement.query('span.label-info').length).toEqual(1);
45 }); 48 });
@@ -49,8 +52,11 @@ describe(&#39;Profile data component&#39;, () =&gt; { @@ -49,8 +52,11 @@ describe(&#39;Profile data component&#39;, () =&gt; {
49 profileMock.additional_data = { 52 profileMock.additional_data = {
50 'Address': 'Street A, Number 102' 53 'Address': 'Street A, Number 102'
51 }; 54 };
52 -  
53 buildComponent().then((fixture: ComponentFixture) => { 55 buildComponent().then((fixture: ComponentFixture) => {
  56 + let profileData: ProfileDataComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
  57 + profileData.profile = profileMock;
  58 +
  59 + expect(profileData.hasCustomFields()).toBeTruthy();
54 expect(fixture.debugElement.query('div.profile-custom-fields').length).toEqual(1); 60 expect(fixture.debugElement.query('div.profile-custom-fields').length).toEqual(1);
55 }); 61 });
56 }); 62 });
src/app/profile/data/profile-data.component.ts
@@ -12,4 +12,12 @@ export class ProfileDataComponent { @@ -12,4 +12,12 @@ export class ProfileDataComponent {
12 @Input() 12 @Input()
13 profile: noosfero.Profile; 13 profile: noosfero.Profile;
14 14
  15 + hasCustomFields(): boolean {
  16 + let result: boolean = false;
  17 + if (this.profile)
  18 + result = (this.profile.additional_data) && Object.keys(this.profile.additional_data).length > 0;
  19 +
  20 + return result;
  21 + }
  22 +
15 } 23 }
src/app/profile/data/profile-data.html
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 </div> 22 </div>
23 23
24 <!-- Custom Fields --> 24 <!-- Custom Fields -->
25 -<div class="main-box clearfix profile-custom-fields" ng-if="ctrl.profile.additional_data"> 25 +<div class="main-box clearfix profile-custom-fields" ng-if="ctrl.hasCustomFields()">
26 <header class="main-box-header clearfix"> 26 <header class="main-box-header clearfix">
27 <h2>{{"profile.others_info" | translate}}</h2> 27 <h2>{{"profile.others_info" | translate}}</h2>
28 </header> 28 </header>
src/spec/helpers.ts
@@ -22,15 +22,15 @@ export function quickCreateComponent({ @@ -22,15 +22,15 @@ export function quickCreateComponent({
22 providers = [], 22 providers = [],
23 directives = [], 23 directives = [],
24 template = '<div></div>', 24 template = '<div></div>',
25 - properties = {}, 25 + properties = <any>{},
26 }): Promise<ComponentFixture> { 26 }): Promise<ComponentFixture> {
27 27
28 @Component({ selector: 'test', template, directives, providers }) 28 @Component({ selector: 'test', template, directives, providers })
29 class Test { 29 class Test {
30 30
31 constructor() { 31 constructor() {
32 - Object.keys(properties).forEach((key) => {  
33 - this[key] = properties[key]; 32 + Object.keys(properties).forEach((key: any) => {
  33 + (<any>this)[key] = <any>properties[key];
34 }); 34 });
35 } 35 }
36 } 36 }