Skip to content

Commit

Permalink
fix(module: tree-select): fix nzNodes type (#2992)
Browse files Browse the repository at this point in the history
fix(module: tree-select): fix spec test
  • Loading branch information
simplejason committed Feb 28, 2019
1 parent b87e8bb commit c435853
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/tree-select/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Any data whose entries are defined in a hierarchical manner is fit to use this c
| `[nzShowExpand]` | Show a Expand Icon before the treeNodes | `boolean` | `true` |
| `[nzShowLine]` | Shows a connecting line | `boolean` | `false` |
| `[nzAsyncData]` | Load data asynchronously (should be used with NzTreeNode.addChildren(...)) | `boolean` | `false` |
| `[nzNodes]` | Data of the treeNodes | `NzTreeNode[]` | `[]` |
| `[nzNodes]` | Data of the treeNodes | `NzTreeNodeOptions[]` | `[]` |
| `[nzDefaultExpandAll]` | Whether to expand all treeNodes by default | `boolean` | `false` |
| `[nzDefaultExpandedKeys]` | Default expanded treeNodes | `string[]` | - |
| `[nzDisplayWith]` | How to display the selected node value in the trigger | `(node: NzTreeNode) => string` | `(node: NzTreeNode) => node.title` |
Expand Down
2 changes: 1 addition & 1 deletion components/tree-select/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ title: TreeSelect
| `[nzShowExpand]` | 节点前添加展开图标 | `boolean` | `true` |
| `[nzShowLine]` | 是否展示连接线 | `boolean` | `false` |
| `[nzAsyncData]` | 是否异步加载(显示加载状态) | `boolean` | `false` |
| `[nzNodes]` | treeNodes 数据 | `NzTreeNode[]` | `[]` |
| `[nzNodes]` | treeNodes 数据 | `NzTreeNodeOptions[]` | `[]` |
| `[nzDefaultExpandAll]` | 默认展开所有树节点 | `boolean` | `false` |
| `[nzDefaultExpandedKeys]` | 默认展开指定的树节点 | `string[]` | - |
| `[nzDisplayWith]` | 如何在输入框显示所选的节点值的方法 | `(node: NzTreeNode) => string` | `(node: NzTreeNode) => node.title` |
Expand Down
8 changes: 7 additions & 1 deletion components/tree-select/nz-tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,13 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, OnDe

updateSelectedNodes(init: boolean = false): void {
if (init) {
const nodes = this.nzNodes.map(item => new NzTreeNode(item, null, this.nzTreeService));
let nodes;
if (!this.nzTreeService.isArrayOfNzTreeNode(this.nzNodes)) {
// has not been new NzTreeNode
nodes = this.nzNodes.map(item => (new NzTreeNode(item, null, this.nzTreeService)));
} else {
nodes = this.nzNodes.map(item => (new NzTreeNode({ ...item.origin }, null, this.nzTreeService)));
}
this.nzTreeService.initTree(nodes);
if (this.nzCheckable) {
this.nzTreeService.calcCheckedKeys(this.value, nodes);
Expand Down
5 changes: 3 additions & 2 deletions components/tree-select/nz-tree-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FormsModule, FormBuilder, FormGroup, ReactiveFormsModule } from '@angul
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { createKeyboardEvent, dispatchFakeEvent, dispatchMouseEvent, typeInElement } from '../core/testing';
import { NzTreeNode } from '../tree';
import { NzTreeSelectComponent } from './nz-tree-select.component';
import { NzTreeSelectModule } from './nz-tree-select.module';

Expand Down Expand Up @@ -222,7 +223,7 @@ describe('tree-select component', () => {
tick(200);
fixture.detectChanges();
expect(treeSelect.nativeElement.querySelectorAll('.ant-select-selection__choice').length).toBe(3);
const maxTagPlaceholderElement = treeSelect.nativeElement.querySelectorAll('.ant-select-selection__choice')[2]
const maxTagPlaceholderElement = treeSelect.nativeElement.querySelectorAll('.ant-select-selection__choice')[ 2 ]
.querySelector('.ant-select-selection__choice__content');
expect(maxTagPlaceholderElement).toBeTruthy();
expect(maxTagPlaceholderElement.innerText.trim()).toBe(`+ ${testComponent.value.length - testComponent.maxTagCount} ...`);
Expand Down Expand Up @@ -655,7 +656,7 @@ export class NzTestTreeSelectFormComponent {
}
]
}
];
].map(item => new NzTreeNode(item));

constructor(private fb: FormBuilder) {
this.formGroup = this.fb.group({
Expand Down

0 comments on commit c435853

Please sign in to comment.