mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-9310] Add missing initial on task assignment dialog (#7694)
* [AAE-9310] Add missing initial on task assignment dialog * [AAE-9310] rewrite full-name pipe * [AAE-9310] improved build username or email * Trigger travis * [AAE-9310] improve buildFromUsernameOrEmail
This commit is contained in:
22
lib/core/models/general-user.model.ts
Normal file
22
lib/core/models/general-user.model.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { EcmUserModel } from './ecm-user.model';
|
||||
import { IdentityUserModel } from './identity-user.model';
|
||||
import { UserProcessModel } from './user-process.model';
|
||||
|
||||
export type User = (EcmUserModel | UserProcessModel | IdentityUserModel) & { displayName?: string } & { username?: string };
|
@@ -37,3 +37,4 @@ export * from './search-text-input.model';
|
||||
export * from './node-metadata.model';
|
||||
export * from './application-access.model';
|
||||
export * from './user-access.model';
|
||||
export * from './general-user.model';
|
||||
|
@@ -16,35 +16,25 @@
|
||||
*/
|
||||
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { User } from '../models/general-user.model';
|
||||
|
||||
@Pipe({ name: 'fullName' })
|
||||
export class FullNamePipe implements PipeTransform {
|
||||
transform(user: any): string {
|
||||
let fullName = '';
|
||||
if (user) {
|
||||
if (user.displayName) {
|
||||
const firstAndLastName = user.displayName.split('\ (.*)');
|
||||
if (firstAndLastName[0]) {
|
||||
fullName += firstAndLastName[0];
|
||||
}
|
||||
if (firstAndLastName[1]) {
|
||||
fullName += fullName.length > 0 ? ' ' : '';
|
||||
fullName += firstAndLastName[1];
|
||||
|
||||
transform(user: User): string {
|
||||
return this.buildFullName(user) ? this.buildFullName(user) : this.buildFromUsernameOrEmail(user);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (user.firstName && user.firstName !== 'null') {
|
||||
fullName += user.firstName;
|
||||
buildFullName(user: User): string {
|
||||
const fullName: string[] = [];
|
||||
|
||||
fullName.push(user?.firstName);
|
||||
fullName.push(user?.lastName);
|
||||
|
||||
return fullName.join(' ').trim();
|
||||
}
|
||||
if (user.lastName && user.lastName !== 'null') {
|
||||
fullName += fullName.length > 0 ? ' ' : '';
|
||||
fullName += user.lastName;
|
||||
}
|
||||
if (!fullName) {
|
||||
fullName += user.username ? user.username : user.email ? user.email : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return fullName;
|
||||
|
||||
buildFromUsernameOrEmail(user: User): string {
|
||||
return (user?.username || user?.email) ?? '' ;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
import { User } from '../models/general-user.model';
|
||||
import { InitialUsernamePipe } from './user-initial.pipe';
|
||||
|
||||
class FakeSanitizer extends DomSanitizer {
|
||||
@@ -53,11 +53,11 @@ class FakeSanitizer extends DomSanitizer {
|
||||
describe('UserInitialPipe', () => {
|
||||
|
||||
let pipe: InitialUsernamePipe;
|
||||
let fakeUser: UserProcessModel;
|
||||
let fakeUser: User;
|
||||
|
||||
beforeEach(() => {
|
||||
pipe = new InitialUsernamePipe(new FakeSanitizer());
|
||||
fakeUser = new UserProcessModel();
|
||||
fakeUser = { username: '' } as User;
|
||||
});
|
||||
|
||||
it('should return a div with the user initials', () => {
|
||||
@@ -88,6 +88,38 @@ describe('UserInitialPipe', () => {
|
||||
expect(result).toBe('<div id="user-initials-image" class="">F</div>');
|
||||
});
|
||||
|
||||
it('should return a single letter into div when only username is defined', () => {
|
||||
fakeUser.firstName = undefined;
|
||||
fakeUser.lastName = undefined;
|
||||
fakeUser.username = 'USERNAME-FAKE';
|
||||
const result = pipe.transform(fakeUser);
|
||||
expect(result).toBe('<div id="user-initials-image" class="">U</div>');
|
||||
});
|
||||
|
||||
it('should return a single letter into div of firstName when only firstName and username is defined', () => {
|
||||
fakeUser.firstName = 'FAKE-NAME';
|
||||
fakeUser.lastName = undefined;
|
||||
fakeUser.username = 'USERNAME-FAKE';
|
||||
const result = pipe.transform(fakeUser);
|
||||
expect(result).toBe('<div id="user-initials-image" class="">F</div>');
|
||||
});
|
||||
|
||||
it('should return two letter into div of username and lastName when firstName is undefined', () => {
|
||||
fakeUser.firstName = undefined;
|
||||
fakeUser.lastName = 'FAKE-SURNAME';
|
||||
fakeUser.username = 'USERNAME-FAKE';
|
||||
const result = pipe.transform(fakeUser);
|
||||
expect(result).toBe('<div id="user-initials-image" class="">UF</div>');
|
||||
});
|
||||
|
||||
it('should return a div with the user initials when firstName, lastName and username is defined', () => {
|
||||
fakeUser.firstName = 'FAKE-NAME';
|
||||
fakeUser.lastName = 'FAKE-SURNAME';
|
||||
fakeUser.username = 'USERNAME-FAKE';
|
||||
const result = pipe.transform(fakeUser);
|
||||
expect(result).toBe('<div id="user-initials-image" class="">FF</div>');
|
||||
});
|
||||
|
||||
it('should return an empty string when user is null', () => {
|
||||
const result = pipe.transform(null);
|
||||
expect(result).toBe('');
|
||||
|
@@ -17,11 +17,7 @@
|
||||
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
import { EcmUserModel } from '../models/ecm-user.model';
|
||||
import { IdentityUserModel } from '../models/identity-user.model';
|
||||
|
||||
export type User = (EcmUserModel | UserProcessModel | IdentityUserModel) & { displayName?: string };
|
||||
import { User } from '../models/general-user.model';
|
||||
|
||||
@Pipe({
|
||||
name: 'usernameInitials'
|
||||
@@ -34,7 +30,7 @@ export class InitialUsernamePipe implements PipeTransform {
|
||||
transform(user: User, className: string = '', delimiter: string = ''): SafeHtml {
|
||||
let safeHtml: SafeHtml = '';
|
||||
if (user) {
|
||||
const initialResult = this.getInitialUserName(user.firstName || user.displayName, user.lastName, delimiter);
|
||||
const initialResult = this.getInitialUserName(user.firstName || user.displayName || user.username, user.lastName, delimiter);
|
||||
safeHtml = this.sanitized.bypassSecurityTrustHtml(`<div id="user-initials-image" class="${className}">${initialResult}</div>`);
|
||||
}
|
||||
return safeHtml;
|
||||
|
@@ -354,34 +354,6 @@ describe('User info component', () => {
|
||||
expect(fullNameElement.textContent).not.toContain('fake-first-name');
|
||||
});
|
||||
|
||||
it('should not show first name if it is null string', async () => {
|
||||
const wrongFirstNameBpmUser: BpmUserModel = new BpmUserModel({
|
||||
firstName: 'null',
|
||||
lastName: 'fake-last-name'
|
||||
});
|
||||
getCurrentUserInfoStub.and.returnValue(of(wrongFirstNameBpmUser));
|
||||
await whenFixtureReady();
|
||||
|
||||
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||
expect(element.querySelector('#adf-userinfo-bpm-name-display')).toBeDefined();
|
||||
expect(element.querySelector('#adf-userinfo-bpm-name-display').textContent).toContain('fake-last-name');
|
||||
expect(element.querySelector('#adf-userinfo-bpm-name-display').textContent).not.toContain('null');
|
||||
});
|
||||
|
||||
it('should not show last name if it is null string', async () => {
|
||||
const wrongLastNameBpmUser: BpmUserModel = new BpmUserModel({
|
||||
firstName: 'fake-first-name',
|
||||
lastName: 'null'
|
||||
});
|
||||
getCurrentUserInfoStub.and.returnValue(of(wrongLastNameBpmUser));
|
||||
await whenFixtureReady();
|
||||
|
||||
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||
expect(element.querySelector('#adf-userinfo-bpm-name-display')).toBeDefined();
|
||||
expect(element.querySelector('#adf-userinfo-bpm-name-display').textContent).toContain('fake-first-name');
|
||||
expect(element.querySelector('#adf-userinfo-bpm-name-display').textContent).not.toContain('null');
|
||||
});
|
||||
|
||||
it('should not show the tabs', async () => {
|
||||
await whenFixtureReady();
|
||||
openUserInfo();
|
||||
|
Reference in New Issue
Block a user