Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set title attribute in text column cell #1092

Merged
merged 14 commits into from
Mar 9, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
"comment": "Set title attribute in text column",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ TableCellState<TableColumnTextCellRecord, TableColumnTextColumnConfig>
>`
<span
class="${x => (typeof x.cellRecord.value === 'string' ? '' : 'placeholder')}"
title="${x => (typeof x.cellRecord.value === 'string'
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
? x.cellRecord.value
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
: x.columnConfig.placeholder)}"
>
${x => (typeof x.cellRecord.value === 'string'
? x.cellRecord.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ describe('TableColumnText', () => {
});
}

it('sets title equal to rendered cell value', async () => {
element.setData([{ field: 'foo' }]);
await connect();
await waitForUpdatesAsync();

expect(pageObject.getCellTitle(0, 0)).toBe('foo');
});

it('sets title equal to rendered placeholder value', async () => {
element.setData([{ field: null }]);
await connect();
await waitForUpdatesAsync();

expect(pageObject.getCellTitle(0, 0)).toBe('no value');
});

it('changing fieldName updates display', async () => {
element.setData([{ field: 'foo', anotherField: 'bar' }]);
await connect();
Expand Down
70 changes: 37 additions & 33 deletions packages/nimble-components/src/table/tests/table.pageobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { TableHeader } from '../components/header';
import type { TableRecord } from '../types';
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
import { waitForUpdatesAsync } from '../../testing/async-helpers';
import type { MenuButton } from '../../menu-button';
import type { TableCell } from '../components/cell';

/**
* Page object for the `nimble-table` component to provide consistent ways
Expand Down Expand Up @@ -54,22 +55,20 @@ export class TablePageObject<T extends TableRecord> {
rowIndex: number,
columnIndex: number
): string {
const rows = this.tableElement.shadowRoot!.querySelectorAll('nimble-table-row');
if (rowIndex >= rows.length) {
throw new Error(
'Attempting to index past the total number of rendered rows'
);
}

const row = rows.item(rowIndex);
const cells = row.shadowRoot!.querySelectorAll('nimble-table-cell');
if (columnIndex >= cells.length) {
throw new Error(
'Attempting to index past the total number of rendered columns'
);
}
return (
this.getCell(
rowIndex,
columnIndex
).shadowRoot!.textContent?.trim() ?? ''
);
}

return cells.item(columnIndex).shadowRoot!.textContent?.trim() ?? '';
public getCellTitle(rowIndex: number, columnIndex: number): string {
return (
this.getCell(rowIndex, columnIndex)
.shadowRoot!.querySelector('.cell-content-container span')
?.getAttribute('title') ?? ''
);
}

public getRecordId(rowIndex: number): string | undefined {
Expand All @@ -93,24 +92,10 @@ export class TablePageObject<T extends TableRecord> {
rowIndex: number,
columnIndex: number
): MenuButton | null {
const rows = this.tableElement.shadowRoot!.querySelectorAll('nimble-table-row');
if (rowIndex >= rows.length) {
throw new Error(
'Attempting to index past the total number of rendered rows'
);
}

const row = rows.item(rowIndex);
const cells = row.shadowRoot!.querySelectorAll('nimble-table-cell');
if (columnIndex >= cells.length) {
throw new Error(
'Attempting to index past the total number of rendered columns'
);
}

return cells
.item(columnIndex)
.shadowRoot!.querySelector<MenuButton>('nimble-menu-button');
return this.getCell(
rowIndex,
columnIndex
).shadowRoot!.querySelector<MenuButton>('nimble-menu-button');
}

public async clickCellActionMenu(
Expand Down Expand Up @@ -163,6 +148,25 @@ export class TablePageObject<T extends TableRecord> {
}
}

private getCell(rowIndex: number, columnIndex: number): TableCell {
const rows = this.tableElement.shadowRoot!.querySelectorAll('nimble-table-row');
if (rowIndex >= rows.length) {
throw new Error(
'Attempting to index past the total number of rendered rows'
);
}

const row = rows.item(rowIndex);
const cells = row.shadowRoot!.querySelectorAll('nimble-table-cell');
if (columnIndex >= cells.length) {
throw new Error(
'Attempting to index past the total number of rendered columns'
);
}

return cells.item(columnIndex);
}

private getHeaderContentElement(
element: HTMLElement | HTMLSlotElement
): Node | undefined {
Expand Down