Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions common/lib/xmodule/xmodule/js/spec/video/completion_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@
}).then(function() {
spyOn(state.completionHandler, 'computeProgress').and.callThrough();
spyOn(state.completionHandler, 'triggerProgress').and.callThrough();
// Less than 10 percents
time = 9 * duration / 100;
// 4 percents should be equivalent to 0
time = 4 * duration / 100;
state.el.trigger('timeupdate', time);
expect(state.completionHandler.computeProgress).toHaveBeenCalled();
expect(state.completionHandler.triggerProgress).toHaveBeenCalled();
state.completionHandler.computeProgress.calls.reset();
state.completionHandler.triggerProgress.calls.reset();
// Between 10 and 20 percents
time = 15 * duration / 100;
// 8 percents should be equivalent to 5
time = 8 * duration / 100;
state.el.trigger('timeupdate', time);
expect(state.completionHandler.computeProgress).toHaveBeenCalled();
expect(state.completionHandler.triggerProgress).toHaveBeenCalled();
state.completionHandler.computeProgress.calls.reset();
state.completionHandler.triggerProgress.calls.reset();
// Another timeupdate in the same decade should not trigger "triggerProgress"
time = 18 * duration / 100;
// Another timeupdate in the same 5-range should not trigger "triggerProgress"
time = 9 * duration / 100;
state.el.trigger('timeupdate', time);
expect(state.completionHandler.computeProgress).toHaveBeenCalled();
expect(state.completionHandler.triggerProgress).not.toHaveBeenCalled();
Expand Down
11 changes: 5 additions & 6 deletions common/lib/xmodule/xmodule/js/src/video/09_completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@
/** Compute current video progression and trigger event if needed */
computeProgress: function(currentTime, duration) {
// Compute current progress percentage
var currentProgressPercentage = currentTime * 100 / duration;
// Check if last "lastProgressPercentage" and current percentage are in the same decade
var sameDecade = Math.floor(
currentProgressPercentage / 10) === Math.floor(this.lastProgressPercentage / 10);
// If no previous "lastProgressPercentage" or different decade, trigger the event
if (this.lastProgressPercentage === undefined || !sameDecade) {
var currentProgressPercentage = Math.floor(currentTime * 100 / duration / 5) * 5;
// Check if last "lastProgressPercentage" and current percentage are in the same 5-range
var newRange = currentProgressPercentage > this.lastProgressPercentage;
// If no previous "lastProgressPercentage" or different 5-range, trigger the event
if (this.lastProgressPercentage === undefined || newRange) {
this.triggerProgress(Math.floor(currentProgressPercentage));
// Save the lastProgressPercentage value
this.lastProgressPercentage = currentProgressPercentage;
Expand Down