Skip to content

Commit 719b0c9

Browse files
committed
test(js): add test for max_columns ellipsis rendering
1 parent 67b8f4e commit 719b0c9

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

tests/js/table_widget.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,73 @@ describe('TableWidget', () => {
335335
expect(headers[0].textContent).toBe('');
336336
expect(headers[1].textContent).toBe('value');
337337
});
338+
339+
/*
340+
* Tests that the widget correctly renders HTML with truncated columns (ellipsis)
341+
* and ensures that the ellipsis column is not treated as a sortable column.
342+
*/
343+
it('should render truncated columns with ellipsis and not make ellipsis sortable', () => {
344+
// Mock HTML with truncated columns
345+
// Use the structure produced by the python backend
346+
const mockHtml = `
347+
<table>
348+
<thead>
349+
<tr>
350+
<th><div class="bf-header-content">col1</div></th>
351+
<th><div class="bf-header-content" style="cursor: default;">...</div></th>
352+
<th><div class="bf-header-content">col10</div></th>
353+
</tr>
354+
</thead>
355+
<tbody>
356+
<tr>
357+
<td class="cell-align-right">1</td>
358+
<td class="cell-align-left">...</td>
359+
<td class="cell-align-right">10</td>
360+
</tr>
361+
</tbody>
362+
</table>
363+
`;
364+
365+
model.get.mockImplementation((property) => {
366+
if (property === 'table_html') {
367+
return mockHtml;
368+
}
369+
if (property === 'orderable_columns') {
370+
// Only actual columns are orderable
371+
return ['col1', 'col10'];
372+
}
373+
if (property === 'sort_context') {
374+
return [];
375+
}
376+
return null;
377+
});
378+
379+
render({ model, el });
380+
381+
// Manually trigger the table_html change handler
382+
const tableHtmlChangeHandler = model.on.mock.calls.find(
383+
(call) => call[0] === 'change:table_html',
384+
)[1];
385+
tableHtmlChangeHandler();
386+
387+
const headers = el.querySelectorAll('th');
388+
expect(headers).toHaveLength(3);
389+
390+
// Check col1 (sortable)
391+
const col1Header = headers[0];
392+
const col1Indicator = col1Header.querySelector('.sort-indicator');
393+
expect(col1Indicator).not.toBeNull(); // Should exist (hidden by default)
394+
395+
// Check ellipsis (not sortable)
396+
const ellipsisHeader = headers[1];
397+
const ellipsisIndicator = ellipsisHeader.querySelector('.sort-indicator');
398+
// The render function adds sort indicators only if the column name matches an entry in orderable_columns.
399+
// The ellipsis header content is "..." which is not in ['col1', 'col10'].
400+
expect(ellipsisIndicator).toBeNull();
401+
402+
// Check col10 (sortable)
403+
const col10Header = headers[2];
404+
const col10Indicator = col10Header.querySelector('.sort-indicator');
405+
expect(col10Indicator).not.toBeNull();
406+
});
338407
});

0 commit comments

Comments
 (0)