Skip to content

Commit

Permalink
Add Tree.selection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptron8 committed Oct 5, 2024
1 parent 93ce735 commit 1f3e663
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/app/components/tree/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,36 @@ describe('Tree', () => {
expect(tree.filteredNodes).toBeTruthy();
expect(tree.filteredNodes.length).toEqual(2);
});

it('should select nodes by reference', () => {
// <p-tree selectionMode="single" [value]="[root]" [selection]="root" />

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!)', () => {
// <p-tree selectionMode="single" [value]="[root]" [selection]="{key: root.key, label: root.label}" />

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();
});
});

0 comments on commit 1f3e663

Please sign in to comment.