diff --git a/front_end/ui/components/TreeOutlineUtils.ts b/front_end/ui/components/TreeOutlineUtils.ts
index e777a6c1fe..2094871a88 100644
--- a/front_end/ui/components/TreeOutlineUtils.ts
+++ b/front_end/ui/components/TreeOutlineUtils.ts
@@ -6,6 +6,7 @@ import * as LitHtml from '../../third_party/lit-html/lit-html.js';
interface BaseTreeNode {
key: string;
+ renderer?: (key: string) => LitHtml.TemplateResult;
}
export interface TreeNodeWithChildren extends BaseTreeNode {
diff --git a/test/unittests/front_end/helpers/DOMHelpers.ts b/test/unittests/front_end/helpers/DOMHelpers.ts
index 7791f6b83a..efb758d63c 100644
--- a/test/unittests/front_end/helpers/DOMHelpers.ts
+++ b/test/unittests/front_end/helpers/DOMHelpers.ts
@@ -189,3 +189,13 @@ export async function doubleRaf() {
export async function raf() {
return new Promise(resolve => requestAnimationFrame(resolve));
}
+
+/**
+ * It's useful to use innerHTML in the tests to have full confidence in the
+ * renderer output, but LitHtml uses comment nodes to split dynamic from
+ * static parts of a template, and we don't want our tests full of noise
+ * from those.
+ */
+export function stripLitHtmlCommentNodes(text: string) {
+ return text.replaceAll('', '');
+}
diff --git a/test/unittests/front_end/ui/components/DataGrid_test.ts b/test/unittests/front_end/ui/components/DataGrid_test.ts
index 3297a4f69a..9509610bee 100644
--- a/test/unittests/front_end/ui/components/DataGrid_test.ts
+++ b/test/unittests/front_end/ui/components/DataGrid_test.ts
@@ -6,7 +6,7 @@ import * as Platform from '../../../../../front_end/platform/platform.js';
import * as Coordinator from '../../../../../front_end/render_coordinator/render_coordinator.js';
import * as LitHtml from '../../../../../front_end/third_party/lit-html/lit-html.js';
import * as UIComponents from '../../../../../front_end/ui/components/components.js';
-import {assertElement, assertShadowRoot, dispatchClickEvent, dispatchKeyDownEvent, getEventPromise, renderElementIntoDOM} from '../../helpers/DOMHelpers.js';
+import {assertElement, assertShadowRoot, dispatchClickEvent, dispatchKeyDownEvent, getEventPromise, renderElementIntoDOM, stripLitHtmlCommentNodes} from '../../helpers/DOMHelpers.js';
import {withMutations} from '../../helpers/MutationHelpers.js';
import {assertCurrentFocusedCellIs, emulateUserFocusingCellAt, emulateUserKeyboardNavigation, focusTableCell, getAllRows, getCellByIndexes, getFocusableCell, getHeaderCellForColumnId, getHeaderCells, getValuesOfAllBodyRows, getValuesOfBodyRowByAriaIndex} from './DataGridHelpers.js';
@@ -60,14 +60,6 @@ Object.freeze(columns);
Object.freeze(columnsWithNoneSortable);
Object.freeze(rows);
-/**
- * It's useful to use innerHTML in the tests to have full confidence in the
- * renderer output, but LitHtml uses comment nodes to split dynamic from
- * static parts of a template, and we don't want our tests full of noise
- * from those.
- */
-const stripLitHtmlCommentNodes = (text: string) => text.replaceAll('', '');
-
const renderDataGrid = (data: Partial): UIComponents.DataGrid.DataGrid => {
const component = new UIComponents.DataGrid.DataGrid();
component.data = {
diff --git a/test/unittests/front_end/ui/components/TreeOutline_test.ts b/test/unittests/front_end/ui/components/TreeOutline_test.ts
index 9659f61dd6..a631f5ada2 100644
--- a/test/unittests/front_end/ui/components/TreeOutline_test.ts
+++ b/test/unittests/front_end/ui/components/TreeOutline_test.ts
@@ -3,8 +3,9 @@
// found in the LICENSE file.
import * as Coordinator from '../../../../../front_end/render_coordinator/render_coordinator.js';
+import * as LitHtml from '../../../../../front_end/third_party/lit-html/lit-html.js';
import * as UIComponents from '../../../../../front_end/ui/components/components.js';
-import {assertElement, assertShadowRoot, dispatchClickEvent, dispatchKeyDownEvent, renderElementIntoDOM} from '../../helpers/DOMHelpers.js';
+import {assertElement, assertShadowRoot, dispatchClickEvent, dispatchKeyDownEvent, renderElementIntoDOM, stripLitHtmlCommentNodes} from '../../helpers/DOMHelpers.js';
const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance();
const {assert} = chai;
@@ -135,8 +136,7 @@ function treeNodeKeyText(node: HTMLLIElement) {
if (!keyNode) {
throw new Error('Found tree node without a key within it.');
}
- // Trim to remove whitespace that made it into the DOM that we don't care about.
- return (keyNode.textContent || '').trim();
+ return keyNode.getAttribute('data-node-key') || '';
}
function getVisibleTreeNodeByText(shadowRoot: ShadowRoot, text: string): HTMLLIElement {
@@ -307,6 +307,36 @@ describe('TreeOutline', () => {
]);
});
+ it('allows a node to have a custom renderer', async () => {
+ const tinyTree: UIComponents.TreeOutlineUtils.TreeNode[] = [{
+ key: 'Offices',
+ renderer: key => LitHtml.html`