diff --git a/src/question_rating.ts b/src/question_rating.ts index 913988e61f..aebe1a9906 100644 --- a/src/question_rating.ts +++ b/src/question_rating.ts @@ -346,6 +346,9 @@ export class QuestionRatingModel extends Question { rateValues = this.createRateValues(); } + if (this.autoGenerate) { + this.rateMax = rateValues[rateValues.length - 1].value; + } if (this.rateType == "smileys" && rateValues.length > 10) rateValues = rateValues.slice(0, 10); this.renderedRateItems = rateValues.map((v, i) => { diff --git a/tests/question_ratingtests.ts b/tests/question_ratingtests.ts index ee89619c6e..9ba2b80d59 100644 --- a/tests/question_ratingtests.ts +++ b/tests/question_ratingtests.ts @@ -287,7 +287,7 @@ QUnit.test("Check numeric item values recalculation", (assert) => { q1.rateStep = 2; assert.equal(q1.visibleRateValues.length, 3); q1.rateMin = 0; - assert.equal(q1.visibleRateValues.length, 4); + assert.equal(q1.visibleRateValues.length, 3); }); QUnit.test("Check rateValues on text change", (assert) => { @@ -827,22 +827,50 @@ QUnit.test("rateMin/rateMax/rateStep changing rateCount", (assert) => { assert.equal(q1.rateCount, 5); q1.rateMax = 6; - assert.equal(q1.rateMax, 6); - assert.equal(q1.rateMin, 1); - assert.equal(q1.visibleRateValues.length, 6); - assert.equal(q1.rateCount, 6); + assert.equal(q1.rateMax, 6, "rateMax #1"); + assert.equal(q1.rateMin, 1, "rateMin #1"); + assert.equal(q1.visibleRateValues.length, 6, "length #1"); + assert.equal(q1.rateCount, 6, "count #1"); q1.rateMin = 2; - assert.equal(q1.rateMax, 6); - assert.equal(q1.rateMin, 2); - assert.equal(q1.visibleRateValues.length, 5); - assert.equal(q1.rateCount, 5); + assert.equal(q1.rateMax, 6, "rateMax #2"); + assert.equal(q1.rateMin, 2, "rateMin #2"); + assert.equal(q1.visibleRateValues.length, 5, "length #2"); + assert.equal(q1.rateCount, 5, "length #2"); q1.rateStep = 3; + assert.equal(q1.rateMax, 5, "rateMax #3"); + assert.equal(q1.rateMin, 2, "rateMin #3"); + assert.equal(q1.visibleRateValues.length, 2, "length #3"); + assert.equal(q1.rateCount, 2, "length #2"); +}); + +QUnit.test("rateStep changing rateMax", (assert) => { + var json = { + questions: [ + { + type: "rating", + name: "q1" + }, + ], + }; + const survey = new SurveyModel(json); + const q1 = survey.getQuestionByName("q1"); + assert.equal(q1.rateMin, 1); + assert.equal(q1.rateMax, 5); + assert.equal(q1.rateCount, 5); + + q1.rateMax = 6; assert.equal(q1.rateMax, 6); - assert.equal(q1.rateMin, 2); - assert.equal(q1.visibleRateValues.length, 2); - assert.equal(q1.rateCount, 2); + assert.equal(q1.rateMin, 1); + assert.equal(q1.visibleRateValues.length, 6); + assert.equal(q1.rateCount, 6); + + q1.rateStep = 2; + assert.equal(q1.rateMax, 5); + assert.equal(q1.rateMin, 1); + assert.equal(q1.visibleRateValues.length, 3); + assert.equal(q1.rateCount, 3); }); QUnit.test("rateValues changing rateCount", (assert) => {