mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-1831] DataTable Unit test (#5475)
This commit is contained in:
@@ -53,6 +53,14 @@ class FakeDataRow implements DataRow {
|
||||
}
|
||||
}
|
||||
|
||||
export function resolverFn(row: DataRow, col: DataColumn) {
|
||||
const value = row.getValue(col.key);
|
||||
if (col.key === 'name') {
|
||||
return `${row.getValue('firstName')} - ${row.getValue('lastName')}`;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
describe('DataTable', () => {
|
||||
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
@@ -1127,6 +1135,28 @@ describe('DataTable', () => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('.adf-sticky-header')).toBeNull();
|
||||
});
|
||||
|
||||
it('should be able to define values using the resolver function', () => {
|
||||
dataTable.data = new ObjectDataTableAdapter([
|
||||
{ id: 1, firstName: 'foo', lastName: 'bar' },
|
||||
{ id: 2, firstName: 'bar', lastName: 'baz' }],
|
||||
[new ObjectDataColumn({ key: 'id' }), new ObjectDataColumn({ key: 'name' })]
|
||||
);
|
||||
spyOn(dataTable, 'resolverFn').and.callFake(resolverFn);
|
||||
fixture.detectChanges();
|
||||
|
||||
const id1 = element.querySelector('[data-automation-id="text_1');
|
||||
const id2 = element.querySelector('[data-automation-id="text_2');
|
||||
const names = element.querySelectorAll('[data-automation-id="text_undefined"]');
|
||||
|
||||
expect(id1.innerText).toEqual('1');
|
||||
expect(names[0].innerText).toEqual('foo - bar');
|
||||
expect(id2.innerText).toEqual('2');
|
||||
expect(names[1].innerText).toEqual('bar - baz');
|
||||
|
||||
expect(dataTable.data.getRows().length).toEqual(2);
|
||||
expect(dataTable.resolverFn).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Accesibility', () => {
|
||||
|
Reference in New Issue
Block a user