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

Adding tests to pr/233 #235

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 lib/jquery.raty.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@

if (name) {
var icon = this.opt[name];
var star = this.stars[Math.ceil(score) - 1];
var star = this.stars[Math.max( Math.ceil(score) - 1,0)];

this._setIcon(star, icon);
} // Full down: [x.00 .. x.25]
Expand Down Expand Up @@ -599,7 +599,7 @@
// TODO: model spec
_setTitle: function(score, evt) {
if (score) {
var integer = parseInt(Math.ceil(score), 10);
var integer = parseInt(Math.max(Math.ceil(score),0), 10);
var star = this.stars[integer - 1];

star.title = this._getHint(score, evt);
Expand Down
29 changes: 29 additions & 0 deletions spec/models/_roundStars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe('#_roundStars', function() {
beforeEach(function() {
this.el = Helper.create('#el');
});


context ('when event is given', function() {
beforeEach(function() {
this.evt = document.createEvent('MouseEvents');
spyOn($.raty.Raty.prototype , '_starName');
});

context('when score is positive integer', function() {
it ('requests calls _starName', function() {
// given
var number = 2;
var element = this.el[0];
var options = {};
var instance = new $.raty.Raty(element, options);

// when
instance._roundStars(number, this.evt);

// then
expect($.raty.Raty.prototype._starName).toHaveBeenCalledWith(this.number, this.evt);
});
});
});
});