Skip to content

Commit

Permalink
fix(module:steps): fix steps ngfor (#1421)
Browse files Browse the repository at this point in the history
close #1418
  • Loading branch information
vthinkxie committed May 10, 2018
1 parent 5ad0452 commit 35da659
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/steps/nz-steps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class NzStepsComponent implements OnInit, OnDestroy, AfterContentInit {
}

ngAfterContentInit(): void {
this.updateChildrenSteps();
Promise.resolve().then(() => this.updateChildrenSteps());
if (this.steps) {
this.stepsSubscription = this.steps.changes.subscribe(this.updateChildrenSteps);
}
Expand Down
33 changes: 27 additions & 6 deletions components/steps/nz-steps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, TemplateRef, ViewChild } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { async, fakeAsync, tick, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { NzStepComponent } from './nz-step.component';
Expand All @@ -10,7 +10,7 @@ describe('steps', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports : [ NzStepsModule ],
declarations: [ NzTestOuterStepsComponent, NzTestInnerStepStringComponent, NzTestInnerStepTemplateComponent ]
declarations: [ NzTestOuterStepsComponent, NzTestInnerStepStringComponent, NzTestInnerStepTemplateComponent, NzTestStepForComponent ]
});
TestBed.compileComponents();
}));
Expand All @@ -25,13 +25,15 @@ describe('steps', () => {
outStep = fixture.debugElement.query(By.directive(NzStepsComponent));
innerSteps = fixture.debugElement.queryAll(By.directive(NzStepComponent));
});
it('should init className correct', () => {
it('should init className correct', fakeAsync(() => {
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(outStep.nativeElement.firstElementChild.className).toBe('ant-steps ant-steps-horizontal ant-steps-label-horizontal');
expect(innerSteps[ 0 ].nativeElement.className).toBe('ant-steps-item ant-steps-item-process');
expect(innerSteps[ 1 ].nativeElement.className).toBe('ant-steps-item ant-steps-item-wait');
expect(innerSteps[ 2 ].nativeElement.className).toBe('ant-steps-item ant-steps-item-wait');
});
}));
it('should current change correct', () => {
fixture.detectChanges();
testComponent.current = 1;
Expand All @@ -40,12 +42,14 @@ describe('steps', () => {
expect(innerSteps[ 1 ].nativeElement.className).toBe('ant-steps-item ant-steps-item-process');
expect(innerSteps[ 2 ].nativeElement.className).toBe('ant-steps-item ant-steps-item-wait');
});
it('should tail display correct', () => {
it('should tail display correct', fakeAsync(() => {
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(innerSteps[ 0 ].nativeElement.firstElementChild.classList.contains('ant-steps-item-tail')).toBe(true);
expect(innerSteps[ 1 ].nativeElement.firstElementChild.classList.contains('ant-steps-item-tail')).toBe(true);
expect(innerSteps[ 2 ].nativeElement.firstElementChild.classList.contains('ant-steps-item-tail')).toBe(false);
});
}));
it('should title correct', () => {
fixture.detectChanges();
expect(innerSteps[ 0 ].nativeElement.querySelector('.ant-steps-item-title').innerText).toBe('0title');
Expand Down Expand Up @@ -183,6 +187,11 @@ describe('steps', () => {
expect(innerSteps[ 2 ].nativeElement.querySelector('.ant-steps-icon').firstElementChild.className).toBe('anticon anticon-smile-o');
});
});
describe('step ng for', () => {
it('should title display correct', () => {
TestBed.createComponent(NzTestStepForComponent).detectChanges();
});
});
});

@Component({
Expand Down Expand Up @@ -246,3 +255,15 @@ export class NzTestInnerStepStringComponent {
})
export class NzTestInnerStepTemplateComponent {
}

@Component({
selector: 'nz-test-step-for',
template: `
<nz-steps>
<nz-step *ngFor="let step of steps"></nz-step>
</nz-steps>
`
})
export class NzTestStepForComponent {
steps = [ 1, 2, 3 ];
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"@angular/animations": "^5.0.0",
"@angular/cli": "^1.7.1",
"@angular/cli": "^1.7.4",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/compiler-cli": "^5.0.0",
Expand Down

0 comments on commit 35da659

Please sign in to comment.