Name column fixes (#6904)

This commit is contained in:
Denys Vuika
2021-04-07 12:00:05 +01:00
committed by GitHub
parent ec2436e73b
commit a244200258
6 changed files with 66 additions and 8 deletions

View File

@@ -16,9 +16,59 @@
*/
import { NameColumnComponent } from './name-column.component';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { ContentTestingModule } from '../../../testing/content.testing.module';
import { skip } from 'rxjs/operators';
describe('NameColumnComponent', () => {
it('should be defined', () => {
expect(NameColumnComponent).toBeDefined();
});
let fixture: ComponentFixture<NameColumnComponent>;
let context: any;
let component: NameColumnComponent;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
]
});
fixture = TestBed.createComponent(NameColumnComponent);
context = {
row: {
node: {entry: {}},
getValue(key) {
return key;
}
}
};
component = fixture.componentInstance;
component.context = context;
});
it('should set the display value based on default key', (done) => {
component.displayText$
.pipe(skip(1))
.subscribe(value => {
expect(value).toBe('name');
done();
});
component.ngOnInit();
});
it('should set the display value based on the custom key', (done) => {
component.key = 'title';
component.displayText$
.pipe(skip(1))
.subscribe(value => {
expect(value).toBe('title');
done();
});
component.ngOnInit();
});
});

View File

@@ -53,6 +53,9 @@ export class NameColumnComponent implements OnInit, OnDestroy {
@Input()
context: any;
@Input()
key = 'name';
displayText$ = new BehaviorSubject<string>('');
node: NodeEntry;
@@ -82,7 +85,8 @@ export class NameColumnComponent implements OnInit, OnDestroy {
this.node = this.context.row.node;
if (this.node && this.node.entry) {
this.displayText$.next(this.node.entry.name || this.node.entry.id);
const displayText = this.context.row.getValue(this.key);
this.displayText$.next(displayText || this.node.entry.id);
}
}