Skip to content

Commit

Permalink
fix(module:steps): updateChildrenSteps bug (NG-ZORRO#3194)
Browse files Browse the repository at this point in the history
  • Loading branch information
giscafer authored and hsuanxyz committed Apr 15, 2019
1 parent 7d66907 commit f771690
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 3 additions & 1 deletion components/steps/nz-steps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export class NzStepsComponent implements OnChanges, OnInit, OnDestroy, AfterCont
ngAfterContentInit(): void {
this.updateChildrenSteps();
if (this.steps) {
this.steps.changes.pipe(takeUntil(this.destroy$)).subscribe(this.updateChildrenSteps);
this.steps.changes.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.updateChildrenSteps();
});
}
}

Expand Down
48 changes: 47 additions & 1 deletion components/steps/nz-steps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ChangeDetectorRef,
Component,
DebugElement,
OnInit,
TemplateRef,
ViewChild
} from '@angular/core';
Expand All @@ -23,7 +24,8 @@ describe('steps', () => {
NzTestOuterStepsComponent,
NzTestInnerStepStringComponent,
NzTestInnerStepTemplateComponent,
NzTestStepForComponent
NzTestStepForComponent,
NzTestStepAsyncComponent
]
});
TestBed.compileComponents();
Expand Down Expand Up @@ -337,6 +339,28 @@ describe('steps', () => {
comp.detectChanges();
});
});
describe('step async assign steps', () => {
it('should allow steps assigned asynchronously', fakeAsync(() => {
const fixture: ComponentFixture<NzTestStepAsyncComponent> = TestBed.createComponent(NzTestStepAsyncComponent);
let innerSteps: DebugElement[];

fixture.detectChanges();
innerSteps = fixture.debugElement.queryAll(By.directive(NzStepComponent));
expect(innerSteps.length).toBe(0);

tick(1000);
fixture.detectChanges();
tick();
innerSteps = fixture.debugElement.queryAll(By.directive(NzStepComponent));
fixture.detectChanges();
expect(innerSteps.length).toBe(3);
expect(innerSteps[0].nativeElement.className).toBe('ant-steps-item ant-steps-item-finish');
expect(innerSteps[1].nativeElement.className).toBe('ant-steps-item ant-steps-item-process');
expect(innerSteps[0].nativeElement.querySelector('.ant-steps-icon').innerText.trim()).toBe('');
expect(innerSteps[1].nativeElement.querySelector('.ant-steps-icon').innerText.trim()).toBe('2');
expect(innerSteps[2].nativeElement.querySelector('.ant-steps-icon').innerText.trim()).toBe('3');
}));
});
});

@Component({
Expand Down Expand Up @@ -432,3 +456,25 @@ export class NzTestStepForComponent {
this.steps.push(4);
}
}

@Component({
selector: 'nz-test-step-async',
template: `
<nz-steps [nzCurrent]="1">
<nz-step *ngFor="let step of steps; trackBy: trackById"></nz-step>
</nz-steps>
`
})
export class NzTestStepAsyncComponent implements OnInit {
steps: number[] = [];

trackById(index: number): number {
return index;
}

ngOnInit(): void {
setTimeout(() => {
this.steps = [1, 2, 3];
}, 1000);
}
}

0 comments on commit f771690

Please sign in to comment.