mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[MNT-25185] Display authority name instead of id if provided (#11809)
* [MNT-25185] Display authority name instead of id if provided * [MNT-25185] CR fixes
This commit is contained in:
+28
-10
@@ -18,11 +18,12 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { UserNameColumnComponent } from './user-name-column.component';
|
import { UserNameColumnComponent } from './user-name-column.component';
|
||||||
import { NodeEntry } from '@alfresco/js-api';
|
import { NodeEntry } from '@alfresco/js-api';
|
||||||
|
import { UnitTestingUtils } from '@alfresco/adf-core';
|
||||||
|
|
||||||
describe('UserNameColumnComponent', () => {
|
describe('UserNameColumnComponent', () => {
|
||||||
let fixture: ComponentFixture<UserNameColumnComponent>;
|
let fixture: ComponentFixture<UserNameColumnComponent>;
|
||||||
let component: UserNameColumnComponent;
|
let component: UserNameColumnComponent;
|
||||||
let element: HTMLElement;
|
let testingUtils: UnitTestingUtils;
|
||||||
const person = {
|
const person = {
|
||||||
firstName: 'fake',
|
firstName: 'fake',
|
||||||
lastName: 'user',
|
lastName: 'user',
|
||||||
@@ -34,13 +35,15 @@ describe('UserNameColumnComponent', () => {
|
|||||||
displayName: 'fake authority'
|
displayName: 'fake authority'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getUserName = (): string => testingUtils.getInnerTextByCSS('span.adf-user-name-column');
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [UserNameColumnComponent]
|
imports: [UserNameColumnComponent]
|
||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(UserNameColumnComponent);
|
fixture = TestBed.createComponent(UserNameColumnComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
element = fixture.nativeElement;
|
testingUtils = new UnitTestingUtils(fixture.debugElement);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,8 +58,8 @@ describe('UserNameColumnComponent', () => {
|
|||||||
};
|
};
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('[title="fake user"]').textContent).toContain('fake user');
|
expect(getUserName()).toBe('fake user');
|
||||||
expect(element.querySelector('[title="fake@test.com"]').textContent).toContain('fake@test.com');
|
expect(testingUtils.getInnerTextByCSS('.adf-user-email-column')).toBe('fake@test.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render person value from node', (done) => {
|
it('should render person value from node', (done) => {
|
||||||
@@ -95,7 +98,7 @@ describe('UserNameColumnComponent', () => {
|
|||||||
};
|
};
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('[title="fake authority"]').textContent.trim()).toBe('fake authority');
|
expect(getUserName()).toBe('fake authority');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display group id when display name is not provided', () => {
|
it('should display group id when display name is not provided', () => {
|
||||||
@@ -110,20 +113,35 @@ describe('UserNameColumnComponent', () => {
|
|||||||
};
|
};
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('[title="fake_group_id"]').textContent.trim()).toBe('fake_group_id');
|
expect(getUserName()).toBe('fake_group_id');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render group for authorityId', () => {
|
it('should render group for authorityId when authorityDisplayName is not provided', () => {
|
||||||
component.context = {
|
component.context = {
|
||||||
row: {
|
row: {
|
||||||
obj: {
|
obj: {
|
||||||
authorityId: 'fake-id'
|
authorityId: 'fake-id',
|
||||||
|
authorityDisplayName: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('[title=fake-id]').textContent.trim()).toBe('fake-id');
|
expect(getUserName()).toBe('fake-id');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render authority display name when provided', () => {
|
||||||
|
component.context = {
|
||||||
|
row: {
|
||||||
|
obj: {
|
||||||
|
authorityId: 'fake-id',
|
||||||
|
authorityDisplayName: 'Fake authority'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
component.ngOnInit();
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(getUserName()).toBe('Fake authority');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render person value from node', () => {
|
it('should render person value from node', () => {
|
||||||
@@ -137,7 +155,7 @@ describe('UserNameColumnComponent', () => {
|
|||||||
} as NodeEntry;
|
} as NodeEntry;
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('[title="Fake authority"]').textContent.trim()).toBe('Fake authority');
|
expect(getUserName()).toBe('Fake authority');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -52,8 +52,8 @@ export class UserNameColumnComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.context != null) {
|
if (this.context != null) {
|
||||||
const { person, group, authorityId } = this.context.row.obj?.entry ?? this.context.row.obj;
|
const { person, group, authorityId, authorityDisplayName } = this.context.row.obj?.entry ?? this.context.row.obj;
|
||||||
const permissionGroup = authorityId ? ({ displayName: authorityId } as Group) : null;
|
const permissionGroup: Group | null = authorityId ? { displayName: authorityDisplayName, id: authorityId } : null;
|
||||||
this.updatePerson(person);
|
this.updatePerson(person);
|
||||||
this.updateGroup(group || permissionGroup);
|
this.updateGroup(group || permissionGroup);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { PermissionElement } from '@alfresco/js-api';
|
|||||||
|
|
||||||
export class PermissionDisplayModel implements PermissionElement {
|
export class PermissionDisplayModel implements PermissionElement {
|
||||||
authorityId?: string;
|
authorityId?: string;
|
||||||
|
authorityDisplayName?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
accessStatus?: 'ALLOWED' | 'DENIED' | string;
|
accessStatus?: 'ALLOWED' | 'DENIED' | string;
|
||||||
isInherited: boolean = false;
|
isInherited: boolean = false;
|
||||||
@@ -28,6 +29,7 @@ export class PermissionDisplayModel implements PermissionElement {
|
|||||||
constructor(obj?: any) {
|
constructor(obj?: any) {
|
||||||
if (obj) {
|
if (obj) {
|
||||||
this.authorityId = obj.authorityId;
|
this.authorityId = obj.authorityId;
|
||||||
|
this.authorityDisplayName = obj.authorityDisplayName;
|
||||||
this.name = obj.name;
|
this.name = obj.name;
|
||||||
this.accessStatus = obj.accessStatus;
|
this.accessStatus = obj.accessStatus;
|
||||||
this.isInherited = obj.isInherited !== null && obj.isInherited !== undefined ? obj.isInherited : false;
|
this.isInherited = obj.isInherited !== null && obj.isInherited !== undefined ? obj.isInherited : false;
|
||||||
|
|||||||
Reference in New Issue
Block a user