MCPcopy Index your code
hub / github.com/angular/components / expectFlatTreeToMatch

Function expectFlatTreeToMatch

src/material/tree/tree.spec.ts:759–805  ·  view source on GitHub ↗
(
  treeElement: Element,
  expectedPaddingIndent: number = 28,
  ...expectedTree: TreeContent
)

Source from the content-addressed store, hash-verified

757}
758
759function expectFlatTreeToMatch(
760 treeElement: Element,
761 expectedPaddingIndent: number = 28,
762 ...expectedTree: TreeContent
763) {
764 const missedExpectations: string[] = [];
765
766 function checkNode(node: Element, expectedNode: NodeContent) {
767 const actualTextContent = node.textContent!.trim();
768 const expectedTextContent = expectedNode[expectedNode.length - 1];
769 if (actualTextContent !== expectedTextContent) {
770 missedExpectations.push(
771 `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`,
772 );
773 }
774 }
775
776 function checkLevel(node: Element, expectedNode: NodeContent) {
777 const rawLevel = (node as HTMLElement).style.paddingLeft;
778
779 // Some browsers return 0, while others return 0px.
780 const actualLevel = rawLevel === '0' ? '0px' : rawLevel;
781 if (expectedNode.length === 1) {
782 if (actualLevel !== `` && actualLevel !== '0px') {
783 missedExpectations.push(`Expected node level to be 0px but was ${actualLevel}`);
784 }
785 } else {
786 const expectedLevel = `${(expectedNode.length - 1) * expectedPaddingIndent}px`;
787 if (actualLevel != expectedLevel) {
788 missedExpectations.push(
789 `Expected node level to be ${expectedLevel} but was ${actualLevel}`,
790 );
791 }
792 }
793 }
794
795 getNodes(treeElement).forEach((node, index) => {
796 const expected = expectedTree[index];
797
798 checkLevel(node, expected);
799 checkNode(node, expected);
800 });
801
802 if (missedExpectations.length) {
803 fail(missedExpectations.join('\n'));
804 }
805}
806
807function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: TreeContent) {
808 const missedExpectations: string[] = [];

Callers 1

tree.spec.tsFile · 0.70

Calls 3

getNodesFunction · 0.70
checkLevelFunction · 0.70
checkNodeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…