table/src/table/table.test-utils.ts
Utility class for generating and managing test IDs for table components. Provides methods to generate consistent test IDs for table elements and helpers for testing frameworks like Playwright and Testing Library.
import { TableTestUtils } from '@talenra/components/table';// Get test ID for a table element
const tableId = TableTestUtils.table();
// Get test ID for a specific cell
const cellId = TableTestUtils.cell('row-1', 'col-name');
// Get test ID for a header cell
const headerId = TableTestUtils.headerCell('col-name');// Configure with custom prefix and attribute
TableTestUtils.setupTableTestIds({
testIdAttribute: 'data-test',
prefix: 'my-app-'
});// With Playwright
const tableId = TableTestUtils.wrap((testId) => page.getByTestId(testId));
await expect(tableId.cell('row-1', 'col-name')).toBeVisible();
// With Angular TestBed
const cellElement = fixture.debugElement.query(
By.css(TableTestUtils.getSelector(TableTestUtils.cell('row-1', 'col-name')))
);
Methods |
|
| Static cell | ||||||||||||
cell(rowId: string, colId: string)
|
||||||||||||
|
Get test ID for a specific cell. Example :
Parameters :
Returns :
string
Test ID for the cell |
| Static getSelector | ||||||||
getSelector(testId: string)
|
||||||||
|
Utility function to get a CSS selector for a test ID. Useful for querySelector or Angular's By.css(). Example :
Parameters :
Returns :
string
CSS attribute selector for the test ID |
| Static getTableTestIdConfig |
getTableTestIdConfig()
|
|
Get the current test ID configuration. Example :
Returns :
TableTestIdConfig
A copy of the current configuration |
| Static header |
header()
|
|
Get test ID for the table header. Example :
Returns :
string
Test ID for the table header |
| Static headerCell | ||||||||
headerCell(colId: string)
|
||||||||
|
Get test ID for a specific header cell. Example :
Parameters :
Returns :
string
Test ID for the header cell |
| Static loading |
loading()
|
|
Get test ID for the loading skeleton. Note: Only one loading indicator is present in the table header when loading. Example :
Returns :
string
Test ID for the loading indicator |
| Static noData |
noData()
|
|
Get test ID for the no data message. Example :
Returns :
string
Test ID for the no data message |
| Static row | ||||||||
row(rowId: string)
|
||||||||
|
Get test ID for a specific row. Example :
Parameters :
Returns :
string
Test ID for the row |
| Static selectAll |
selectAll()
|
|
Get test ID for the select all checkbox. Example :
Returns :
string
Test ID for the select all checkbox |
| Static selectRow | ||||||||
selectRow(rowId: string)
|
||||||||
|
Get test ID for a row selection checkbox. Example :
Parameters :
Returns :
string
Test ID for the row selection checkbox |
| Static setupTableTestIds | ||||||||||
setupTableTestIds(options: TableTestIdConfig)
|
||||||||||
|
Configure the table test utilities. Example :
Parameters :
Returns :
void
|
| Static sortIcon | ||||||||
sortIcon(colId: string)
|
||||||||
|
Get test ID for a column sort icon. Example :
Parameters :
Returns :
string
Test ID for the sort icon |
| Static table |
table()
|
|
Get test ID for the main table element. Example :
Returns :
string
Test ID for the table element |
| Static toolbar |
toolbar()
|
|
Get test ID for the table toolbar. Example :
Returns :
string
Test ID for the table toolbar |
| Static wrap | ||||||||
wrap(getByTestId: TestIdGetter<T>)
|
||||||||
Type parameters :
|
||||||||
|
Creates a wrapper around TableTestUtils methods to reduce boilerplate in tests. This is particularly useful with testing frameworks like Playwright or Testing Library. Example :
Parameters :
Returns :
literal type
Object with methods that return elements for each table part |