From f77169052ff8ac056e4732a7f4bee73766867027 Mon Sep 17 00:00:00 2001 From: Nickbing Lao Date: Mon, 15 Apr 2019 17:20:58 +0800 Subject: [PATCH] fix(module:steps): updateChildrenSteps bug (#3194) close #3193 --- components/steps/nz-steps.component.ts | 4 ++- components/steps/nz-steps.spec.ts | 48 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/components/steps/nz-steps.component.ts b/components/steps/nz-steps.component.ts index 038146afaee..44af336e36c 100644 --- a/components/steps/nz-steps.component.ts +++ b/components/steps/nz-steps.component.ts @@ -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(); + }); } } diff --git a/components/steps/nz-steps.spec.ts b/components/steps/nz-steps.spec.ts index 047e1b13279..25bbecdd046 100644 --- a/components/steps/nz-steps.spec.ts +++ b/components/steps/nz-steps.spec.ts @@ -3,6 +3,7 @@ import { ChangeDetectorRef, Component, DebugElement, + OnInit, TemplateRef, ViewChild } from '@angular/core'; @@ -23,7 +24,8 @@ describe('steps', () => { NzTestOuterStepsComponent, NzTestInnerStepStringComponent, NzTestInnerStepTemplateComponent, - NzTestStepForComponent + NzTestStepForComponent, + NzTestStepAsyncComponent ] }); TestBed.compileComponents(); @@ -337,6 +339,28 @@ describe('steps', () => { comp.detectChanges(); }); }); + describe('step async assign steps', () => { + it('should allow steps assigned asynchronously', fakeAsync(() => { + const fixture: ComponentFixture = 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({ @@ -432,3 +456,25 @@ export class NzTestStepForComponent { this.steps.push(4); } } + +@Component({ + selector: 'nz-test-step-async', + template: ` + + + + ` +}) +export class NzTestStepAsyncComponent implements OnInit { + steps: number[] = []; + + trackById(index: number): number { + return index; + } + + ngOnInit(): void { + setTimeout(() => { + this.steps = [1, 2, 3]; + }, 1000); + } +}