Commit e386083ef5e11c4dda623ea53a34d814373e0898
1 parent
5b219f8d
Exists in
master
and in
30 other branches
Fix helpers.ts type problems and added conditional to show profile custom-fields table
Showing
4 changed files
with
20 additions
and
6 deletions
Show diff stats
src/app/profile/data/profile-data.component.spec.ts
| ... | ... | @@ -14,6 +14,7 @@ describe('Profile data component', () => { |
| 14 | 14 | |
| 15 | 15 | let profileMock = <noosfero.Profile>{ |
| 16 | 16 | id: 1, |
| 17 | + name: 'Profile Test', | |
| 17 | 18 | identifier: 'profile-test', |
| 18 | 19 | type: 'Person' |
| 19 | 20 | }; |
| ... | ... | @@ -24,7 +25,7 @@ describe('Profile data component', () => { |
| 24 | 25 | angular.mock.module("angularMoment"); |
| 25 | 26 | |
| 26 | 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('Profile data component', () => { |
| 40 | 41 | |
| 41 | 42 | it('renders profile-data directive', () => { |
| 42 | 43 | buildComponent().then((fixture: ComponentFixture) => { |
| 44 | + let profileData: ProfileDataComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | |
| 45 | + | |
| 43 | 46 | expect(fixture.debugElement.query('div.table-responsive').length).toEqual(1); |
| 44 | 47 | expect(fixture.debugElement.query('span.label-info').length).toEqual(1); |
| 45 | 48 | }); |
| ... | ... | @@ -49,8 +52,11 @@ describe('Profile data component', () => { |
| 49 | 52 | profileMock.additional_data = { |
| 50 | 53 | 'Address': 'Street A, Number 102' |
| 51 | 54 | }; |
| 52 | - | |
| 53 | 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 | 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 | 12 | @Input() |
| 13 | 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 | 22 | </div> |
| 23 | 23 | |
| 24 | 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 | 26 | <header class="main-box-header clearfix"> |
| 27 | 27 | <h2>{{"profile.others_info" | translate}}</h2> |
| 28 | 28 | </header> | ... | ... |
src/spec/helpers.ts
| ... | ... | @@ -22,15 +22,15 @@ export function quickCreateComponent({ |
| 22 | 22 | providers = [], |
| 23 | 23 | directives = [], |
| 24 | 24 | template = '<div></div>', |
| 25 | - properties = {}, | |
| 25 | + properties = <any>{}, | |
| 26 | 26 | }): Promise<ComponentFixture> { |
| 27 | 27 | |
| 28 | 28 | @Component({ selector: 'test', template, directives, providers }) |
| 29 | 29 | class Test { |
| 30 | 30 | |
| 31 | 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 | } | ... | ... |