Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kurmanov committed Dec 28, 2023
2 parents d9f4fe1 + a7e55fa commit f095bce
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
19 changes: 11 additions & 8 deletions src/surveyTimerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export class SurveyTimerModel extends Base {
@property() clockMinorText: string;
@property({ defaultValue: 0 }) spent: number;
public get survey(): ISurveyTimerText { return <any>this.surveyValue; }
public onCreating(): void {}
public onCreating(): void { }
private timerFunc: any = null;
public start(): void {
if(!this.survey) return;
if (!this.survey) return;
if (this.isRunning || this.isDesignMode) return;
this.survey.onCurrentPageChanged.add(() => {
this.update();
Expand Down Expand Up @@ -65,23 +65,26 @@ export class SurveyTimerModel extends Base {
}
this.spent = this.spent + 1;
this.update();
if(this.onTimer) {
if (this.onTimer) {
this.onTimer(page);
}
}
private updateProgress() {
let { spent, limit } = this.survey.timerInfo;
if(!limit) {
if (!limit) {
this.progress = undefined;
} else {
if(spent == 0) {
if (spent == 0) {
this.progress = 0;
setTimeout(() => {
this.progress = Math.floor((spent + 1)/limit * 100) / 100;
this.progress = Math.floor((spent + 1) / limit * 100) / 100;
}, 0);
}
else if(spent !== limit) {
this.progress = Math.floor((spent + 1)/limit * 100) / 100;
else if (spent <= limit) {
this.progress = Math.floor((spent + 1) / limit * 100) / 100;
}
if (this.progress > 1) {
this.progress = undefined;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function getIsTouch() {
return _isTouch;
}

export let IsTouch = getIsTouch();
export let IsTouch = IsMobile && getIsTouch();

//for tests
export function _setIsTouch(val: boolean): void {
Expand Down
35 changes: 34 additions & 1 deletion tests/surveytimertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,37 @@ QUnit.test("Check timer when limits are not specified", function(assert) {
assert.strictEqual(timerModel.clockMajorText, "0:01");
assert.strictEqual(timerModel.clockMinorText, undefined);
survey.stopTimer();
});
});

QUnit.test("Progress shouldn't be more than 1", function (assert) {
const createSurvey = (maxTimeToFinish: number, maxTimeToFinishPage: number): SurveyModel => {
var survey = new SurveyModel();
survey.maxTimeToFinish = maxTimeToFinish;
survey.maxTimeToFinishPage = maxTimeToFinishPage;
survey.addNewPage("p1");
survey.pages[0].addNewQuestion("text");
return survey;
};
var survey = createSurvey(3, 3);
const timerModel = survey.timerModel;
survey.startTimer();
assert.equal(survey.timerInfo.limit, 3);
assert.equal(survey.timerInfo.spent, 0, "initial spent");
assert.equal(timerModel.progress, 0, "initial progress");
doTimer(1);
assert.equal(survey.timerInfo.limit, 3);
assert.equal(survey.timerInfo.spent, 1, "spent 1");
assert.equal(timerModel.progress, 0.66, "progress 1");
doTimer(1);
assert.equal(survey.timerInfo.limit, 3);
assert.equal(survey.timerInfo.spent, 2, "spent 2");
assert.equal(timerModel.progress, 1, "progress 2");
doTimer(1);
assert.equal(survey.timerInfo.limit, 3);
assert.equal(survey.timerInfo.spent, 3, "spent 3");
assert.equal(timerModel.progress, undefined, "progress 3");
doTimer(1);
assert.equal(survey.timerInfo.limit, 3);
assert.equal(survey.timerInfo.spent, 3, "spent 4");
assert.equal(timerModel.progress, undefined, "progress 4");
});
2 changes: 1 addition & 1 deletion tests/utilstests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ QUnit.test(
}
);

QUnit.test(
QUnit.skip(
"utils: devices: getIsTouch",
function (assert) {
assert.equal(getIsTouch(), false, "getIsTouch() return false for 'mouse' screens");
Expand Down

0 comments on commit f095bce

Please sign in to comment.