Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Wilken <gnomation@gnomeontherun.com>
  • Loading branch information
gnomeontherun committed Mar 21, 2019
1 parent 12d6915 commit 2b56a76
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
19 changes: 2 additions & 17 deletions src/clr-angular/data/tree-view/tree-node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/

import { Component, ViewChild } from '@angular/core';
import { fakeAsync, tick } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { By } from '@angular/platform-browser';
import { RecursiveTreeNodeModel } from './models/recursive-tree-node.model';

import { ClrTreeViewModule } from './tree-view.module';
Expand All @@ -24,14 +22,13 @@ import { ClrTreeNode } from './tree-node';
@Component({
template: `<clr-tree-node #node [(clrSelected)]="selected" [(clrExpanded)]="expanded" [clrExpandable]="expandable">
Hello world
<clr-tree-node *ngIf="withChild" [(clrSelected)]="childSelected">Child</clr-tree-node>
<clr-tree-node *ngIf="withChild">Child</clr-tree-node>
</clr-tree-node>`,
})
class TestComponent {
@ViewChild('node') tree: ClrTreeNode<void>;

selected = ClrSelectedState.UNSELECTED;
childSelected = ClrSelectedState.UNSELECTED;
expanded = false;
withChild = true;
expandable: boolean | undefined;
Expand Down Expand Up @@ -165,18 +162,6 @@ export default function(): void {
describe('Template API', function() {
spec(ClrTreeNode, TestComponent, ClrTreeViewModule, { imports: [NoopAnimationsModule, ClrIconModule] });

it('offers a [(clrSelected)] two-way binding', function(this: Context) {
// Here we are testing the child two-way binding, which should be updated by two-way always.
const child = this.fixture.debugElement.query(By.directive(ClrTreeNode));
this.hostComponent.selected = ClrSelectedState.SELECTED;
this.detectChanges();
expect(this.clarityDirective.selected).toBe(ClrSelectedState.SELECTED);
expect(child.componentInstance.selected).toBe(ClrSelectedState.SELECTED);
this.clarityDirective.selected = ClrSelectedState.UNSELECTED;
this.detectChanges();
expect(child.componentInstance.selected).toBe(ClrSelectedState.UNSELECTED);
});

it('offers a [(clrSelected)] two-way binding, but skips emitting output when setting input', function(this: Context) {
this.hostComponent.selected = ClrSelectedState.SELECTED;
this.detectChanges();
Expand All @@ -188,7 +173,7 @@ export default function(): void {
// Here we are expecting that the output has not emitted.
// See https://github.com/vmware/clarity/issues/3073
expect<ClrSelectedState>(this.hostComponent.selected).toBe(ClrSelectedState.SELECTED);
// By setting the model here, we will emit the binding since its not through the input
// By setting the model here, we will emit the binding since it's not through the input
this.clarityDirective._model.setSelected(ClrSelectedState.INDETERMINATE, true, true);
this.detectChanges();
expect<ClrSelectedState>(this.hostComponent.selected).toBe(ClrSelectedState.INDETERMINATE);
Expand Down
1 change: 0 additions & 1 deletion src/clr-angular/data/tree-view/tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class ClrTreeNode<T> implements OnInit, OnDestroy {
this.skipEmitChange = false;
}

// We need an async EventEmitter or we will trigger chocolate errors like it's 2016.
@Output('clrSelectedChange') selectedChange = new EventEmitter<ClrSelectedState>(false);

@HostBinding('attr.role')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import { ClrSelectedState } from '@clr/angular';
interface SelectedMap {
[key: string]: ClrSelectedState;
}

interface TreeNode {
name: string;
selected?: ClrSelectedState;
children?: TreeNode[];
}
@Component({
selector: 'clr-eager-recursive-tree-demo',
styleUrls: ['../tree-view.demo.scss'],
templateUrl: './eager-recursive-tree.html',
})
export class EagerRecursiveTreeDemo {
singleRoot = {
singleRoot: TreeNode = {
name: 'A',
children: [
{ name: 'AA', children: [{ name: 'AAA' }, { name: 'AAB' }, { name: 'AAC' }] },
Expand All @@ -25,7 +31,7 @@ export class EagerRecursiveTreeDemo {
],
};

multiRoot = [
multiRoot: TreeNode[] = [
{
name: 'A',
children: [
Expand All @@ -44,7 +50,7 @@ export class EagerRecursiveTreeDemo {
},
];

private buildDefaultSelected(rootMap, selectedMap: SelectedMap = {}) {
private buildDefaultSelected(rootMap: TreeNode | TreeNode[], selectedMap: SelectedMap = {}) {
if (!Array.isArray(rootMap)) {
rootMap = [rootMap];
}
Expand Down

0 comments on commit 2b56a76

Please sign in to comment.