From b1d1976f1817953ecf814e872bea3773d72303ee Mon Sep 17 00:00:00 2001 From: mihai sirghe <32762007+smihai78@users.noreply.github.com> Date: Wed, 1 Nov 2017 16:35:23 +0200 Subject: [PATCH] [ADF-1772] fix for application name title translation (#2572) * fix for ADF-1772 Enabling translation for application-list-component title * [ADF-1772] fix translation for default application name added unit tests for checking this fix --- .../src/components/apps-list.component.html | 6 ++--- .../components/apps-list.component.spec.ts | 24 +++++++++++++++++++ .../src/components/apps-list.component.ts | 24 ++++++++++++++----- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.html b/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.html index b304ea3918..440522ea05 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.html +++ b/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.html @@ -2,7 +2,7 @@ touch_app - {{app.name}} + {{getAppName(app) | async}}
@@ -13,7 +13,7 @@ fxLayout="column" role="button" class="adf-app-listgrid-item-card" - title="{{app.name}}" + title="{{getAppName(app) | async}}" [ngClass]="[getTheme(app)]" (click)="selectApp(app)" (keyup.enter)="selectApp(app)"> @@ -21,7 +21,7 @@ {{getBackgroundIcon(app)}}
-

{{app.name | translate}}

+

{{getAppName(app) | async}}

{{app.description}}

diff --git a/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.spec.ts index ed3b34c3c5..5f821e9409 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.spec.ts @@ -129,6 +129,30 @@ describe('AppsListComponent', () => { expect(emitSpy).toHaveBeenCalled(); }); + describe('intenationalization', () => { + + fit('should provide a translation for the default application name, when app name is not provided', () => { + const appDataMock = { + defaultAppId: 'tasks', + name: null + }; + component.getAppName(appDataMock).subscribe((name) => { + expect(name).toBe('ADF_TASK_LIST.APPS.TASK_APP_NAME'); + }); + }); + + fit('should provide the application name, when it exists', () => { + const appDataMock = { + defaultAppId: 'uiu', + name: 'the-name' + }; + + component.getAppName(appDataMock).subscribe((name) => { + expect(name).toBe(appDataMock.name); + }); + }); + }); + describe('layout', () => { it('should display a grid by default', () => { diff --git a/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.ts index 0cf68bcae5..d85856733a 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/apps-list.component.ts @@ -16,7 +16,7 @@ */ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { AppsProcessService } from 'ng2-alfresco-core'; +import { AppsProcessService, TranslationService } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Observable'; import { Observer } from 'rxjs/Observer'; import { AppDefinitionRepresentationModel } from '../models/filter.model'; @@ -60,8 +60,10 @@ export class AppsListComponent implements OnInit { private iconsMDL: IconModel; - constructor(private appsProcessService: AppsProcessService) { - this.apps$ = new Observable(observer => this.appsObserver = observer).share(); + constructor( + private appsProcessService: AppsProcessService, + private translationService: TranslationService) { + this.apps$ = new Observable(observer => this.appsObserver = observer).share(); } ngOnInit() { @@ -77,11 +79,11 @@ export class AppsListComponent implements OnInit { } private load() { - this.appsProcessService.getDeployedApplications().subscribe( + this.appsProcessService.getDeployedApplications() + .subscribe( (res: AppDefinitionRepresentationModel[]) => { this.filterApps(res).forEach((app: AppDefinitionRepresentationModel) => { - if (app.defaultAppId === AppsListComponent.DEFAULT_TASKS_APP) { - app.name = AppsListComponent.DEFAULT_TASKS_APP_NAME; + if (this.isDefaultApp(app)) { app.theme = AppsListComponent.DEFAULT_TASKS_APP_THEME; app.icon = AppsListComponent.DEFAULT_TASKS_APP_ICON; this.appsObserver.next(app); @@ -96,6 +98,16 @@ export class AppsListComponent implements OnInit { ); } + isDefaultApp(app) { + return app.defaultAppId === AppsListComponent.DEFAULT_TASKS_APP; + } + + getAppName(app) { + return this.isDefaultApp(app) + ? this.translationService.get(AppsListComponent.DEFAULT_TASKS_APP_NAME) + : Observable.of(app.name); + } + /** * Pass the selected app as next * @param app