Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:steps): fix steps state change error under onpus strategy #3061

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/steps/nz-step.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class NzStepComponent {
renderer.addClass(elementRef.nativeElement, 'ant-steps-item');
}

detectChanges(): void {
this.cdr.detectChanges();
markForCheck(): void {
this.cdr.markForCheck();
}
}
2 changes: 1 addition & 1 deletion components/steps/nz-steps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class NzStepsComponent implements OnChanges, OnInit, OnDestroy, AfterCont
step.index = index + this.nzStartIndex;
step.currentIndex = this.nzCurrent;
step.last = length === index + 1;
step.detectChanges();
step.markForCheck();
});
});
}
Expand Down
16 changes: 14 additions & 2 deletions components/steps/nz-steps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, TemplateRef, ViewChild } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, TemplateRef, ViewChild } from '@angular/core';
import { async, fakeAsync, tick, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

Expand Down Expand Up @@ -41,6 +41,7 @@ describe('steps', () => {
tick();
fixture.detectChanges();
testComponent.current = 1;
testComponent.cdr.markForCheck();
fixture.detectChanges();
tick();
fixture.detectChanges();
Expand Down Expand Up @@ -77,18 +78,21 @@ describe('steps', () => {
it('should size display correct', () => {
fixture.detectChanges();
testComponent.size = 'small';
testComponent.cdr.markForCheck();
fixture.detectChanges();
expect(outStep.nativeElement.firstElementChild.className).toBe('ant-steps ant-steps-horizontal ant-steps-label-horizontal ant-steps-small');
});
it('should direction display correct', () => {
fixture.detectChanges();
testComponent.direction = 'vertical';
testComponent.cdr.markForCheck();
fixture.detectChanges();
expect(outStep.nativeElement.firstElementChild.className).toBe('ant-steps ant-steps-vertical');
});
it('should label placement display correct', () => {
fixture.detectChanges();
testComponent.labelPlacement = 'vertical';
testComponent.cdr.markForCheck();
fixture.detectChanges();
expect(outStep.nativeElement.firstElementChild.classList).toContain('ant-steps-label-vertical');
});
Expand All @@ -97,17 +101,20 @@ describe('steps', () => {
tick();
fixture.detectChanges();
testComponent.status = 'wait';
testComponent.cdr.markForCheck();
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(innerSteps[ 0 ].nativeElement.className).toBe('ant-steps-item ant-steps-item-wait');
testComponent.status = 'finish';
testComponent.cdr.markForCheck();
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(innerSteps[ 0 ].nativeElement.className).toBe('ant-steps-item ant-steps-item-finish');
testComponent.status = 'error';
testComponent.current = 1;
testComponent.cdr.markForCheck();
fixture.detectChanges();
tick();
fixture.detectChanges();
Expand All @@ -119,6 +126,7 @@ describe('steps', () => {
tick();
fixture.detectChanges();
testComponent.progressDot = true;
testComponent.cdr.markForCheck();
fixture.detectChanges();
tick();
fixture.detectChanges();
Expand All @@ -132,6 +140,7 @@ describe('steps', () => {
tick();
fixture.detectChanges();
testComponent.progressDot = testComponent.progressTemplate;
testComponent.cdr.markForCheck();
fixture.detectChanges();
tick();
fixture.detectChanges();
Expand All @@ -149,6 +158,7 @@ describe('steps', () => {
fixture.detectChanges();
testComponent.startIndex = 3;
testComponent.current = 3;
testComponent.cdr.markForCheck();
fixture.detectChanges();
tick();
fixture.detectChanges();
Expand Down Expand Up @@ -250,7 +260,8 @@ describe('steps', () => {
<span class="insert-span">{{status}}{{index}}</span>
<ng-template [ngTemplateOutlet]="dot"></ng-template>
</ng-template>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class NzTestOuterStepsComponent {
@ViewChild('progressTemplate') progressTemplate: TemplateRef<void>;
Expand All @@ -261,6 +272,7 @@ export class NzTestOuterStepsComponent {
status = 'process';
progressDot = false;
startIndex = 0;
constructor (public cdr: ChangeDetectorRef) {}
}

@Component({
Expand Down