Skip to content

Commit

Permalink
Survey Timer and Validation - The timer should stop at 0 and wait unt…
Browse files Browse the repository at this point in the history
…il a user corrects validation errors fix #7507 (#7526)
  • Loading branch information
andrewtelnov authored Dec 18, 2023
1 parent 38bf35c commit 7379cd3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7032,6 +7032,9 @@ export class SurveyModel extends SurveyElementCore
return this.getLocalizationFormatString(strName, surveySpent, surveyLimit);
}
private getDisplayClockTime(val: number): string {
if(val < 0) {
val = 0;
}
const min: number = Math.floor(val / 60);
const sec: number = val % 60;
let secStr = sec.toString();
Expand Down
25 changes: 25 additions & 0 deletions tests/surveytimertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,37 +165,43 @@ QUnit.test("Showing prev button, showTimerInfo='all'", function(assert) {
"You have spent 0 sec on this page and 0 sec in total.",
"Timer is not started"
);
assert.deepEqual(survey.timerClock, { majorText: "0:00", minorText: "0:00" }, "timerClock #1");
survey.startTimer();
assert.equal(
survey.timerInfoText,
"You have spent 0 sec on this page and 0 sec in total.",
"Timer just started"
);
assert.deepEqual(survey.timerClock, { majorText: "0:00", minorText: "0:00" }, "timerClock #2");
doTimer(62);
assert.equal(
survey.timerInfoText,
"You have spent 1 min 2 sec on this page and 1 min 2 sec in total.",
"62 sec passed"
);
assert.deepEqual(survey.timerClock, { majorText: "1:02", minorText: "1:02" }, "timerClock #3");
survey.nextPage();
doTimer(3);
assert.equal(
survey.timerInfoText,
"You have spent 3 sec on this page and 1 min 5 sec in total.",
"next page 65 sec passed"
);
assert.deepEqual(survey.timerClock, { majorText: "0:03", minorText: "1:05" }, "timerClock #4");
survey.maxTimeToFinish = 120;
assert.equal(
survey.timerInfoText,
"You have spent 3 sec on this page. You have spent 1 min 5 sec of 2 min in total.",
"survey limit, next page 65 sec passed"
);
assert.deepEqual(survey.timerClock, { majorText: "0:55", minorText: "0:03" }, "timerClock #5");
survey.maxTimeToFinishPage = 60;
assert.equal(
survey.timerInfoText,
"You have spent 3 sec of 1 min on this page and 1 min 5 sec of 2 min in total.",
"survey and page limit, next page 65 sec passed"
);
assert.deepEqual(survey.timerClock, { majorText: "0:57", minorText: "0:55" }, "timerClock #6");
survey.maxTimeToFinish = 0;
assert.equal(
survey.timerInfoText,
Expand All @@ -212,6 +218,25 @@ QUnit.test("Showing prev button, showTimerInfo='all'", function(assert) {
assert.equal(survey.timerInfoText, "!65!", "use onTextMarkdown event.");
survey.stopTimer();
});
QUnit.test("syrvey.timerClock, no negative value", function(assert) {
var survey = new SurveyModel();
survey.addNewPage("p1");
survey.pages[0].addNewQuestion("text");
survey.maxTimeToFinish = 60;
survey.maxTimeToFinishPage = 50;
survey.startTimer();
assert.deepEqual(survey.timerClock, { majorText: "0:50", minorText: "1:00" }, "timerClock #1");
survey.timeSpent = 20;
survey.currentPage.timeSpent = 20;
assert.deepEqual(survey.timerClock, { majorText: "0:30", minorText: "0:40" }, "timerClock #2");
survey.timeSpent = 60;
survey.currentPage.timeSpent = 60;
assert.deepEqual(survey.timerClock, { majorText: "0:00", minorText: "0:00" }, "timerClock #3");
survey.timeSpent = 600;
survey.currentPage.timeSpent = 600;
assert.deepEqual(survey.timerClock, { majorText: "0:00", minorText: "0:00" }, "timerClock #4");
survey.stopTimer();
});

QUnit.test("Start timer automatically if there is the start page", function(
assert
Expand Down

0 comments on commit 7379cd3

Please sign in to comment.