From 1f3e6631990c3d948f68d356dd121c909d2c79d2 Mon Sep 17 00:00:00 2001 From: perceptron8 Date: Sat, 5 Oct 2024 09:37:10 +0200 Subject: [PATCH] Add `Tree.selection` tests --- src/app/components/tree/tree.spec.ts | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/app/components/tree/tree.spec.ts b/src/app/components/tree/tree.spec.ts index 8e996a6a142..4565f75c4ef 100755 --- a/src/app/components/tree/tree.spec.ts +++ b/src/app/components/tree/tree.spec.ts @@ -290,4 +290,36 @@ describe('Tree', () => { expect(tree.filteredNodes).toBeTruthy(); expect(tree.filteredNodes.length).toEqual(2); }); + + it('should select nodes by reference', () => { + // + + const root = {key: undefined, label: '(root)'}; + tree.selectionMode = 'single'; + tree.value = [root]; + + tree.selection = root; + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('.p-highlight'))).toBeTruthy(); + + tree.selection = undefined; + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('.p-highlight'))).toBeFalsy(); + }); + + it('should select nodes by key (even if key is empty!)', () => { + // + + const root = {key: '', label: '(root)'}; + tree.selectionMode = 'single'; + tree.value = [root]; + + tree.selection = {key: root.key, label: root.label}; + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('.p-highlight'))).toBeTruthy(); + + tree.selection = {key: 'non-' + root.key, label: root.label}; + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('.p-highlight'))).toBeFalsy(); + }); });