Skip to content

Commit

Permalink
fix(rating): restore update on click fucntionality
Browse files Browse the repository at this point in the history
Fixes #1072

Closes #1074
  • Loading branch information
pkozlowski-opensource committed Nov 22, 2016
1 parent ed5d4ca commit a64a8a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/rating/rating.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ describe('ngb-rating', () => {
});

it('handles correctly the click event', () => {
const fixture = createTestComponent('<ngb-rating rate="3" max="5"></ngb-rating>');

const fixture = createTestComponent('<ngb-rating [(rate)]="rate" max="5"></ngb-rating>');
const compiled = fixture.nativeElement;
const ngbRating = fixture.debugElement.query(By.directive(NgbRating)).injector.get(NgbRating);

ngbRating.enter(2); // simulate mouseenter
getStar(compiled, 2).click();
fixture.detectChanges();

expect(getState(compiled)).toEqual([true, true, false, false, false]);
expect(fixture.componentInstance.rate).toBe(2);
});

it('should set pointer cursor on stars when not readonly', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/rating/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class NgbRating implements OnInit,
if (!this.readonly) {
const newRate = getValueInRange(value, this.max, 0);

if (this.rate !== newRate) {
if (this._oldRate !== newRate) {
this._oldRate = newRate;
this.rate = newRate;
this.rateChange.emit(newRate);
Expand Down

0 comments on commit a64a8a0

Please sign in to comment.