test: fixed failing tests

This commit is contained in:
Shariq Ansari 2021-12-20 18:36:52 +05:30
parent 5aafc4def9
commit ed60a30e69
2 changed files with 6 additions and 6 deletions

View file

@ -20,12 +20,13 @@ context('Control Rating', () => {
cy.get('div.rating')
.children('svg')
.find('.right-half')
.first()
.click()
.should('have.class', 'star-click');
cy.get('@dialog').then(dialog => {
var value = dialog.get_value('rate');
expect(value).to.equal(1);
expect(value).to.equal(1/7);
dialog.hide();
});
});
@ -35,6 +36,7 @@ context('Control Rating', () => {
cy.get('div.rating')
.children('svg')
.find('.right-half')
.first()
.invoke('trigger', 'mouseenter')
.should('have.class', 'star-hover')

View file

@ -73,14 +73,12 @@ frappe.ui.form.ControlRating = class ControlRating extends frappe.ui.form.Contro
let out_of_ratings = this.df.options || 5;
value = value * out_of_ratings;
let el = $(this.input_area).find('svg');
let is_half = value % 1 == 0.5;
el.children('svg').prevObject.each( function(e) {
if (e < value) {
$(this).find('.left-half, .right-half').addClass('star-click');
if (e == Math.floor(value) && is_half) {
$(this).find('.left-half').addClass('star-click');
$(this).find('.right-half').removeClass('star-click');
}
let is_half = e == Math.floor(value) && value % 1 == 0.5;
is_half && $(this).find('.right-half').removeClass('star-click');
} else {
$(this).find('.left-half, .right-half').removeClass('star-click');
}