Skip to content

Commit

Permalink
fix: rate half value when allow half is false (#8536)
Browse files Browse the repository at this point in the history
  • Loading branch information
imaliouris committed May 28, 2024
1 parent d0dbd5b commit 7742fe3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/rate/rate.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class NzRateComponent implements OnInit, ControlValueAccessor, OnChanges
}

this._value = input;
this.hasHalf = !Number.isInteger(input);
this.hasHalf = !Number.isInteger(input) && this.nzAllowHalf;
this.hoverValue = Math.ceil(input);
}

Expand Down
15 changes: 14 additions & 1 deletion components/rate/rate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,22 @@ describe('rate', () => {
expect(testComponent.modelChange).toHaveBeenCalledTimes(1);
}));
it('should allow half work', fakeAsync(() => {
testComponent.allowHalf = true;
testComponent.allowHalf = false;
fixture.detectChanges();
expect(testComponent.value).toBe(0);
testComponent.value = 3.5;
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(rate.nativeElement.firstElementChild.children[3].classList).toContain('ant-rate-star-full');
expect(rate.nativeElement.firstElementChild.children[4].classList).toContain('ant-rate-star-zero');
flush();

testComponent.allowHalf = true;
testComponent.value = 0;
fixture.detectChanges();
flush();
fixture.detectChanges();
rate.nativeElement.firstElementChild.children[3].firstElementChild.children[1].click();
fixture.detectChanges();
flush();
Expand Down

0 comments on commit 7742fe3

Please sign in to comment.