Skip to content

Commit

Permalink
feat(module:steps): fix steps not rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendell committed Apr 3, 2019
1 parent 51c0d53 commit 25126be
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions components/steps/nz-steps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,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);
}
// Still subscribe changes because this property is not null
// and user may assign steps asynchronously.
this.steps.changes.pipe(takeUntil(this.destroy$)).subscribe(this.updateChildrenSteps);
}

private updateChildrenSteps(): void {
Expand Down
38 changes: 37 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 @@ -330,13 +332,29 @@ describe('steps', () => {
it('should title display correct', () => {
TestBed.createComponent(NzTestStepForComponent).detectChanges();
});

it('should push works correct', () => {
const comp = TestBed.createComponent(NzTestStepForComponent);
comp.detectChanges();
comp.debugElement.componentInstance.updateSteps();
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();
innerSteps = fixture.debugElement.queryAll(By.directive(NzStepComponent));
expect(innerSteps.length).toBe(3);
}));
});
});

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

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

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

0 comments on commit 25126be

Please sign in to comment.