Skip to content

Commit

Permalink
#7922 Rating Scale values appear differently in designer and preview (#…
Browse files Browse the repository at this point in the history
…7923)

Fixes #7922
  • Loading branch information
novikov82 authored Mar 5, 2024
1 parent ddb86f5 commit 56c561f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
52 changes: 40 additions & 12 deletions tests/question_ratingtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 = <QuestionRatingModel>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) => {
Expand Down

0 comments on commit 56c561f

Please sign in to comment.